简体   繁体   English

使用 filter_complex 时如何使用 ffmpeg 修剪视频?

[英]how to trim videos with ffmpeg when using a filter_complex?

I am using a complex_filter with ffmpeg to join multiple video-files.我正在使用带有 ffmpeg 的 complex_filter 来加入多个视频文件。

ffmpeg -i video1.webm -i video2.webm -v debug -strict -2 -filter_complex "[0:v] [0:a:0] [1:v] [1:a:0] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4

This is working for me.这对我有用。 But now i want to select a start and an endpoint for EACH input video, so that i can cut each of the videos.但是现在我想为每个输入视频选择一个起点和一个终点,以便我可以剪切每个视频。

I already tried我已经试过了

ffmpeg -i video1.webm -ss 00:00:01.000 -t 00:00:05.658 -i video2.webm -ss 00:00:01.000 -t 00:00:05.658 -v debug -strict -2 -filter_complex "[0:v] [0:a:0] [1:v] [1:a:0] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4

But that wasn't working as expected.但这并没有按预期工作。 also the -to parameter is not working. -to 参数也不起作用。

Is it possible to do this with a complex filter?是否可以使用复杂的过滤器来做到这一点?

John Carmack of Oculus says that you can use this ( https://mediamachine.io/blog/ffmpeg-series-complex-filters-trim-concat/ ): Oculus 的 John Carmack 说你可以使用这个( https://mediamachine.io/blog/ffmpeg-series-complex-filters-trim-concat/ ):

ffmpeg \
-i "$INPUT_FILE_1" \
-i "$INPUT_FILE_2" \
-i "$INPUT_FILE_3" \
-filter_complex \
"[0:v]trim=start=5:duration=10,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=start=5:duration=10,asetpts=PTS-STARTPTS[a0]; \
 [1:v]trim=start=20:duration=10,setpts=PTS-STARTPTS[v1];
 [1:a]atrim=start=20:duration=10,asetpts=PTS-STARTPTS[a1]; \
 [2:v]trim=start=20:duration=10,setpts=PTS-STARTPTS[v2];
 [2:a]atrim=start=20:duration=10,asetpts=PTS-STARTPTS[a2]; \
 [v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[final]" \
-map "[final]" concat-video.mp4

So, for your example所以,对于你的例子

ffmpeg -i video1.webm -i video2.webm  -v debug -strict -2
-filter_complex 
"[0:v]trim=start=1:duration=4.658[v0]
[0:a:0]atrim=start=1:duration=4.658[a0]
[1:v]trim=start=1:duration=4.658[v1]
[1:a:0]atrim=start=1:duration=4.658[a1]
[v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]"
-map "[v]" -map "[a]" output.mp4

I'm pretty sure you only need the setpts stuff if your videos are trimmed from different starting locations.如果您的视频是从不同的起始位置修剪的,我很确定您只需要 setpts 内容。

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

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