FFMPEG reduce a video to specific file size and keep best quality
The videos have 1.5gb to 10gb, length 0.20h to 10h, and the target size should not exceed about 1gb.
Similar to the example but with the best possible quality, can libx265 be used or better option than in the example? |
Quote:
I haven't done that with ffmpeg for a while. The formula to calculate filesize for a bitrate is: Code:
(Desired_size_MB * 8350) / seconds_of_video.0) - Sound_kbps = video_bitrate Code:
((1000*8350)/3600.0) - 192 = 2127.44 Code:
ffmpeg -i file.mp4 -c:a copy -c:v libx264 -crf 18 -preset slow -r 24 -s 300x168 out.mp4 |
How can I use "-crf" for the best quality without first manually testing and calculating to get the average size from about 1gb to a maximum of 1.5gb?
The videos have very different values 1="size:3889957442, bit_rate:2108103 duration:14762", 2="size:1856409823, bit_rate:6785433 duration:2189", 3="size:1752405186, bit_rate:1841002 duration:7779". I think video1 would have to be strongly compressed by size with regard to quality because of medium bitrate and long duration, video2 would have to be compressed a little more because duration is short and bitrate is high, video3 would have to be compressed with regard to quality because of longer duration and low bitrate. There are a lot of videos to be edited, so I would have to calculate a suitable crf value in my opinion. Is there a better way or can my example still be optimized? Code:
ar0=(1079775913 1371610925 1752405186 1856409823 1857346492 2035982939 3889957442); ar1=(4338506 3460210 1841002 6785433 5915325 1324780 2108103); ar2=(1991 3271 7779 2189 2512 12295 14762); Quote:
|
I simplified the crasy calculation. :D
Code:
ar0=(832655422 927902511 1079775913 1371610925 1752405186 1856409823 1857346492 2035982939 3889957442); ar1=(1853011 5084258 4338506 3460210 1841002 6785433 5915325 1324780 2108103); ar2=(3595 1460 1991 3271 7779 2189 2512 12295 14762); for ((z=0; z<${#ar0[@]}; z++)); do y="${ar0[$z]}"; x="${ar1[$z]}"; w="${ar2[$z]}"; size bitrate duration = possible CRF Quote:
How can I optimize the result for CRF, and could the results be approximately suitable for the respective video size? |
Why don't you look and see how youtube does it.
Code:
yt-dlp -f 22 https://m.youtube.com/watch?v=UIYEuDs7wBA -o NovemberMan.mp4 Why don't you experiment with small segments of video. Get 3 minutes of your video. Code:
ffmpeg -ss 00:01:00 -t 00:04:00 -i Myvid.mp4 -c:a copy -c:v copy Test1.mp4 Code:
ffmpeg -i Test1.mp4 -c:a copy -c:v libx264 -crf 18 -preset slow -r 24 Out1.mp4 Docs: https://trac.ffmpeg.org/wiki/TitleIndex https://ffmpeg.org/ffmpeg.html https://linux.die.net/man/1/ffmpeg Edit: 2 pass was good for Xvid. I don't that it does much in file size for x264. |
Ok, I'll try that, hope it's comparable to compressing 3.5gb > 1gb alternatively 3.5mb > 1mb.
Thanks for the help. |
All times are GMT -5. The time now is 07:18 PM. |