3

To a 2GB raw video file taken in front of a greenscreen I want to add the alpha channel.

My problem is: the output files appear much too large to me (about 20-fold the size of the input), and OpenShot, the video editor, seems unable to handle such huge files. Comparing file properties of input and output shows bitrates of about 15k in the infiles, and 150k-250k in the result files, which seems to pinpoint the problem.

(By the way, I also want to discard the first part of the clip as well as its audio channel and reduce the frame rate from 30 to 24 fps in the process, which all works fine.)

This is my command:

ffmpeg.exe -i <in.MOV> -vf chromakey=0x007d06:0.15:0.0 -ss 40.420 -r 24 -b:v 15840k -maxrate 15840k -bufsize 15840k -an -c:v <encoder> <out.mov>

The parameters as I understand them:

-i <in.mov> ... infile
-vf chromakey=0x007d06:0.15:0.0 ... chroma, tolerance & blend of greenscreens
-ss 40.420 ... skip before second 40.420 (this works)
-r 24 ... frame rate (this works, too)
-b:v 15804k ... bitrate (seemingly no effect)
-maxrate 15840k ... maximum BitRate (seemingly no effect)
-bufzise 15840k ... Buffer size (can't tell)
-an ... no audio channel (works fine)
-c:v <encoder> ... Video Encoder (ffvhuff, png, qtrle and tiff were tried, all to the same result)
<out.mov> ... outfile

b, maxrate and bufsize are described as global options. No matter what setting, during the process bitrates of up to some 3000000kbits/s (tiff) are reported.

(I also added -pixel_format argb, but this, too, seemed to be ignored, ffmpeg always reports to write yuva420p.)

What am I missing?

Mat
  • 140
  • 1
  • 4
  • 12

1 Answers1

3

All the encoders you tried are lossless. You can't set a bitrate for a lossless encoder.

Try VP8/9 i.e. -c:v libvpx or libvpx-vp9 with a pixel format of -pix_fmt yuva420p. Remove the bitrate/maxrate/bufsize and set -crf N -b:v 0 where N can range from 0 to 63. Try with a value of 20. Go up/down for smaller/better video stream respectively.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thanks a lot! Unfortunately, no success. libvpx gives me "Transparency encoding with auto_alt_ref does not work". (Adding -auto_alt_ref 0 yields an "unrecognized option" error.) I have tried 18 encoders using your hint. Every single one of them failed (for various reasons). Libvpx-vp9 seemed to work (no warnings), even though at painstaking speed (0.03, i.e. a 40' clip will take 50hrs), However, in the video editor, the 3 seconds I rendered showed no transparency anyway. Is there a listing, if encoders are lossy and compatible to a pixel-format containing alpha? I find nothing. – Mat Mar 27 '17 at 14:20
  • 1
    It's `-auto-alt-ref 0`. My given settings are only applicable for the VPx encoders; they aren't generic. – Gyan Mar 27 '17 at 14:29
  • I'm not familiar with Openshot, but can you use a separate layer/video as an alpha channel i.e. `alpha matte` – Gyan Mar 27 '17 at 14:31
  • I am far from sure, but I am afraid: no. – Mat Mar 27 '17 at 15:44
  • I tried to reduce bitrate of rawvideo (I guess yuv420p) to reduce file size. This answer brought the solution to my task. Especially the libvpx encoder and `-auto-alt-ref 0` part. Following command works for me like a charm: `ffmpeg -i input_video.avi -c:v libvpx -pix_fmt yuva420p -crf 20 -b:v 0 -auto-alt-ref 0 output.avi`. Thanks for this answer. – marco Aug 23 '22 at 11:47
  • I've an additional question: The quality of the video is quite poor even if I like the reduction from 1,4GiB to 650KiB. But I loose some important information in the video. What would be a good start regarding parameters or so to tune the quality? Increasing crf value to 60 did not create an acceptable result. Everything between 1MiB and 100MiB would be ok. – marco Aug 23 '22 at 12:04