我使用以下代码,该代码用于:
变量
$filePath = '/home/mywebsite/public_html/assets/videos/';
$convertfile = $filePath.'convert-videos-2.txt';
$watermark = $filePath.'watermark.png';
$preroll = $filePath.'preroll.mp4';
$video = $filePath.'Video.mp4';
$video_watermark = str_replace(".mp4","-watermark.mp4",$video);
$newVideo = $filePath.'Video-New.mp4';
$postroll = $filePath.'postroll.mp4';
$input1 = $filePath.'input1.ts';
$input2 = $filePath.'input2.ts';
$input3 = $filePath.'input3.ts';向原始mp4添加水印
$mark = "ffmpeg -y -i '".$video."' -i '".$watermark."' -filter_complex \"overlay=10:10\" '".$video_watermark."'";
exec($mark);转换为ts (视频传输流)
exec("ffmpeg -i '".$preroll."' -c copy -bsf:v h264_mp4toannexb -f mpegts '".$input1."'");
exec("ffmpeg -i '".$video_watermark."' -c copy -bsf:v h264_mp4toannexb -f mpegts '".$input2."'");
exec("ffmpeg -i '".$postroll."' -c copy -bsf:v h264_mp4toannexb -f mpegts '".$input3."'");创建带有新.ts文件的级联txt文件
$cmd = "echo \"file '".$input1."'\n";
$cmd.="file '".$input2."'\n";
$cmd.="file '".$input3."'\" > ".$convertfile;
exec($cmd);创建输出mp4
exec("ffmpeg -f concat -safe 0 -y -i '".$convertfile."' -c copy -bsf:a aac_adtstoasc '".$newVideo."'");这是可行的,但要用很长时间。对于1GB或更高的mp4,最多需要3个小时?单是水印就需要1小时以上。如何优化这段代码?合并命令?我该怎么解决?
我尝试在生成下面的第二个.ts文件时添加水印,但不起作用,返回请求输出流0:0的错误流,这是从一个复杂的过滤器图输入的。过滤和流复制不能一起使用.
exec("ffmpeg -y -i '".$video."' -i '".$watermark."' -filter_complex \"overlay=10:10\" -c copy -bsf:v h264_mp4toannexb -f mpegts '".$input2."'");发布于 2021-08-17 17:10:15
这些都是水印吗?简单的答案是懒惰,避免做所有这些水印,任何人都不会关心或注意到。
无论如何,不需要.ts中间体。
-preset (但要确保这不会导致与preroll.mp4和postroll.mp4不同的属性)。input.txt包含:
文件'preroll.mp4‘文件'main.mp4’文件'postroll.mp4‘https://stackoverflow.com/questions/68817865
复制相似问题