ffmpeg using crf and bufsize
I am converting an mpeg 2 video to h.264 using ffmpeg.
As I am not able to decide what exact bitrate and we never really know what bit rate will be the best for a certain video there I am using the crf flag to set the quality of the video.
Now the hardware decoder I am using has a 2MB bufer size. Is it possible to use crf and also set the buffersize in ffmpeg.
Here is the command I am using.
Code:
ffmpeg -i input.mpg -q:v 1 -q:a 1 -y -c:v libx264 -profile:v main -preset slow -s 1280x720 -x264opts crf=21:keyint=40 -threads 0 -c:a libvo_aacenc -ac 2 -ar 44100 -b:a 192k output.mp4
Re: ffmpeg using crf and bufsize
Quote:
Is it possible to use crf and also set the buffersize in
ffmpeg.
yes crf and vbv restrictions can be used together.
-> https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
Re: ffmpeg using crf and bufsize
in ffmpeg, -maxrate is equivalent to --vbv-maxrate in x264 , and -bufsize is equivalent to --vbv-bufsize in x264
https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
I don't know what the value of units are, in x264, they are expressed in kilobits (not kilobytes) , but beware ffmpeg often uses different units, and different ffmpeg binaries sometimes have slightly different syntax or different units. (For 2MB buffer, don't forget to take into account bytes => bits conversion)
EDIT: selur beat me to it :)
Re: ffmpeg using crf and bufsize
Code:
-x264opts crf=20:keyint=40:ref=3:vbv-bufsize=14000:vbv-maxrate=3072
I am using the above x264 options to set the bufsize to 14000 and max bit rate to 3Mbps and still maintain a crf 20.
will this make very video buffer size as 14000 or is that the maximum buffer size?
Moreover, the maxrate defines the max rate at which the buffer is filled, is that the same thing as the max bitrate?
I am using profile main and level 3.1, do I even need to define the bufsize or is it over kill as the maximum buf size of this profile and level is 14000kb
Re: ffmpeg using crf and bufsize
Quote:
Originally Posted by
wotdefcuk
Code:
-x264opts crf=20:keyint=40:ref=3:vbv-bufsize=14000:vbv-maxrate=3072
I am using the above x264 options to set the bufsize to 14000 and max bit rate to 3Mbps and still maintain a crf 20.
will this make very video buffer size as 14000 or is that the maximum buffer size?
Moreover, the maxrate defines the max rate at which the buffer is filled, is that the same thing as the max bitrate?
I am using profile main and level 3.1, do I even need to define the bufsize or is it over kill as the maximum buf size of this profile and level is 14000kb
No, maxrate isn't what people traditionally think as the "max bitrate"
A larger vbv-bufsize will give the encoder more flexibility to make better/higher quality decisions, but the tradeoff is start up will be slower . vbv-init is the proportion of buffer that is filled before playback starts (default is 0.9 * vbv-bufsize) . So if vbv-maxrate is 3000, it will take a few seconds to fill 90% of a 14000kb buffer
Re: ffmpeg using crf and bufsize
So if I do not define the bufsize and just rely on the maxrate and the fact that main level 3.1 will take care of it, will that work?
Re: ffmpeg using crf and bufsize
If you're doing this for streaming, device playback, you should always enter the values . It might work with maxrate only, but if you recall from your other thread - currently setting the level and profile doesn't limit anything (it's just a "label"). But vbv paramaters are never violated in libx264 (and if it does, it will say so in the log). Personally, I wouldn't leave anything to chance.
Re: ffmpeg using crf and bufsize
but then how to solve the problem of slow start up that you mentioned?
Re: ffmpeg using crf and bufsize
Quote:
Originally Posted by
wotdefcuk
but then how to solve the problem of slow start up that you mentioned?
either use a smaller buffer, or decrease vbv-init
tradeoff of a smaller buffer, is encoder will limit some decisions , potentially lower quality
encoding is all about tradeoffs
Re: ffmpeg using crf and bufsize
so here is what i am try to do.
1. Use crf 20
2. Max buffer size 14000
3. Max video bitrate 2MBps
I need all 3 of these conditions. I will reduce the keyint if the output is too slow to start. Can someone tell me how I can achieve this using x264opts?
Re: ffmpeg using crf and bufsize
Quote:
Originally Posted by
wotdefcuk
so here is what i am try to do.
1. Use crf 20
2. Max buffer size 14000
3. Max video bitrate 2MBps
I need all 3 of these conditions. I will reduce the keyint if the output is too slow to start. Can someone tell me how I can achieve this using x264opts?
I believe the command line you are looking for is:
Code:
-c:v libx264 -crf ${CRF} -maxrate ${maxBitrate}k -bufsize ${bufSize}
Example:
ffmpeg -i "INPUT" -c:v libx264 -crf 20 -maxrate 2000k -bufsize 14000 -x264opts ref=3:deblock=0,-1 -c:a libfdk_aac -vbr 2 "OUTPUT"
Cheers!