FFmpeg: Keeping quality during conversion [duplicate]

Possible Duplicate:
Convert AVI to MP4 keeping the same quality

I'd like to convert a good amount of wmv, mpg and avi files (with differing audio and video encodings) to mp4/x264/aac with equivalent quality. I've done some tests with the following command:

ffmpeg.exe -i "test.avi" -c:v libx264 -c:a libvo_aacenc "test.mp4"

(As you can see, I've omitted options that specify the bitrate and quality of audio and video)

Using this command, FFmpeg automatically preserves the video dimensions, but I'm still not sure how it handles things like bitrate when they are omitted? What is the best way to keep the quality of a video while converting it to a different format and codec?

I'm using 64 bit Windows 7 and ffmpeg-20121230-git-518239c-win64-shared


Solution 1:

FFmpeg sets the -crf option to 23 by default.

Try:

ffmpeg.exe -i "test.avi" -c:v libx264 -crf 20 -c:a aac -strict -2 "test.mp4"

The CRF option sets the encode quality. The bit-rate will vary as necessary to provide a consistent quality throughout the video. 51 being the worst to 0 being the best — lossless.

I tend to set all my encodes to 20 which happens to be Handbrake’s default and I’ve been happy with the quality. I suggest playing around with that value to find a level of quality that is acceptable to you.

You might want to use the -ss and -t options to create short test encodes. -ss being the start time and -t being the duration — both in seconds. You probably don’t need to encode the entire video to determine what’s acceptable.

To create a 1min clip starting 1min into the video:

ffmpeg.exe -i "test.avi" -c:v libx264 -crf 20  -c:a aac -strict -2 -ss 60 -t 60 "test.mp4"