Python opencv videowriter issue: not compressing/writing

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.

python
opencv
encoding
asked on Stack Overflow Sep 30, 2017 by user136128

2 Answers

0

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

fourcc=0x00000021
answered on Stack Overflow Sep 30, 2017 by user136128
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.

answered on Stack Overflow Feb 19, 2019 by SpeedCoder5

User contributions licensed under CC BY-SA 3.0