mrgloom
mrgloom

Reputation: 21632

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

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?

Upvotes: 9

Views: 37799

Answers (4)

Gonzalo Garcia
Gonzalo Garcia

Reputation: 6632

You should change:

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

to:

fourcc = cv2.VideoWriter_fourcc(*'avc1')

Upvotes: 4

lenin
lenin

Reputation: 1011

First like some answers pointed out, we should use "AVC1" instead of "h264". Secondly, when we are using opencv-python, there are some licence issues : https://github.com/opencv/opencv-python/issues/207 , we may need to compile on our own.

Upvotes: 2

Raam Mishra
Raam Mishra

Reputation: 75

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

Upvotes: 1

Revanth Kausikan
Revanth Kausikan

Reputation: 673

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

Upvotes: 4

Related Questions