duanlei4759
2017-05-03 01:12
浏览 458
已采纳

连接多个视频php ffmpeg

I have multiple files that are already been encoded (they have the same format and size) I would like to concatenate on a single video (that already exist and has to be overwritten).

Following the official FAQ Documentation I should use demuxer

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.

The problem is that I should use a .txt file with a list of files using this command line

ffmpeg -f concat -safe 0 -i mylist.txt -c copy output

where mylist.txt should be:

file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

How can I do with PHP?


Also tried with concat protocol

I tried using also the concat protocol that re-encode videos with these lines of code:

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

that generate this command line:

/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

but I got this error:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc8aa800000] Found duplicated MOOV Atom. Skipped it

图片转代码服务由CSDN问答提供 功能建议

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

官方FAQ文档我应该使用demuxer

\ n

FFmpeg有一个concat demuxer,当你想避免重新编码时你可以使用它,你的格式不支持文件级连接。 < 问题是我应该使用 .txt 文件和一个使用此命令行的文件列表

ffmpeg -f concat -safe 0 -i mylist.txt -c copy output

其中 mylist.txt 应为:

 <  code> file'/ path / to / file1'
file'/ path / to / file2'
file'/ path / to / file3'
   
 
 

怎么能 我用PHP吗?


\ n

还尝试使用concat协议

我尝试使用 concat协议重新编码视频 代码:

  $ cli = FFMPEG。'  -y -i \'concat:'; 
 
foreach($ data as $ key =&gt; $ 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 < / code>

但是我收到了这个错误:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fc8aa800000]发现 复制的MOOV Atom。 跳过它

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpba63888 2017-05-03 01:33
    已采纳

    The only real trick here is making a temporary file with 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
    ";
    
      //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);
    

    Keep in mind I have not run this code, but the idea is here.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题