While performing a 2-Pass encode to multiple output files I was receiving the error
ratecontrol_init: can't open stats file 1 ffmpeg2pass-2.log
My setup is to do a single first pass and then multiple second pass encodes to output files with different target bitrates using the same first pass results.
ffmpeg -y -i $INPUT_FILE -an -vcodec libx264 -pass 1 -b:v 700k -f rawvideo /dev/null
ffmpeg -y -i $INPUT_FILE -i out-aud.mp4 \
$AUDIO_OPTIONS_P2 -vcodec libx264 -pass 2 -b:v 250k -f mp4 out-250.mp4 \
$AUDIO_OPTIONS_P2 -vcodec libx264 -pass 2 -b:v 500k -f mp4 out-500.mp4 \
$AUDIO_OPTIONS_P2 -vcodec libx264 -pass 2 -b:v 700k -f mp4 out-700.mp4
This sequence resulted in the error listed above. What I discovered thru code-inspection is that ffmpeg/x264 looks for a different set of first-pass files for each second-pass encoding path. The first encoding path uses the set of files originally created
ffmpeg2pass-0.log
ffmpeg2pass-0.log.mbtree
The second encoding path requires first-pass files with the names
ffmpeg2pass-2.log
ffmpeg2pass-2.log.mbtree
The third encoding path requires first-pass files with the names starting with ffmpeg2pass-4*, etc.
My solution was to create soft-links to the originally created set of files with the new names that were required for each pass before running the second-pass command.
ln -s ffmpeg2pass-0.log ffmpeg2pass-2.log
ln -s ffmpeg2pass-0.log.mbtree ffmpeg2pass-2.log.mbtree
ln -s ffmpeg2pass-0.log ffmpeg2pass-4.log
ln -s ffmpeg2pass-0.log.mbtree ffmpeg2pass-4.log.mbtree
This seems to work as it results in the output encodes that I needed. However, I don't know if this method is legitimate. Am I getting sub-optimal encoding results by using a first-pass output for one bitrate (700k) as the input to second-pass encodings for other bitrates?
Use the passlogfile
option and set the log file name on the first pass. You can use the same option on the second pass and use the same log file for multiple second passes. However you need to consider things like same fps, and bframes to be same as the first pass.