Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Compression Techniques [ffmpeg] Best settings for quick images @ 720p MP4

  • [ffmpeg] Best settings for quick images @ 720p MP4

    Posted by Alex Harzy on November 22, 2012 at 10:21 am

    Hello everybody,
    I am doing some tests to find the best settings to create MP4 files using x264 codec video and MP3 audio at a resolution of 1280×720, regarding quick fluid images (action stories, fast zoomings, quick fadings, etc…).
    I am using Ubuntu 12.10 as o.s.

    Using this particular setting:
    ffmpeg -i input_file -vcodec libx264 -s 1280x720 -b 1750k -acodec libmp3lame -ac 2 -ab 160k -threads 4 output_file.mp4

    I managed to convert this full hd 1920×1080 test video (112MB) of the famous n****a graphic card
    ale@beast:~/Scrivania$ ffmpeg -i fullhd_test.mp4
    ffmpeg version 0.8.4-6:0.8.4-0ubuntu0.12.10.1, Copyright (c) 2000-2012 the Libav developers
    built on Nov 6 2012 16:51:11 with gcc 4.7.2
    *** THIS PROGRAM IS DEPRECATED ***
    This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.

    Seems stream 1 codec frame rate differs from container frame rate: 59.83 (29917/500) -> 29.92 (29917/1000)
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'fullhd_test.mp4':
    Metadata:
    major_brand : mp42
    minor_version : 0
    compatible_brands: isomavc1mp42
    creation_time : 2010-01-07 12:05:03
    Duration: 00:04:21.99, start: 0.000000, bitrate: 3427 kb/s
    [b]Stream #0.0(und): Audio: aac, 44100 Hz, stereo, s16, 125 kb/s[/b]
    Metadata:
    creation_time : 2010-01-07 12:05:03
    [b]Stream #0.1(und): Video: h264 (High), yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 3298 kb/s, 29.92 fps[/b], 29.92 tbr, 29917 tbn, 59.83 tbc
    Metadata:
    creation_time : 2010-01-07 12:05:03
    At least one output file must be specified
    ale@beast:~/Scrivania$

    into another one of 64MB (half the size!), without losing significant video quality.
    What other thngs could I do to improve it?
    I’m using “-threads 4” option ’cause I have a quad-core.

    Lou Logan replied 13 years, 4 months ago 3 Members · 14 Replies
  • 14 Replies
  • Reuben Martin

    November 23, 2012 at 8:31 pm

    There’s all kinds of things you can do; but without knowing what you want to achieve, nobody can help you.

    What is your goal? Speed, minimal file size, best quality, device compatibility, something else?

  • Alex Harzy

    November 25, 2012 at 11:02 am

    You’re right.
    I want to find the most convenient compromise between them all, in particular:

    taking for example the most common simple situation, my goal is to find out the best conversion method to turn a 90-minutes-long, high-quality-a/v movie into a .mp4-extended, libx264/mp3 file which weighs more/less 1GB.
    I want to convert it in a quite fast way (not 1:1 ratio, not two-passed!).
    I want that the quality is good, but I don’t mind having the blue-ray details!

    Thank you

  • Lou Logan

    November 26, 2012 at 3:21 am

    See the CRF section of the FFmpeg and x264 Encoding Guide. This will allow you to set a specific quality that the encoder will attempt to achieve. The basic methodology is to use the highest crf value that still gives an acceptable quality and the slowest preset that you have patience for. The link as an example and a more in-depth explanation.

    As for the audio see Encoding VBR (Variable Bit Rate) mp3 audio with FFmpeg and LAME.

  • Alex Harzy

    November 26, 2012 at 5:46 pm

    Narrowing it all down, I wrote this command and believe me, it works *flawlessly*. My jaw was on the floor when it took 1 minute to convert a full hd video of 400MB into a 70MB mp4 simil-high quality clip.

    The CRF factor was essential to my experiments.

    I tried different values: from 0 to 18 it’s the same, it copies the stream losslessly… but…. when you begin to reach 20…and couple it with the -preset veryfast command….it definitely has to be the best setting that I’ve been searching for at least one year.

    This is it:

    Converting a full hd into a 960×540 → mp4 1500k / mp3 160kbps (no map) FAST & CRF = 22
    ffmpeg -i input_file -vcodec libx264 -s 960x540 -b 1500k -preset veryfast -crf 22 -acodec libmp3lame -ac 2 -ab 160k -threads 4 output_file.mp4

    Converting a full hd into a HD 720p → mp4 1750k / mp3 160kbps (no map) FAST (30s:85s)
    ffmpeg -i input_file -vcodec libx264 -s 1280x720 -b 1750k -preset veryfast -crf 22 -acodec libmp3lame -ac 2 -ab 160k -threads 4 output_file.mp4

    Thanks Reuben Martin and Lou Logan.

    I hope this post will help all the people that had been searching good ffmpeg settings in the last years, just like me.

  • Reuben Martin

    November 28, 2012 at 3:13 am

    Get rid of the “-b” option when using crf. The b option is when you are trying to achieve a specific bitrate. This is really only needed when there are external limitations requiring you to limit the bitrate. CRF targets a specific quality and adjusts bitrate as needed to maintain that quality. The two are working with very different, and often conflicting, goals; it doesn’t make much sense to specify both.

  • Lou Logan

    November 29, 2012 at 6:52 pm

    Additionally, remove “-threads 4”. Recent ffmpeg deals with threads automatically by default (which is “-threads 0”, or number of logical processors * 1.5, rounded down), so forcing a value of “4” may not be optimal. However, you’re using the fork and not FFmpeg, and I don’t know its default behaviour.

  • Alex Harzy

    December 6, 2012 at 1:35 pm

    Thank you so much, friends.

    I narrowed it down a little more:

    ffmpeg -i input_file -vcodec libx264 -s 960x540 -preset veryfast -crf XX -acodec libmp3lame -ac 2 -ab 160k Output.mp4

    -crf XX values:
    0 – 18 for lossless
    20 for about 2500-3000 kbit/s bitrate
    21 for about 2000-2500 kbit/s bitrate
    22 for about 1500-2000 kbit/s bitrate
    23 for about 1000-1500 kbit/s bitrate
    24 – 28 for low quality files (useful for still images)

  • Lou Logan

    December 7, 2012 at 10:41 pm

    [Alex Harzy] “-crf XX values:
    0 – 18 for lossless
    20 for about 2500-3000 kbit/s bitrate
    21 for about 2000-2500 kbit/s bitrate
    22 for about 1500-2000 kbit/s bitrate
    23 for about 1000-1500 kbit/s bitrate
    24 – 28 for low quality files (useful for still images)”

    These values are probably not very useful since they can vary depending on your input and your preset.

  • Alex Harzy

    December 9, 2012 at 10:10 pm

    [Lou Logan] ” These values are probably not very useful since they can vary depending on your input and your preset.”

    Can they vary *that* much?
    I’m asking you because I couldn’t find a sort of a table displaying couples regarding # crf <—> kbit/s bitrate.

    Thank you.

  • Lou Logan

    December 9, 2012 at 10:48 pm

    [Alex Harzy]
    Can they vary *that* much?
    I’m asking you because I couldn’t find a sort of a table displaying couples regarding # crf <—> kbit/s bitrate.”

    You won’t find such information, and if you did the data would only apply to the inputs used to create the table. If you crate your own data it may give you a rough idea if your inputs all contain similar scenes. As in where the content does not vary much between each input.

    To overgeneralize, think of -crf as a ratecontrol mode to choose a certain quality. A ratecontrol will decide how many bits are give per frame–which will determine file size and how quality is distributed. With -crf the bitrate will fluctuate due to the encoder attempting to achieve the target quality. A more complex input will use more bits to achieve the desired quality, so not all inputs will use the same amount of bits to achieve a certain quality. One thing you can can estimate is that a crf value of +6 is roughly half the bitrate, and -6 is roughly twice the bitrate; meaning -crf 20 will probably use ~2x as many bits as -crf 26. The CRF Guide contains some more information.

Page 1 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy