连接多个视频php ffmpeg



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

官方常见问题文档后,我应该使用Demuxer

ffmpeg有一个concat demuxer,您可以在要避免时使用它 重新编码和您的格式不支持文件级别串联。

问题是我应该使用此命令行列表使用.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协议

尝试

我也尝试使用使用这些代码行重新编码视频的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.mp4n";
  //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);

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

最新更新