简体   繁体   English

PHP-FFMpeg视频输出被截断

[英]PHP-FFMpeg video output is truncated

I'm using the PHP-FFMpeg library found here and code from the " Basic Usage " section. 我正在使用此处找到的PHP-FFMpeg库和“ 基本用法 ”部分中的代码。

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. 我使用的是28秒长的源视频,但输出仅为9秒。 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 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 9.234000

Thanks to slhck for the suggestion to investigate the conversion log. 感谢slhck提供调查转换日志的建议
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. 我不知道从PHP-FFMpeg库获取ffmpeg输出的方法。
So I used getFinalCommand() to output the ffmpeg command: 因此,我使用getFinalCommand()输出ffmpeg命令:

$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 -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 [libx264 @ 0x2395ec0] ratecontrol_init:无法打开统计文件
Error initializing output stream 0:0 -- Error while opening encoder for output stream 初始化输出流时出错0:0-打开输出流编码器时出错
#0:0 - maybe incorrect parameters such as bit_rate, rate, width or height #0:0-可能是不正确的参数,例如bit_rate,rate,width或height

The passlogfile seemed to be causing problems, so I removed it and got: passlogfile似乎引起了问题,因此我将其删除并得到:

corrupt input packet in stream 0:04.76 bitrate= 880.0kbits/s speed=3.15x 流中损坏的输入数据包0:04.76比特率= 880.0kbits / s速度= 3.15x
[h264 @ 0x7b4500] Invalid NAL unit size (51618 > 33287). [h264 @ 0x7b4500]无效的NAL单位大小(51618> 33287)。
[h264 @ 0x7b4500] Error splitting the input into NAL units. [h264 @ 0x7b4500]将输入拆分为NAL单元时出错。
Error while decoding stream #0:0: Invalid data found when processing input 解码流#0:0时出错:处理输入时发现无效数据

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: 在此过程中,我还发现“音频编解码器libfaac已从ffmpeg中删除 ”( iki789 ),“还有更好的选择”( llogan ),并且音频编解码器可以设置为“ aac”,如下所示:

$format = new \FFMpeg\Format\Video\X264();
$format->setAudioCodec("aac");

$video = $ffmpeg->open('test/source.mp4');
$video->save($format, 'test/export.mp4');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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