[FFmpeg-user] AWS Lambda h264 ratecontrol_init: can't open stats file

Moritz Barsnick barsnick at gmx.net
Tue Apr 16 10:41:37 EEST 2019

Hi Douglas,

On Mon, Apr 15, 2019 at 16:08:15 -0700, Douglas Rhiner wrote:
> *Pass One Command*
> os.system('/tmp/ffmpeg -y -i /tmp/789789789/789789789.mp4 -c:v libx264
> -strict -2 -b:v 7000k -maxrate 7000k -bufsize 5250.0k -vf scale=-2:960 -an
> -pass 1 -passlogfile my_passlog_789789789_960_7000 -f mp4
> /tmp/789789789/temp_789789789_960_7000')
>    - [libx264 @ 0x5d81cc0] ratecontrol_init: can't open stats file
>    - Error initializing output stream 0:0 -- Error while opening encoder
>    for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate,
>    width or height
>    - Conversion failed!

libx264 isn't very good at log messages. It obviously has an issue
accessing the "stats file", which is the two-pass file which you
specified as "my_passlog_789789789_960_7000".

To see in more detail what is going wrong, you could issue the command
with strace (with a few extra command line parameters).

My guess is: The command is being launched from a location (current
directory) where it doesn't have write access. Therefore libx264 and/or
ffmpeg cannot create "./my_passlog_789789789_960_7000". You should try
giving the "-passlogfile" a filename with a full path to a writable
location - "/tmp/my_passlog_789789789_960_7000" comes to mind as the
most obvious choice.

> *Pass two Command*

You probably shouldn't be running the second command if the first one
fails. When scripting, try to take return codes into consideration,
otherwise your scripts may fall over terribly. (Not just in the case of
using ffmpeg.) You might make assumptions that something worked - e.g.
creating a directory or removing something - and that has effects on
what happens afterwards.

Cheers and good luck,

More information about the ffmpeg-user mailing list