简体   繁体   English

如何优化FFMPEG /编辑视频?

[英]How to optimize FFMPEG/ Editing video?

I have the next commands for editing video but all the process take a long time. 我有下一个用于编辑视频的命令,但是所有过程都需要很长时间。 But with the same quality of the original video. 但是具有与原始视频相同的质量。

//First cut original video
exec("ffmpeg -i $video_path_main -ss $first_time1 -t $first_time2 -s 476x268 -r 10 -b 2000k -r 30 -g 100 -ar 22050 -ab 48000 -ac 1 -strict -2 $name_first");
exec("ffmpeg -i $video_path_main -ss $second_time1 -t $second_time2 -s 476x268 -r 10 -b 2000k -r 30 -g 100 -ar 22050 -ab 48000 -ac 1 -strict -2 $name_second");

$name_edit_second = uniqid() . '.mp4'; //Then editing the second video
exec("ffmpeg -i $name_second -s 476x268 -r 10 -b 2000k -r 30 -g 100 -ar 22050 -ab 48000 -ac 1 -strict -2 -vf movie='" . $image_name . " [watermark]; [in] [watermark] overlay=308:43"."' $name_edit_second");

//Then merge video file mp4 with Mencoder
$name_total_1 = uniqid() . '.mp4';
exec("mencoder -oac pcm -ovc xvid -vf scale -xvidencopts bitrate=460 -o $name_total_1 ".$name_first.' '.$name_edit_second);

//Then convert the video to 3 formats that is necessary in my Player.
$name_total = uniqid();

//Of MP4 a FLV
exec("ffmpeg -i $name_partial -f flv -s 476x268 -r 10 -b 2000k -r 30 -g 100 -ar 22050 -ab 48000 -ac 1 $name_total.flv");

//Of MP4-Mencoder a MP4-FFMPEG
exec("ffmpeg -i $name_partial -s 476x268 -r 10 -b 2000k -r 30 -g 100 -ar 22050 -ab 48000 -ac 1 -strict -2 $name_total.mp4"));

//Of MP4 a WEBM
exec("ffmpeg -i $name_partial -acodec libvorbis -s 476x268 -r 10 -b 2000k -r 30 -g 100 -ar 22050 -ab 48000 -ac 2 -f webm $name_total.webm");

I don't know if some of parameters take much time for all the process. 我不知道某些参数在整个过程中是否花费大量时间。 Or if one of this command take much time. 或者,如果此命令之一需要花费很多时间。

Note: Some videos have more than 2 parts of their original videos. 注意:某些视频的原始视频包含2个以上的部分。


UPDATE 更新

Maybe the parameter -theards 1 help me in NO take a lot of resources of the CPU. 也许-theards 1参数-theards 1帮助我不占用大量CPU资源。 Also, I need to optimize the re-encoding because with only 8 users take the 100% of resources. 另外,我还需要优化重新编码,因为只有8个用户占用了100%的资源。

I run FFMPEG in a other server that return the video edited to other server where stay my application. 我在另一台服务器上运行FFMPEG,将编辑过的视频返回到其他服务器,并保存在我的应用程序中。

Sorry for my english. 对不起我的英语不好。

Make segments and overlay image 进行分段和覆盖图像

ffmpeg -i input.flv -i image.jpg -ss 30 -t 5 -c:v libx264 -preset medium \
-crf 23 -filter_complex overlay=308:43 -c:a libfaac -q:a 100 output1.mp4

ffmpeg -i input.flv -i image.jpg -ss 60 -t 5 -c:v libx264 -preset medium \
-crf 23 -filter_complex overlay=308:43 -c:a libfaac -q:a 100 output2.mp4

Concatenate the segments and encode 连接片段并编码

First make the file list that the demuxer will read from. 首先创建要从中解复用器读取的文件列表。 It is named list.txt in this example: 在此示例中,它名为list.txt

echo "file 'output1.mp4'" >> list.txt
echo "file 'output2.mp4'" >> list.txt

The contents of list.txt are simply: list.txt的内容很简单:

file 'output1.mp4'
file 'output2.mp4'

Now concatenate the videos output1.mp4 and output2.mp4 using the concat demuxer . 现在使用concat demuxer连接视频output1.mp4output2.mp4 The demuxer will use the files listed in list.txt as inputs: list.txt将使用list.txt列出的文件作为输入:

ffmpeg -f concat -i list.txt -c copy -movflags faststart final.mp4
ffmpeg -f concat -i list.txt -c:v libvpx -c:a libtheora -q:a 3 final.webm

The -movflags faststart will allow the mp4 file to begin playback in JW Player before it is completely downloaded. -movflags faststart将允许mp4文件在完全下载之前开始在JW Player中播放。 You will want to add some sort of rate control method to the webm example (such as -b:v ). 您将需要向webm示例中添加某种速率控制方法(例如-b:v )。 I am unfamiliar with this encoder and the defaults are not great. 我不熟悉此编码器,默认设置也不是很好。

Now you have a file with H.264 video and AAC audio in MP4 container, and a file with VP8 video and Vorbis audio in webm container which should provide decent coverage for the various browsers. 现在,您在MP4容器中有一个带有H.264视频和AAC音频的文件,在webm容器中有一个带有VP8视频和Vorbis音频的文件,这应该为各种浏览器提供不错的覆盖范围。

See also 也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM