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.