I've been fighting with this dilemma for about a week or two now and I've tried my best to understand it from whatever I can find through google.

What I need (or at least I think I need) to do is calculate the bitrate to determine the mbps, if it's over my requirement (720p @ 4mbps) then I want to optimise the video, if it's below my requirement then it's just a matter of copying the file to an mp4 container.

Now I have my own code for FFmpeg, which I will attach below, and I found that there are alternative applications that will provide me with kbps calculated from the file, but I want to do as much of this as possible with only one application if I can.

I'm not asking anyone to code anything here, but more so to tell me how I can calculate this myself using the information I get from FFmpeg or even FFprobe, and what parameters I'd need to set within FFmpeg to make sure that the video file is encoded to stream at 4mbps.

ffmpeg -i "input.file" -map 0:0 -map 0:1 -map 0:1 -r 30 -profile:v Main -level:v 4.0 -crf 19 -c:a:0 copy -b:a:0 448k -metadata:s:a:0 language="english" -metadata:s:a:0 title="AC3 5.1" -c:a:1 libfdk_aac -ac:a:1 2 -b:a:1 160k -metadata:s:a:1 language="english" -metadata:s:a:1 title="AAC Stereo" -movflags +faststart "output.file"

Thanks in advance.

Update to my original code

This new code includes the bitrate buffsize and maxrate (if needed), in my script, if the fps is over 30 it will be set to 30, otherwise it was left alone, but if the fps is uncertain, example 23.970542342, this can produce an error in FFmpeg, I thought "-r 23.97" would fix this but apparently not, so I had to change "-r" to "-filter:v fps=" and set the fps for my files by calculating the "r_frame_rate", which is easy enough.

My new code

ffmpeg -i "input.file" -map 0:0 -map 0:1 -map 0:1 -filter:v fps=30 -profile:v Main -level:v 4.0 -crf 18 -b:v 4000k -bufsize 4000k -maxrate:v 4000k -metadata title="" -metadata year="" -c:a:0 copy -metadata:s:a:0 language="english" -metadata:s:a:0 title="AC3 5.1" -c:a:1 libfdk_aac -ac:a:1 2 -b:a:1 160k -metadata:s:a:1 language="english" -metadata:s:a:1 title="AAC Stereo" -movflags +faststart "output.file"

In the script that I'm building, it's going to generate the appropriate parameters for FFmpeg, so if the codec is not x264, if profile:v is not main, if level:v is not 4.0, if bit_rate is more than 4000k, then all the needed parameters will be set, otherwise it gets copied.

FFprobe Code from Mulvya, slightly modified so I can get everything I need from it.

ffprobe -v error -select_streams v -show_entries stream="bit_rate,codec_name,profile,level,r_frame_rate" -of compact=p=0:nk=1 "input.file"

Goal at the end of this is to have my own automation script to encode my videos from a folder, I know about sickbeard mp4 automator, but I don't need all those features, and there are things I want that it doesn't have.

1 Answer 1


The ffprobe command below will spit out the bitrate:

ffprobe in.mp4 -select_streams v -show_entries stream=bit_rate -of compact=p=0:nk=1



If the result is greater than 4000000 then you can add -b:v 4000k -bufsize 4000k -maxrate:v 4000k. Or you can add it anyway. Set -c:v to copy if the stream is under 4000000 else to libx264. The three values will be ignored just like -b:a:0 448k in your command is.

  • Thank you @Mulvya the bit_rate was slightly confusing for me, so I assume bit_rate is bits per second? and 4000000 = 4 Mbps?, I'll test this out and get back asap. The command "-b:a:0 448k" and even "-b:a:1 160k", doesn't get ignored when I run my current script, if I was to output the info, both audio streams display what I set, as for bit_rate, I didn't think of just comparing it to the overall bit_rate, I thought there was more to it than that lol.
    – Rycore
    Jan 19, 2017 at 15:04
  • When c:a is set to copy for a stream, the b:a is inert as there's no encoding being performed.
    – Gyan
    Jan 19, 2017 at 16:15
  • Ah right, I took a look at the files they already had the 448k audio, so it makes sense why it was always the same as my output lol. Just a quick thought and last question lol, can't I just use "-maxrate:v" on its own during the encoding to ensure it doesn't exceed my requirement? or would it be more practical to include "-b:v" and "-buffsize"?
    – Rycore
    Jan 21, 2017 at 17:24
  • If -b:v is not set, then the default value (200k) is used, or in the case of x264, CRF mode is used instead of bitrate targeting.
    – Gyan
    Jan 21, 2017 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.