Search code examples
videoffmpegjpegmp4webm

ffmpeg webm vs mp4 quality issue


I have a series of .jpg files in a directory that I want to turn into the movie with ffmpeg. When I make a .mp4 file of all the jpegs, the video quality is pretty much the same as the original images. When I make a .webm file though, it looks very blocky. These are the two commands I'm using:

$ ffmpeg -i %10d.jpg -s 640x480 -r 16 test.mp4

$ ffmpeg -i %10d.jpg -s 640x480 -r 16 test.webm

I know next to nothing about video encoding so any help would be appreciated.


Solution

  • Use -qscale n when ’n’ is between 1 (excellent quality) and 31 (worst quality).

    This actually sets a constant quality but variable bitrate.

    So now your code will look something like this when you set qscale 1:

    ffmpeg -i %10d.jpg -s 640x480 -r 16 -qscale 1 test.webm
    

    Sometimes it outputs an error as qscale is ambiguous. In such cases, use -q:v 1 instead of -qscale 1.

    Now if you still want better quality, set the bit rate too for your output file to 320 kbs.

    Now code will be:

    ffmpeg -i input.mp4 -b:v 320k -q:v 0 output.webm
    

    If you are still not satisfied with the quality, try this code:

    ffmpeg -i input.mp4 -codec:v libx264 -profile:v high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:480 -threads 0 -codec:a libfdk_aac -b:a 128k output.webm
    

    Explanation of the above so that you change it according to your needs:

    • -profile:v high: Sets H.264 profile to high. You can also use baseline,main.

    • -preset slow: Sets encoding preset for x264 (slower presets give more quality at same bitrate, but takes more time to encode); can also use ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow.

    • -b:v: Sets video bitrate in bits/s.

    • -maxrate and -bufsize: Maximum rate to be streamed 500kbit/s also looking into device buffer of 1000kbits.

    • -vf scale: Used for scaling video, based upon your requirements you can use this.

    • -threads 0: Choose optimal number of threads to encode.

    • -codec:a libfdk_aac: Sets encoder to aac through libfdk-aac library

    • -b:a: Sets audio bitrate