1

I am currently using opencv in python to write a video with compression. Here are some parts of the code that are giving errors.

fourcc=cv2.VideoWriter_fourcc(*'X264')
video = cv2.VideoWriter(outfiles[c],fourcc, fps, (width,height))

The error is

OpenCV: FFMPEG: tag 0x34363258/'X264' is not supported with codec id 28 and form at 'mp4 / MP4 (MPEG-4 Part 14)' OpenCV: FFMPEG: fallback to use tag 0x00000021/'!???' Working on file test_videos/solidYellowLeft.mp4 OpenCV: FFMPEG: tag 0x34363258/'X264' is not supported with codec id 28 and form at 'mp4 / MP4 (MPEG-4 Part 14)' OpenCV: FFMPEG: fallback to use tag 0x00000021/'!???'

I have downloaded the openh264-1.6.0-win64msvc.dll file for the newer versions of H264 encoding. I've tried different types, H264, X264, XVID, VIDX, not using MJPG because it produces a large file. Setting the 5th option in VideoWriter to False (making it single channel) didn't work either. If you have a suggestion on how to fix this or to try an alternative method, that would help greatly.. If you need any more information, let me know.

1
  • Just downloading the h264 implementation library won't solve your problem. The cv2.VideoWriter uses the FFMPEG API for video encoding, so your copy of FFMPEG must be built with libx264 support.
    – zindarod
    Commented Sep 30, 2017 at 21:18

2 Answers 2

0

If anyone came across this error, I solved it by using the fallback tag which removed the error.

fourcc=0x00000021
1
  • I used this solution on Ubuntu 16.04, and it worked great. But I have an Ubuntu 18 machine, and now I'm back to the same error. Anyone have this problem when they upgraded?
    – TPM
    Commented Jul 21, 2018 at 2:09
0

Assuming outfiles[c] contains a filename like "out.mp4" the following worked for me on an Ubuntu 16.04 machine with an NVidia GPU.

fourcc = cv.VideoWriter_fourcc(*"mp4v")
video = cv2.VideoWriter(outfiles[c],fourcc, fps, (width,height))

Cheers to jspiers for answering here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.