Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two pass encoding in ffmpeg

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
like image 570
Robin Avatar asked Aug 06 '15 14:08

Robin


1 Answers

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.

Link to docs

like image 81
aergistal Avatar answered Sep 22 '22 18:09

aergistal