FFMPEG sensible defaults

左心房为你撑大大i 提交于 2019-11-28 09:31:17

Usually wanting the output to be the "same quality" as the input is an assumed thing that people will always want. Unfortunately, this is not possible when using a lossy encoder, and even lossless encoders may not provide the same quality due to colorspace conversion, chroma subsampling, and other issues. However, you can achieve visually lossless (or nearly so) outputs when using a lossy encoder; meaning that it may look as if the output is the same quality to your eyes, but technically it is not. Also, attempting to use the same bitrate and other parameters as the input will most likely not achieve what you want.

Example:

ffmpeg -i input -codec:v libx264 -preset medium -crf 24 -codec:a copy output.mkv

The two option for you to adjust are -crf and -preset. CRF (constant rate factor) is your quality level. A lower value is a higher quality. The preset is a collection of options that will give a particular encoding speed vs compression tradeoff. A slower preset will encode slower, but will achieve higher compression (compression is quality per filesize). The basic usage is:

  1. Use the highest crf value that still gives you the quality you want.
  2. Use the slowest preset you have patience for (see x264 --help for a preset list and ignore the placebo preset as it is a joke).
  3. Use these settings for the rest of your videos.

Other notes:

  • You do not have to encode the whole video to test quality. You can use the -ss and -t options to select a random section to encode, such as -ss 30 -t 60 which will skip the first 30 seconds and create a 60 second output.

  • In this example the audio is stream copied instead of re-encoded.

  • Remember that every encoder is different, and what works for x264 will not apply to other encoders.

  • Add -pix_fmt yuv420p if the output does not play in dumb players like QuickTime.

Also see:

Here is a set of very good examples http://ffmpeg.org/ffmpeg.html#Examples

Here is a script i made for converting files to flv video and also adding a preview image

<?php 
$filename = "./upload/".$_GET['name'].".".substr(strrchr($_FILES['Filedata']['name'], '.'), 1);
move_uploaded_file($_FILES['Filedata']['tmp_name'], $filename);
chmod($filename, 0777);
exec ("ffmpeg -i ".$filename." -ar 22050 -b 200 -r 12 -f flv -s 500x374 upload/".$_GET['name'].".flv");
exec ("ffmpeg -i ".$filename." -an -ss 00:00:03 -an -r 1 -s 300x200 -vframes 1 -y -pix_fmt rgb24 upload/".$_GET['name']."%d.jpg");
?>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!