Video not saving when I use the fourcc 'X264'

0

I'm new to opencv and ffmpeg so I don't know if this is a noob question. I'm writing a video with the following statement:

out = cv2.VideoWriter('videoname.mp4', cv2.VideoWriter_fourcc(*'X264'), 10, (frame_width, frame_height))

My program runs however, the video does not save. I tried looking for solutions online but none of them seem to work. What I have already tried:

  1. It works correctly when I used *'XVID' or *'MJPG' but the file size is larger than what I require.
  2. Using 0x00000021 as the fourcc argument
  3. Trying variations of x264, X264, H264, h264 as I read it might be case sensitive. This also does not work.
  4. Specifying the channel when installing ffmpeg with the command conda install -c conda-forge ffmpeg (even though I already have built ffmpeg from source, I tried this)
  5. Trying to install x264 using sudo apt-get install ffmpeg x264 libx264-dev. I get the following result:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libx264-dev is already the newest version (2:0.152.2854+gite9a5903-2).
x264 is already the newest version (2:0.152.2854+gite9a5903-2).
ffmpeg is already the newest version (7:3.4.8-0ubuntu0.2).
0 upgraded, 0 newly installed, 0 to remove and 82 not upgraded.

Can someone help me where I could possibly be going wrong? I require the video codec to be x264 when saving the video to get a small file size.

Other info: OpenCV version used: 4.2.0 Platform: Ubuntu 18.04

python-3.x
opencv
video
ffmpeg
asked on Stack Overflow Mar 14, 2021 by user42 • edited Mar 14, 2021 by user42

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0