简体   繁体   中英

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. Now I want to trimm the first 5 seconds and apply the boomerang effect on it. 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. 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.

That's what I tried with [a], which should act as the output stream of my trimed video. 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.

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.

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:

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 .

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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