Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Constant Bit Rate using FFMPEG

Tags:

ffmpeg

bitrate

I use FFMPEG (command line Input) to convert my videos to a specific output format. The problem I am facing is when I try to pass a constant bit rate(700 kbps) to FFMPEG, the result is an output video with a different bit rate(say 1000 kbps). This phenomenon occurs invariably for all videos.Why is this happening? I need to maintain a constant bit rate. Can anyone help me out.

My FFMPEG version is 0.5

The command line parameter which I am passing to FFMPEG is,

-i {inputfile}
-b 700k -ab 64k
-vcodec libx264
-acodec libfaac -ac 2 -ar 44100
-y -s 320x240 
{outputfile}

EDIT:

I was able to force CBR with a fluctuation of +/- 3% when I used the following parameters.

 ffmpeg -i myfile.avi
-b 4000k -minrate 4000k 
-maxrate 4000k -bufsize 1835k   out.m2v

But when I used -maxrate and - minrate along with my parameter set I was not able to force CBR. My parameter set is as follows,

-i {inputfile}
-b 1200k -minrate 1200k 
-maxrate 1200k -bufsize 1200k 
-ab 64k -vcodec libx264
-acodec libfaac -ac 2 -ar 44100
-y -s 320x240 
 {outputfile}

Why is this happening?

like image 995
user1338254 Avatar asked Jun 06 '12 05:06

user1338254


People also ask

How do I set constant bitrate in FFmpeg?

In order to output a constant bitrate video, we would be using the following FFmpeg output options : -b:v – Specifies the average target output bitrate of the video. -maxrate – Specifies the maximum bitrate tolerance. -minrate – Specifies the minimum bitrate tolerance.

What does Bufsize do in FFmpeg?

ffmpeg bufsize is simply the amount of data processed (number of bits) before ffmpeg re-calculates the current bitrate, based on the content being transcoded. You may think of bufsize as similar to key frames.

What is bit rate FFmpeg?

FFmpeg maintains the same audio channels and samples as the source file and applies a bitrate of 128Kbps.


1 Answers

Try this:

ffmpeg 
-i input 
-b 1200k 
-minrate 1200k 
-maxrate 1200k 
-bufsize 1200k 
-ab 64k 
-vcodec libx264 
-acodec aac -strict -2 
-ac 2 
-ar 44100 
-s 320x240 
-y output.mp4

Had to use aac instead of libfaac, which requires "-strict -2".

Also had to add ".mp4" to output file name.

I moved the "-y" next to the output file name since it tells it to overwrite the file, but it seemed to work where you had it too.

I did this on 64 bit OS X 10.8.4; ffmpeg version 1.2.1-tessus.

I have seen the same ffmpeg version work differently on 32 bit and 64 bit linux systems, so who knows if this will work for you.

like image 157
ox. Avatar answered Oct 17 '22 09:10

ox.