Thanks to slhck for the suggestion to investigate the conversion log.
It seems that my source file was corrupt.
I documented my process below.
I'm not aware of a way to get the ffmpeg output from the PHP-FFMpeg library.
So I used getFinalCommand()
to output the ffmpeg command:
$video = $ffmpeg->open('test/source.mp4');
echo $video->getFinalCommand(new FFMpeg\Format\Video\X264(), 'test/export.mp4')[0];
-y -i test/source.mp4 -vcodec libx264 -acodec libfaac -b:v 1000k -refs 6 -coder 1 -sc_threshold 40 -flags +loop -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -trellis 1 -b:a 128k -pass 1 -passlogfile /tmp/ffmpeg-passes5d108f0d5007cirj2x/pass-5d108f0d500f9 test/export.mp4
I executed the command got this error:
[libx264 @ 0x2395ec0] 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
The passlogfile
seemed to be causing problems, so I removed it and got:
corrupt input packet in stream 0:04.76 bitrate= 880.0kbits/s speed=3.15x
[h264 @ 0x7b4500] Invalid NAL unit size (51618 > 33287).
[h264 @ 0x7b4500] Error splitting the input into NAL units.
Error while decoding stream #0:0: Invalid data found when processing input
It seems that my source video file was corrupt.
I reuploaded it and the error was gone.
In the process, I also found that "audio codec libfaac has been removed from ffmpeg" (iki789), that "there are better alternatives" (llogan), and that the audio codec can be set to "aac" like this:
$format = new \FFMpeg\Format\Video\X264();
$format->setAudioCodec("aac");
$video = $ffmpeg->open('test/source.mp4');
$video->save($format, 'test/export.mp4');