FFMPEG图像以不同的开始时间和持续时间为视频



我最近了解了FFMPEG的存在,我正在尝试在WordPress网站上使用它。

在网站上,我正在使用html/php/js表单页面,该页面可让用户上传图片,并在图像显示和持续时间时设置。

现在我拥有的代码仅显示整个视频的一个图像。

<?php if (isset($_POST['button'])) { 
echo shell_exec('ffmpeg -t '.$cap_1.' -i /myurl/beach-1866431.jpg -t '.$cap_2.' -i /myurl/orlando-1104481-1.jpg -filter_complex "scale=1280:-2" -i /myurl/audio.mp3 -c:v libx264 -pix_fmt yuv420p -t 30 -y /myurl/'.$v_title.'.mp4 2>&1');
 } ?>

我尝试使用我的PHP变量设置" -t",但没有任何变化,我无法弄清楚在每个图像的开始时间都使用的是什么。

另外,当编写shell_exec命令时,而不是全部都在一行上时,是否有一种方法可以在php文件中编写工作命令代码?例如 -

 <?php if (isset($_POST['button'])) { 
    echo shell_exec('ffmpeg -t '.$cap_1.' -i /myurl/beach-1866431.jpg 
    -t '.$cap_2.' -i /myurl/orlando-1104481-1.jpg 
    -filter_complex "scale=1280:-2" 
    -i /myurl/audio.mp3 
    -c:v libx264 -pix_fmt yuv420p -t 30 -y /myurl/'.$v_title.'.mp4 2>&1');
         } ?>

编辑

到目前为止,contat文本文件似乎都起作用,但是我不知道如何为每个图像设置启动时间---

ffconcat version 1.0
file /path/beach-1866431.jpg
duration 3
file /path/orlando-1104481-1.jpg
duration 5
file /path/beach-1866431.jpg

和ffmpeg命令 -

shell_exec('ffmpeg -f concat -safe 0 -i /path/file.txt -filter_complex "scale=1280:-2" -i /path/audio.mp3 -c:v libx264 -pix_fmt yuv420p -t 30 -y /path/'.$v_title.'.mp4 2>&1');

编辑2

使用建议的Concat方法,我的代码现在看起来像这样 -

<?php if (isset($_POST['button'])) { 
echo shell_exec('ffmpeg 
-loop 1 -framerate 24 -t 10 -i goldmetal.jpg 
-i 3251.mp3 
-loop 1 -framerate 24 -t 10 -i cash-register-1885558.jpg 
-loop 1 -framerate 24 -t 10 -i ice-1915849.jpg 
-filter_complex "[0:v][1:a][2:v][3:v]concat=n=4:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 /path/'.$v_title.'.mp4 2>&1');
 } ?>

但是我遇到了这个错误 -

**Stream specifier ':v' in filtergraph description [0:v][1:a][2:v][3:v]concat=n=4:v=1:a=1[v][a] matches no streams.**

编辑3

我几乎根据需要使它工作,使用2个命令,一个用于图像和淡出,另一个用于组合音频。我唯一的问题是更改每个图像显示的时间。 -

echo shell_exec('ffmpeg 
-loop 1 -t 5 -i '.$thepath .'/'.$v_pix1.' 
-loop 1 -t 5 -i ' .$thepath . '/cash-register-1885558.jpg 
-loop 1 -t 5 -i ' .$thepath . '/ice-1915849.jpg 
-loop 1 -t 5 -i '.$thepath .'/'.$v_pix1.' 
-loop 1 -t 5 -i ' .$thepath . '/ice-1915849.jpg 
-filter_complex 
"[0:v]setpts=PTS-STARTPTS,fade=t=out:st=4:d=1,scale=1280:720,setdar=16/9,setsar=sar=300/300[v0]; 
 [1:v]setpts=PTS-STARTPTS,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1,scale=1280:720,setdar=16/9,setsar=sar=300/300[v1]; 
 [2:v]setpts=PTS-STARTPTS,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1,scale=1280:720,setdar=16/9,setsar=sar=300/300[v2]; 
 [3:v]setpts=PTS-STARTPTS,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1,scale=1280:720,setdar=16/9,setsar=sar=300/300[v3]; 
 [4:v]setpts=PTS-STARTPTS,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1,scale=1280:720,setdar=16/9,setsar=sar=300/300[v4]; 
 [v0][v1][v2][v3][v4]concat=n=5:v=1:a=0,format=yuv420p[v]" -map "[v]" -y '.$thepath .'/fadeout.mp4 2>&1');

echo shell_exec('ffmpeg 
-i '.$thepath .'/fadeout.mp4 
-i '.$thepath .'/3251.mp3 
-filter_complex "[0:v:0][1:a:0] concat=n=1:v=1:a=1 [vout] [aout]" -map "[vout]" -map "[aout]" -c:v libx264 -r 1 -y '.$thepath .'/mergetest.mp4 2>&1');

此答案解决了您广泛的多个问题中的ffmpeg特定问题。

此示例将拍摄任何任意尺寸的图像,将它们放入1280x720的框中,在图像之间褪色,并同时播放音频。每当图像或音频结束时,视频都会结束:

最短。
ffmpeg 
-i audio1.mp3 
-i audio2.wav 
-loop 1 -t 5 -i image1.jpg 
-loop 1 -t 5 -i image2.png 
-loop 1 -t 5 -i image3.jpg 
-filter_complex 
"[2:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=out:st=4:d=1[v1]; 
 [3:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v2]; 
 [4:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[v3]; 
 [0:a][1:a]amerge=inputs=2[a];
 [v1][v2][v3]concat=n=3:v=1:a=0,format=yuv420p[v]" 
-map "[v]" -map "[a]" -ac 2 -shortest -movflags +faststart output.mp4

最新更新