I'm having trouble writing h264 video with OpenCV 3 via FFmpeg ("'X','2','6','4'" FOURCC). I've seen all the related posts so far on SO, but nothing helps. Code:
cv::VideoWriter writer(output_path.string(), CV_FOURCC('X','2','6','4'), 60, frame_size);
Output:
OpenCV: FFMPEG: tag 0x34363258/'X264' is not supported with codec id 28 and format 'mp4 / MP4 (MPEG-4 Part 14)' OpenCV: FFMPEG: fallback to use tag 0x00000021/'!???'
The resulting video is extremely small (byte-wise) and unreadable. Setting the four_cc to -1 results in "unknown tag" from FFmpeg, I don't get any prompt to choose codec as others suggested.
The OpenCV 3 doc states:
FFMPEG backend with MP4 container natively uses other values as fourcc code: see ObjectType, so you may receive a warning message from OpenCV about fourcc code conversion.
That page they refrence doesn't have h264 / x264 listed, and I'm not sure how to interpret that statement, since earlier SO posts seem to all list X.2.6.4 as the appropriate code. Using H.2.6.4 actually gives identical output.
Any suggestions / workarounds?
P.S. the ffmpeg is most up-to-date from Ubuntu maintainers, it lists that it was configured with --enable-libx264
EDIT: I tried to use the mkv container instead of mp4. The warning about tag not being supported went away, but the resulting video is still unreadable.
See Question&Answers more detail:os