gpt4 book ai didi

PHP-FFMpeg 视频输出被截断

转载 作者:行者123 更新时间:2023-12-04 23:07:59 25 4
gpt4 key购买 nike

我正在使用找到的 PHP-FFMpeg 库 here和“Basic Usage”部分的代码。

输出的视频似乎被截断了。我使用的是 28 秒长的源视频,但输出只有 9 秒。怎么了?

在这里,我正在检查源视频的持续时间:

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

28.700000



然后生成输出视频:
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('test/source.mp4');
$video->save(new FFMpeg\Format\Video\X264(), 'test/export.mp4');

然后检查输出视频的持续时间:
$ffprobe = FFMpeg\FFProbe::create();
$duration = $ffprobe
->format('test/export.mp4')
->get('duration');

9.234000

最佳答案

感谢 slhck对于suggestion调查转换日志。
看来我的源文件已损坏。
我在下面记录了我的过程。

我不知道从 PHP-FFMpeg 库中获取 ffmpeg 输出的方法。
所以我用了 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



我执行命令得到了这个错误:

[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


passlogfile似乎引起了问题,所以我将其删除并得到:

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



看来我的源视频文件已损坏。
我重新上传了它,错误消失了。

在这个过程中,我还发现“audio codec libfaac has been removed from 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');

关于PHP-FFMpeg 视频输出被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56729861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com