Ffmpeg video compression / specific file size

I currently have 80 MB movies that I want to use ffmpeg to convert down to say about 10mb or 15mb. I know that there will be a loss of quality, but they will have to have a sound. Is there a way to specify file size or higher compression than what I did earlier.

ffmpeg -i movie.mp4 -b 2255k -s 1280x720 movie.hd.ogv 

They currently make up about 25 MB of fragment

+8
source share
2 answers

if you are targeting a specific output file size, it’s best to use H.264 and two-pass encoding .

There is a great example here, but it's too big for copy-paste: https://trac.ffmpeg.org/wiki/Encode/H.264

You calculate the target bitrate using bitrate = file size / duration and run ffmpeg two times: one pass analyzes the media, and the second performs the actual encoding:

 ffmpeg -y -i input -c:v libx264 -preset medium -b:v 555k -pass 1 -c:a libfdk_aac -b:a 128k -f mp4 /dev/null && \ ffmpeg -i input -c:v libx264 -preset medium -b:v 555k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4 

Edit: H.265 (HEVC) is even better when compressed (in some cases, it is 50% of the H.264 size), but support is not widespread so far, so stick with H.264.

+19
source

Here is a way to do this automatically using a bash script
Just call as ./script.sh file.mp4 15 for 15mB

 bitrate="$(awk "BEGIN {print int($2 * 1024 * 1024 * 8 / $(ffprobe \ -v error \ -show_entries format=duration \ -of default=noprint_wrappers=1:nokey=1 \ "$1" \ ) / 1000)}")k" ffmpeg \ -y \ -i "$1" \ -c:v libx264 \ -preset medium \ -b:v $bitrate \ -pass 1 \ -an \ -f mp4 \ /dev/null \ && \ ffmpeg \ -i "$1" \ -c:v libx264 \ -preset medium \ -b:v $bitrate \ -pass 2 \ -an \ "${1%.*}-$2mB.mp4" 

NB I mute audio

0
source

Source: https://habr.com/ru/post/1215465/


All Articles