gpt4 book ai didi

php - 连接多个视频php ffmpeg

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

我有多个已经编码的文件(它们具有相同的格式和大小)我想连接到一个视频(已经存在并且必须被覆盖)。

关注 official FAQ Documentation我应该使用解复用器

FFmpeg has a concat demuxer which you can use when you want to avoid a re-encode and your format doesn’t support file level concatenation.



问题是我应该使用 .txt使用此命令行的文件列表文件
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output
在哪里 mylist.txt应该:
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

我该如何使用 PHP?

也尝试使用 concat 协议(protocol)

我也尝试使用 concat protocol使用这些代码行重新编码视频:
$cli = FFMPEG.' -y -i \'concat:';

foreach ($data as $key => $media) {
$tmpFilename = $media['id'];
$tmpPath = $storePath.'/tmp/'.$tmpFilename.'.mp4';

if ($key != ($dataLenght - 1)) {
$cli .= $tmpPath.'|';
} else {
$cli .= $tmpPath.'\'';
}
}

$cli .= ' -c copy '.$export;
exec($cli);

生成此命令行:
/usr/local/bin/ffmpeg -i 'concat:/USER/storage/app/public/video/sessions/590916f0d122b/tmp/1493768472144.mp4|/USER/storage/app/public/video/sessions/590916f0d122b/tmp/1493767926114.mp4|/USER/storage/app/public/video/sessions/590916f0d122b/tmp/1493771107551.mp4|/USER/storage/app/public/video/sessions/590916f0d122b/tmp/1493771114598.mp4' -c:v libx264 /USER/storage/app/public/video/sessions/590916f0d122b/tmp_video_session.mp4
但我收到了这个错误:
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc8aa800000] Found duplicated MOOV Atom. Skipped it

最佳答案

这里唯一真正的技巧是使用 tempnam 创建一个临时文件。 :

//Generate a unique temporary file name, preferably in "/tmp"
$temporaryFileName = tempnam('/tmp/');

$cli = FFMPEG." -f concat -safe 0 -i $temporaryFileName -c copy $export";

$temporaryFile = fopen($temporaryFileName, 'w');

foreach ($data as $key => $media) {
$tmpFilename = $media['id'];
$tmpPath = "file $storePath/tmp/$tmpFilename.mp4\n";

//Write "$tmpPath" to our temporary file
fwrite($temporaryFile, $tmpPath);
}

//Close our file resource
fclose($temporaryFile);

exec($cli);

//Clean up the temporary text file
unlink($temporaryFileName);

请记住,我没有运行此代码,但想法就在这里。

关于php - 连接多个视频php ffmpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43749522/

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