FORUMS: list search recent posts

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

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Alex Harzy
[ffmpeg] Best settings for quick images @ 720p MP4
on Nov 22, 2012 at 10:21:03 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 1280x720, 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 1920x1080 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.


Return to posts index

Reuben Martin
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Nov 23, 2012 at 8:31:39 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?


Return to posts index

Alex Harzy
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Nov 25, 2012 at 11:02:25 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


Return to posts index


Lou Logan
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Nov 26, 2012 at 3:21:41 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.


Return to posts index

Alex Harzy
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Nov 26, 2012 at 5:46:05 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 960x540 → 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.


Return to posts index

Reuben Martin
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Nov 28, 2012 at 3:13:21 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.


Return to posts index


Lou Logan
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Nov 29, 2012 at 6:52:19 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.


Return to posts index

Alex Harzy
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Dec 6, 2012 at 1:35:13 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)


Return to posts index

Lou Logan
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Dec 7, 2012 at 10:41:52 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.


Return to posts index


Alex Harzy
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Dec 9, 2012 at 10:10:50 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.


Return to posts index

Lou Logan
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Dec 9, 2012 at 10:48:04 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.


Return to posts index

Alex Harzy
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Dec 25, 2012 at 11:00:42 am

Hello,
I've been converting many clips and they all get good using the simple (but powerful) command of

ffmpeg -i input_file -vcodec libx264 -preset veryfast -crf 20 -acodec libmp3lame -ac 2 -ab 160k output.mp4


I can get enough quality for everything I want.

I figured out two big problems, though:

1) Sometimes, the aspect ratio of the output file is scrumbled. I mean, sometimes the video converted is unnaturally stretched in a 4:3 screen aspect. I don't know why this happens, I solved this problem by adding "-s 960x540" in the command in the video section.

2) Sometimes, when I convert a two hour mkv to a mp4, the audio is out of sync by a second or two, progressively. This means that at the beginning it's in sync, but at the end it is not anymore. How can I do to re-sync it? What can I do to convert mkv to mp4 without having this loss of sync?

Thank you and merry X-Mas everybody!


Return to posts index


Lou Logan
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Dec 25, 2012 at 9:08:55 pm

[Alex Harzy] "
1) Sometimes, the aspect ratio of the output file is scrumbled. I mean, sometimes the video converted is unnaturally stretched in a 4:3 screen aspect. I don't know why this happens, I solved this problem by adding "-s 960x540" in the command in the video section."


With what player(s) does it appear to be incorrect? It's hard to say what might be going on without the complete ffmpeg console output that appears after you run your command (excluding "-s 960x540").

[Alex Harzy] "
2) Sometimes, when I convert a two hour mkv to a mp4, the audio is out of sync by a second or two, progressively."


Does this occur using the same command you showed, or are you modifying it? Also, instead of re-encoding the MKV, you can probably simply re-mux into a MP4 container since the video stream in the MKV is most likely H.264 video which works just fine in MP4 container. Assuming your audio stream is compatible with MP4 container:

ffmpeg -i input.mkv -c copy -map 0 output.mp4


Return to posts index

Alex Harzy
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Dec 27, 2012 at 5:50:18 pm

[Lou Logan] "instead of re-encoding the MKV, you can probably simply re-mux into a MP4 container since the video stream in the MKV is most likely H.264 video which works just fine in MP4 container. Assuming your audio stream is compatible with MP4 container:
ffmpeg -i input.mkv -c copy -map 0 output.mp4"


Really?
Well I probably don't know the difference between muxing and encoding.
what would that "-c copy" and "-map 0" command do?
I'm confused :-/


Return to posts index

Lou Logan
Re: [ffmpeg] Best settings for quick images @ 720p MP4
on Dec 27, 2012 at 7:02:44 pm

[Alex Harzy] "Well I probably don't know the difference between muxing and encoding."

Think of it as a copying and pasting the video and audio into another media container format.

[Alex Harzy] "what would that "-c copy" and "-map 0" command do?"

"-c copy" enables stream copy mode, and "-map 0" will copy all streams of input 0 (the first input). By default ffmpeg includes only one stream of each type (video, audio, subtitle) present in the input files and adds them to each output file. "-map 0" overrides this default. I usually explicitly include it because users often don't know that the default behaviour may not include all streams of the input: such as in input with multiple audio streams.

See the documentation on stream copy, stream selection, and stream specifiers. Also see info on "-codec (or '-c' as an alias)" under Main options, and "-map" under Advanced options.

This is my 14th post and they are still being moderated for approval. I wonder how long that lasts.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]