Generate new video from selected seconds of a long

2019-03-01 01:02发布

I try to generate a shorter version of a 10min original videofile.mp4 that includes only four 10s subclips of the original file (i.e. from seconds 10 to 20;197 to 207;393 to 403;570 to 580). So far I could only generate 4 new files copying both video and audio:

ffmpeg -i videofile.mp4 -vcodec copy -acodec copy -ss 10 -to 20 videofile1.mp4 -vcodec copy -acodec copy -ss 197 -to 207 videofile2.mp4 -vcodec copy -acodec copy -ss 393 -to 403 videofile3.mp4 -vcodec copy -acodec copy -ss 570 -to 580 videofile4.mp4

However, I am having deep trouble in concatenating those 4 subclips to generate the desired 40seconds out_videofile.mp4. I found this alternative approach using the "select" command in ffmpeg which saves me of my "failed" concatenation process. So far I have:

ffmpeg -i videofile.mp4 -vf "select='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)" out_videofile.mp4

I guess this last code should give me the 40s out_videofile.mp4 I want. However, it gives me a "SyntaxError: invalid syntax". Any idea where I go wrong?

Thanks for your time anyways.

1条回答
可以哭但决不认输i
2楼-- · 2019-03-01 01:17

You're missing a closing quote, but also a filter for smoothing the audio timestamps.

Use

ffmpeg -i videofile.mp4 -vf "select='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',asetpts=N/SR/TB" out_videofile.mp4
查看更多
登录 后发表回答