OpenCV: FFMPEG: tag 0x34363268/'h264' is not supported with codec

Viewed 19364

After installed opencv like on Mac OS 10.13.6:

conda install -c conda-forge ffmpeg
conda install -c conda-forge opencv

And using fourcc = cv2.VideoWriter_fourcc('h', '2', '6', '4') in videowriter

I get error:

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

How to fix it?

4 Answers

You should change:

fourcc = cv2.VideoWriter_fourcc('h', '2', '6', '4')

to:

fourcc = cv2.VideoWriter_fourcc(*'avc1')

The codecs are platform dependent, that could be the problem. Try using this combination:

  • extension of file = test.mkv
  • codec . = CV_FOURCC(*'X264)

Here is the reference link

FourCC is a 4-byte code used to specify the video codec. The list of available codes can be found in fourcc.org. It is platform dependent. The following codecs work fine for me.

  • In Fedora: DIVX, XVID, MJPG, X264, WMV1, WMV2. (XVID is more preferable. MJPG results in high size video. X264 gives very small size video)
  • In Windows: DIVX (More to be tested and added)
  • In OSX: MJPG (.mp4), DIVX (.avi), X264 (.mkv).

Source

Related