简体   繁体   English

使用 FFmpeg 修剪视频并在其上添加回旋镖效果

[英]Trim a video and add the boomerang effect on it with FFmpeg

I have a given source video which is 30 seconds long in total.我有一个给定的源视频,总共 30 秒长。 Now I want to trimm the first 5 seconds and apply the boomerang effect on it.现在我想修剪前 5 秒并对其应用回旋镖效果。 That's the command where I am currently:这就是我目前所在的命令:

ffmpeg -i src.mp4 -y -an -filter_complex "[0]trim=start=0:end=5[a];[a]reverse[r];[a][r]concat,loop=0:250,setpts=N/30/TB" out.mp4

Im relatively new to ffmpeg and I'm trying to understand the principals, but I struggle with it a bit.我对 ffmpeg 相对较新,我正在尝试了解原理,但我有点挣扎。 After reading some docs, I understanded that the first brackets [0] are the source stream for the manipulation and the leading ending brackets are the output stream name, so I can continue to process it with other manipulations like concat etc.在阅读了一些文档后,我了解到第一个括号 [0] 是用于操作的源 stream,前导括号是 output ZF7B44CFAFD5C52223D5498196C8A2E 等名称,因此可以继续使用其他操作。

That's what I tried with [a], which should act as the output stream of my trimed video.这就是我用 [a] 尝试的,它应该充当我修剪视频的 output stream。 But this didn't worked well.但这并没有奏效。

Another approach what I found is to use -ss 0 -t 5 ,but this would trim it at the end of the processing, what would be inefficient since ffmpeg would apply my manipulation on the complete 30 seconds and throw away the 25secs afterwards.我发现的另一种方法是使用-ss 0 -t 5 ,但这会在处理结束时对其进行修剪,因为 ffmpeg 会在整个 30 秒内应用我的操作并在之后丢弃 25 秒,因此效率低下。

What did I understand wrong and how can I fix it?我理解错了什么,我该如何解决?

Something like this?像这样的东西?

ffmpeg -i src.mp4 -filter_complex "
[0]trim=start=0:end=5[a];
[0]trim=start=0:end=5,reverse[b];
[a][b]concat
" -an out.mp4 -y -hide_banner

Another approach what I found is to use -ss 0 -t 5 ,but this would trim it at the end of the processing, what would be inefficient since ffmpeg would apply my manipulation on the complete 30 seconds and throw away the 25secs afterwards.我发现的另一种方法是使用-ss 0 -t 5 ,但这会在处理结束时对其进行修剪,因为 ffmpeg 会在整个 30 秒内应用我的操作并在之后丢弃 25 秒,因此效率低下。

Remember that all flags apply to the next in-/output file.请记住,所有标志都适用于下一个输入/输出文件。

If you want to read only the first 5 seconds of the input file, you have to put the -ss 0 -t 5 before the -i flag:如果您只想读取输入文件的前 5 秒,则必须将-ss 0 -t 5放在-i标志之前

ffmpeg -ss 0 -t 5 -an -i src.mp4 -y -filter_complex "[0]split[b][c];[c]reverse[r];[b][r]concat" out.mp4

This will run the filter chain only on the first 5 seconds of src.mp4 .这将仅在src.mp4的前 5 秒运行过滤器链。

If you put the -ss 0 -t 5 after the input file, it will apply to the output out.mp4 instead, so the complete input file would be processed but only the first 5 seconds of the result written to out.mp4 .如果将-ss 0 -t 5放在输入文件之后,它将适用于 output out.mp4 ,因此将处理完整的输入文件,但仅将结果的前 5 秒写入out.mp4

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

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