0

i'm trying to write a script to record camera display.

When i tried to run, i got the error:

OpenCV: FFMPEG: tag 0x5634504d/'MP4V' is not supported with codec id 12 and format 'mp4 / MP4 (MPEG-4 Part 14)'

OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'

Here's my code:

import cv2

cam = cv2.VideoCapture(0)

width = int(cam.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cam.get(cv2.CAP_PROP_FRAME_HEIGHT))

fourcc = cv2.VideoWriter_fourcc(*"MP4V")
writer = cv2.VideoWriter("captures/record.mp4", fourcc, 20, (width, height))

while True:
    is_camera_working, display = cam.read()
    cv2.imshow("Camera Data", display)

    if cv2.waitKey(25) & 0xFF == ord("q"):
        break

cam.release()
writer.release()

cv2.destroyAllWindows

I tried to write (*"mp4v") , ("m","p","4","v") in the VideoWriter_fourcc. Also i delete fourcc variable and just write 0x7634706d as second argumnet of VideoWriter function.

I saw this and this threads. Still not works for me.

What is the problem and how can i solve it? Thanks in advance.

anbvy
  • 27
  • 7

2 Answers2

1

The codec identifier you need to use is "mp4v" (lowercase) instead of "MP4V":

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
Velimir Mlaker
  • 10,664
  • 4
  • 46
  • 58
  • I already tried that, i wrote it down after the code block. – anbvy Mar 21 '23 at 17:38
  • 1
    The warning you pasted shows that you used "MP4V" -- can you try using 'mp4v' instead, and paste the warning you receive? (Just to be sure...) – Velimir Mlaker Mar 21 '23 at 17:45
  • I forgot the add `writer.write(display)` line. That was the problem. And also, i write with lower case "mp4v" again to check the output. There was no error message and record.mp4 was created but still, because of the `writer.write(display)` it was blank. Thank you for your time! – anbvy Mar 21 '23 at 18:38
-1

I just realise that i didn't write writer.write(display) in the while loop. It works now. Thanks everyone for their time!

anbvy
  • 27
  • 7