使用ffmepg动态更改视频的文本/内容

时间:2015-11-10 07:51:54

标签: ffmpeg

我有视频模板,我想动态更改视频内容。尝试用ffmpeg,但我不知道如何做到这一点。可以这样做吗?如果是的话怎么做?

我尝试添加文本表单文本文件,但无法确定在某个特定时间/帧添加文本的人。

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案,它是一个php解决方案。

function videoConversion($videoId, $batchId){
$font_path = "/var/www/html/james/LeagueGothic-Regular.otf";//path of the fonts
$ffmpeg_path = "/usr/local/bin/ffmpeg";//path of the ffmpeg
$this->input_video = "/home/ec2-user/crmvid/original_videos/sept.mp4";//path of the sample video file
$this->output_video = "/var/www/html/james/final/test.mp4";//path of final output video
/* ---------code for write file -----------*/
$commandFile = '/var/www/html/james/newvideo/command/test.cmd';//path of the command file, where we write commands of video writing.
$fo = fopen($commandFile, "w");
fwrite($fo,"0.7-1.5 [enter] drawtext reinit 'fontfile=$font_path:text='Parineet':fontsize=117:fontcolor=indigo:x=480:y=315',
[leave] drawtext reinit 'fontfile=Cousine-Bold.ttf:text=';\n");
fwrite($fo,"9.5-14.2 [enter] drawtext reinit 'fontfile=$font_path:text='Chauhan':fontsize=56:fontcolor=black:x='300':y=280',
[leave] drawtext reinit 'fontfile=Cousine-Bold.ttf:text=';\n");
fwrite($fo,"14.5-17.8 [enter] drawtext reinit 'fontfile=$font_path:text='Chauhan':fontsize=72:fontcolor=indigo:x='150':y=330',
[leave] drawtext reinit 'fontfile=Cousine-Bold.ttf:text=';\n");
fclose($fo);
chmod($commandFile, 0755);
/* ---------end code for write file -------*/
$p = $commandFile;
shell_exec("$ffmpeg_path -y -i $this->input_video -vf sendcmd=f=$p,drawtext=fontfile=$font_path:text='' -vcodec h264 -acodec aac -strict -2 $this->output_video");
chmod($this->output_video, 0755);
return $this->output_video;
}