1

I'm adding overlay images to a video. and I'm trying to make the output very similar to the original video in order to get the best quality for example if the original video (like the one in the screenshot) Date Rate: 23296 kbps Total bitrate: 23613 kbps

enter image description here

My ffmpeg code will look like this:

for %%a in ("*.mp4") do C:\ffmpeg\ffmpeg.exe -threads 18 -i "%%a" -i Logo.png -filter_complex "overlay=main_w-overlay_w-40:40" -crf 23 -c:v libx264 -preset fast -profile:v high -b 15000k -maxrate 15000k -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a aac -b:a 384k -profile:a aac_low "LogoHD\%%~na.mp4"

Any suggestion to improve the output and keep it as similar to the original it will appreciate.

0

1 Answer 1

2

A basic set of improvements:

  1. change your -b 15000k -maxrate 15000k up to 23000k to match your original.
  2. Better choice of preset: Using the fast preset is likely to be, as implied, faster but if you are trying to retain quality then a slower preset may be better.
  3. Lowering crf should also retain more quality so you'll want it to be as low as possible to suit your bitrate. From the FFMPEG h.264 wiki

    A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so; it should look the same or nearly the same as the input but it isn't technically lossless.

  4. I would suggest removing -c:a aac -b:a 384k -profile:a aac_low in favour of -c:a copy so you are not transcoding audio when all you want to do is embed something in the video.
    • Your original audio is 317kbps and you are, for whatever reason, converting up to 384kbps. You are essentially wasting more data for a potential loss of quality. -c:a copy will keep the original audio without any loss, assuming your end user does not mind the format.
  5. coder 1 enables CABAC encoding which is slower but better compression so is a good option to retain quality
  6. -pix_fmt yuv420p depends on your input. I'd remove it so that you simply copy the input pixel format rather than possibly removing data. If you have a yuv444p input then you may be losing some quality by converting to yuv420p, though it may not be noticeable depending on the video.
  7. -movflags +faststart moves metadata to the start of the file so is an easy for the player to know how to play the file without downloading all of it first. It's a reasonable option if supported by your player that has no real downside as long as your using a good modern player.
  8. -g 30 and -bf 2, these are adjusting the video encoder for specific circumstances. -g 30 means that a maximum of 30 P- or B-frames are allowed in between I-frames. I-frames are the "full image" frames while other frame types are based on changes from the previous or next I-frame:
    enter image description here
    Whether you want these options depends on if you know you have lots of fast changing video. Personally I'd drop these options and let the encoder work it out, I'd only be changing them if I knew one specific video might work better with them, converting a bunch of videos it is unlikely to be helpful to all of them

My ammendments to your line would be

for %%a in ("*.mp4") do C:\ffmpeg\ffmpeg.exe -threads 18 -i "%%a" -i Logo.png -filter_complex "overlay=main_w-overlay_w-40:40" -crf 18 -c:v libx264 -preset slow -profile:v high -b 23000k -maxrate 23000k -coder 1 -movflags +faststart -c:a copy "LogoHD\%%~na.mp4"
2
  • I really appreciate your help and the afford that you put into your comment. What you think about: -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2
    – Bassel999
    Commented Apr 21, 2022 at 18:47
  • @Bassel999 edited
    – Mokubai
    Commented Apr 21, 2022 at 19:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .