0

I am on ubuntu 22.04.

I installed ffmpeg with apt.

I am creating a video from some image files using python/opencv2 (installed via pip)

When I use:

cv2.VideoWriter_fourcc(*"mp4v")

the video is successfully created, but is not supported by firefox.

I read online that the H264 encoder would be a better fit for web-browsers supports.

ffmpeg -codecs | grep h264 

shows:

DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m h264_qsv h264_cuvid ) (encoders: libx264 libx264rgb h264_nvenc h264_omx h264_qsv h264_v4l2m2m h264_vaapi nvenc nvenc_h264 )

but

cv2.VideoWriter_fourcc(*"h264")

results in:

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

I could not find online what was wrong (h264 is not installed, how to install it? the 'fourcc' of h264 is not 'h264' ? I should not create a *.mp4 file ?)

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Vince
  • 3,979
  • 10
  • 41
  • 69
  • read this [link](https://stackoverflow.com/questions/70247344/save-video-in-opencv-with-h264-codec/74917712#74917712). several of solutions – gilad eini Aug 30 '23 at 01:48

1 Answers1

1

To write H.264, you need to use the fourcc *"avc1"

If that still doesn't work, the ffmpeg built into your OpenCV might have restrictions on it that prohibit bundling with the x264 encoder. There are builds of ffmpeg with x264 encoder. Using that would require building OpenCV yourself.

If the option is available, OpenCV/ffmpeg would notify you that you could use the "OpenH264" library. This would require downloading a DLL from Cisco. Make sure it's the exact version given in the prompt.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36