two pass encoding in ffmpeg
When you use 2-pass encoding, the first pass will create log
files using the ffmpeg2pass-X
naming convention where X
is the stream number.
You can use the -passlogfile
option to set a custom prefix for your files. Example:
-passlogfile your_unique_video_id
This will create a file named your_unique_video_id-0.log
for the stream 0.
Robin
Updated on August 08, 2020Comments
-
Robin almost 4 years
I will be encoding different videos uploaded by the user asynchronously in my server. I saw this post, and according to this, this is how to endcode two pass encoding:
ffmpeg -y -i input -c:v libx264 -preset medium -b:v 555k -pass 1 -c:a libfdk_aac -b:a 128k -f mp4 /dev/null && \ ffmpeg -i input -c:v libx264 -preset medium -b:v 555k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4
I noticed the -pass 1 and -pass 2 flags. But I tried encoding a video by just giving it a -pass 2 flag without first encoding in -pass 1 flag. Although I had this warning, it executed anyway:
2nd pass has more frames than 1st pass
So, my concern is how will ffmpeg know which one is the first pass so that it can do its pass 2 encoding? And since many videos will be uploaded simultaneously I can't keep them all at the /dev/null won't it will replace one with another. So how can I manage it?
Your help and guidance will be very much appreciated.
Thank you.
Upadate
ffmpeg cmd:
ffmpeg -i input.mp4 -codec:v libx264 -tune zerolatency -profile:v main -preset medium -b:v 1500k -maxrate 1500k -bufsize 15000k -s hd720 -threads 0 -pass 1 -an -f mp4 /dev/null ffmpeg -i input.mp4 -codec:v libx264 -tune zerolatency -profile:v main -preset medium -b:v 1000k -maxrate 1000k -bufsize 10000k -s hd720 -threads 0 -pass 2 -codec:a libfdk_aac -movflags +faststart output.mp4
-
Robin almost 9 yearsHello, I didn't quite grasp the idea here. If I am using
-passlogfile unique-id
I don't need to use-pass
flag? Would you please kindly update your answer with the commands that I will use (updated my question with the commands). -
aergistal almost 9 yearsYou keep the
-pass N
argument because that makes ffmpeg do 2-pass and add the-passlogfile
with the same value for both passes so it uses the same log files for a particular video. Don't hesitate to click on that documentation link :) -
Robin almost 9 yearsOk. Now I get it. One last confusion, About /dev/nul. How do I manage different files? As the server may encode many videos in parallel, it will get replaced by the present encoding.
-
aergistal almost 9 years
/dev/null
is the null device file, not an ordinary file. It discards all data sent to it since the purpose of pass-1 is to create the log file. The actual encoding is done in the second pass using the information from pass 1. -
Robin almost 9 yearsSo its ok to point all the pass-1 to /dev/nul with -passlogfile? I am sorry if these are noob questions but I am a windows guy please bear with me. :)
-
aergistal almost 9 yearsYes, during the first pass the required information goes to the
passlogfile
and the encoding to/dev/null
. During the second pass it uses the information inpasslogfile
and saves the encoded video as anmp4
. So pass-1 creates alog
file and no video and pass-2 uses thelog
file and creates the video.