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:
source share