FFMPEG reasonable defaults

I use ffmpeg to create a watermark with a PNG file using vfilters, for example:

ffmpeg -i 26.wmv -vcodec libx264 -acodec copy -vf "movie=logo.png [watermark]; [in][watermark] overlay=10:10 [out]" 26_w.mkv 

However, the input files have different qualities / bitrates, and I want the output files to be of the same quality / bitrate for the input files. How can i achieve this? In addition, I know almost nothing about ffmpeg, so are there any options that are reasonable to set for good quality: file size ratio?

+4
source share
2 answers

Usually wanting the result to be โ€œof the same qualityโ€ as the input is an assumption 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 color space conversion, color oversampling, and other problems. However, you can achieve visually lossless (or nearly) outputs when using a lossy encoder; this means that it may look as if the result was the same for your eyes, but technically it is not. In addition, trying to use the same bit 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 

Two options to configure: -crf and -preset . CRF (constant speed coefficient) - your level of quality. Lower value - higher quality. A preset is a set of options that will give a certain encoding speed and compression compromise. A slower preset will be encoded more slowly, but will provide higher compression (compression is the quality of the file size). Main use:

  • Use the maximum crf value, which still gives you the quality you want.
  • Use the slowest preset you have patience for (see x264 --help for a list of presets and ignore the placebo preset as this is a joke).
  • Use these settings for the rest of your videos.

Other notes:

  • You do not need to encode all the videos to check the quality. You can use the -ss and -t options to select an arbitrary section for encoding, for example -ss 30 -t 60 , which will skip the first 30 seconds and generate 60 second output.

  • In this example, audio stream copy instead of re-encoding.

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

  • Add -pix_fmt yuv420p if the output doesn't play in dumb games like QuickTime.

Also see:

+15
source

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

Here is a script i made to convert files to FLV video, as well as add 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"); ?> 
0
source

Source: https://habr.com/ru/post/1393617/


All Articles