简体   繁体   中英

PHP-FFMpeg video output is truncated

I'm using the PHP-FFMpeg library found here and code from the " Basic Usage " section.

The outputted video seems to be truncated. I'm using a source video that's 28 seconds long, but the output is only 9 seconds. What's going wrong?

Here, I'm checking the duration of the source video:

$ffprobe = FFMpeg\FFProbe::create();
$duration = $ffprobe
  ->format('test/source.mp4')
  ->get('duration');

28.700000

Then generating an output video:

$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('test/source.mp4');
$video->save(new FFMpeg\Format\Video\X264(), 'test/export.mp4');

Then checking the duration of the output video:

$ffprobe = FFMpeg\FFProbe::create();
$duration = $ffprobe
  ->format('test/export.mp4')
  ->get('duration');

9.234000

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM