简体   繁体   中英

Using ffmpeg trim filter to trim a video, while preserving it's audio (with filter_complex)

I reached a part where i can cut the video with

ffmpeg -i test.mp4 -filter_complex 
'[0:v] trim=start=5:end=10,setpts=PTS-STARTPTS [cut]' -map [cut]  output.mp4

And it successfully trims the video, however it completely removes the audio. I'm trying to chain couple of different filters, so i'd like to keep the similar syntax, just to somehow preserve the audio.

You can also use the atrim filter to trim the audio and the asetpts filter to modify the audio timestamp:

ffmpeg -i test.mp4 -filter_complex \
'[0:v] trim=start=5:end=10, setpts=PTS-STARTPTS [v0]; \
 [0:a]atrim=start=5:end=10,asetpts=PTS-STARTPTS [a0]'\
 -map [v0] -map [a0]  output.mp4

Simple method for audio is to declare input twice and use -ss & -t then map this stream:

ffmpeg -i test.mp4 -ss 5 -t 5 -i test.mp4 -filter_complex 
'[0:v] trim=start=5:end=10,setpts=PTS-STARTPTS [cut]' -map [cut] -map 1:a -c:a copy output.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