I a trying to convert my high quality movie collection to save some disk space. And I learned that 2 Pass encoding will do the job better. And this is the command line that I am using to encode videos with 2 pass.
ffmpeg -i input.mkv -c:v libx264 -vf "scale=1920x1080" -vb 3.5M -pass 1 -an pass1.mp4
ffmpeg -i input.mkv -c:v libx264 -vf "scale=1920x1080" -vb 3.5M -pass 2 -c:a copy pass2.mp4And this works fine. And I know that this command will give the output for the first pass also. That's fine. I will delete them. My doubt is, I read many forums that people use -y and -passlogfile commands in 2 pass encoding. What does -y and -passlogfile do?
Also is there any other setting can I add to improve the quality?
01 Answer
tl;dr - Just use -crf with 1-pass unless you need a specific file size
- 1 pass is faster than 2 passes.
- 2-pass does not make a better quality or smaller file: it only lets you set the output file size (but not the quality), whereas
-crflets you choose the quality (but not the file size).
Questions
I learned that 2 Pass encoding will do the job better.
Two-passes will to a better job targeting a specific output file size. Otherwise, just do a single pass with -crf.
I know that this command will give the output for the first pass also. That's fine. I will delete them.
You could output to /dev/null (Linux & macOS) or NUL (Windows) instead and avoid making a temporary file:
ffmpeg -y -i input.mkv -c:v libx264 -vf "scale=1920:1080" -b:v 3.5M -pass 1 -an -f mp4 /dev/null
ffmpeg -y -i input.mkv -c:v libx264 -vf "scale=1920:1080" -b:v 3.5M -pass 2 -c:a aac output.mp4See FFmpeg Wiki: H.264 - Two-Pass for more info and examples.
What does
-yand-passlogfiledo?
-yOverwrite output files without asking for confirmation. Makes sense for the first pass, otherwise it will ask youFile '/dev/null' already exists. Overwrite ? [y/N]. Yes, you can "overwrite"/dev/null.-passlogfileSets the two-pass log file name. You don't need to use this option unless you want to use a custom log file name instead of the default (ffmpeg2pass-0.log).
See the ffmpeg documentation for more info on these options.
Also is there any other setting can I add to improve the quality?
- Use the slowest preset you have patience for. See FFmpeg Wiki: H.264.
- Increase the bitrate.
- Use a more efficient encoder, such as libx265. See FFmpeg Wiki: H.265. Be aware that it is slow.
- Avoid upscaling. Experiment with different scaling algorithms to see what looks best to you:
"scale=1920:-2:flags=lanczos". - Buy another drive and don't re-encode.