[FFmpeg-user] Understanding two pass encoding
Henk D. Schoneveld
belcampo at zonnet.nl
Sat Aug 8 18:24:26 CEST 2015
On 08 Aug 2015, at 14:46, Robin Lery <robinlery at gmail.com> wrote:
> Yes, thank you. I understand now. However I tried doing two pass multiple
> output with one input like this:
>
> ffmpeg -i mi6.mp4 \
> -codec:v libx264 -tune zerolatency -profile:v main -preset medium -b:v
> 1000k -maxrate 1000k -bufsize 10000k -s hd720 -threads 0 -pix_fmt yuv420p
> -pass 1 -passlogfile unique_id-hd720 -an -f mp4 /dev/null \
> -codec:v libx264 -tune zerolatency -profile:v baseline -level 3.0
> -preset medium -b:v 250k -maxrate 250k -bufsize 2500k -vf
> scale="trunc(oh*a/2)*2:360" -threads 0 -pix_fmt yuv420p -movflags
> +faststart -pass 1 -passlogfile unique_id-360 -an -f mp4 /dev/null && \
> -codec:v libx264 -tune zerolatency -profile:v main -preset medium -b:v
> 1000k -maxrate 1000k -bufsize 10000k -s hd720 -threads 0 -pix_fmt yuv420p
> -pass 2 -passlogfile unique_id-hd720 -codec:a libfdk_aac -movflags
> +faststart output/mi6-poty-720.mp4 \
> -codec:v libx264 -tune zerolatency -profile:v baseline -level 3.0
> -preset medium -b:v 250k -maxrate 250k -bufsize 2500k -vf
> scale="trunc(oh*a/2)*2:360" -threads 0 -pass 2 -passlogfile unique_id-360
> -codec:a libfdk_aac -pix_fmt yuv420p -movflags +faststart
> output/mi6-poty-360.mp4
>
>
> When I run this command first I get this:
>
> File '/dev/null' already exists. Overwrite ? [y/N] y
>
> File '/dev/null' already exists. Overwrite ? [y/N] y
>
>
> Afterward there's two file with the specified name, but the file size is 0.
> What's going on?
former mail talks about
/dev/nul
NOT
/dev/null
>
>
>
> On Thu, Aug 6, 2015 at 7:56 PM, Moritz Barsnick <barsnick at gmx.net> wrote:
>
>> Hi Robin,
>>
>> On Thu, Aug 06, 2015 at 19:42:39 +0530, Robin Lery wrote:
>>> 2nd pass has more frames than 1st pass
>>
>> Because you didn't do a first pass. ;-)
>>
>>> So, my concern is how will ffmpeg know which one is the first pass so
>> that
>>> it can do its pass 2 encoding?
>>
>> ffmpeg stores its findings from the first pass in a log file, and
>> reuses that during its second pass.
>>
>>> And since many videos will be uploaded simultaneously I can't keep
>>> them all at the /dev/null as it will replace one with another. So how
>>> can I manage it?
>>
>> If your Unix system is set up correctly, /dev/null has plenty of space
>> for holding _all_ the first pass videos. ;-) (If you don't get the
>> joke: Read up on /dev/null.)
>>
>> The problem will be that the log files will interfere with each other.
>> Please do read ffmpeg's fine documentation on 2-pass encoding:
>>
>> ‘-pass[:stream_specifier] n (output,per-stream)’
>>
>> Select the pass number (1 or 2). It is used to do two-pass video
>> encoding. The statistics of the video are recorded in the first
>> pass into a log file (see also the option -passlogfile), and in the
>> second pass that log file is used to generate the video at the
>> exact requested bitrate. On pass 1, you may just deactivate audio
>> and set output to null, examples for Windows and Unix:
>>
>> ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y NUL
>> ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y /dev/null
>>
>> ‘-passlogfile[:stream_specifier] prefix (output,per-stream)’
>>
>> Set two-pass log file name prefix to prefix, the default file name
>> prefix is “ffmpeg2pass”. The complete file name will be
>> ‘PREFIX-N.log’, where N is a number specific to the output stream
>>
>> This means if you do parallel encoding, you need to give each encode a
>> unique file name prefix with "-passlogfile". You can generate unique
>> file names (or prefixes) using "mktemp". For a web app like yours, I
>> would alternatively probably generate unique temporary directories, and
>> operate within them.
>>
>> HTH,
>> Moritz
>> _______________________________________________
>> ffmpeg-user mailing list
>> ffmpeg-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
More information about the ffmpeg-user
mailing list