I am a newer user to ffmpeg, but I have a slightly complicated use case for it. I need to be able to cut multiple sections out of a video and/or multiple sections out of the audio, with the actual length of the video and audio files remaining intact (e.g. the audio would cut out but the video continues, or the video continues but the audio cuts out). I have been slowly learning about complex filtergraphs, but a little help would be VERY much appreciated.
this is currently my super basic "test script" to see if I can get it to work (in it's actual use case, the timestamps will be variables in a python program)
ffmpeg -i bdt.mkv -filter_complex
[0:v]trim=start=10.0:end=15.0,setpts=PTS-STARTPTS[0v];
[0:a]atrim=start=10.0:end=15.0,asetpts=PTS-STARTPTS[0a];
[0:v]trim=start=65.0:end=70.0,setpts=PTS-STARTPTS[1v];
[0:a]atrim=start=65.0:end=70.0,asetpts=PTS-STARTPTS[1a];[0v][0a][1v]
[1a]concat=n=2:v=1:a=1[outv][outa] -map [outv] -map [outa] out.mp4
Use timeline option enable
with the between
expression. For video, you can use the overlay
filter.
-vf color=black[b_];
[b_][0:v]scale2ref[b][in];
[in][b]overlay=shortest=1:enable='between(t,1,2)'
For audio, use the volume
filter:
-af volume=0:enable='between(t,1,2)'
You'll need to escape '
s. If you want to do more complex on/off's build up enable
option using additional expressions (see the link above).
These aren't the only way to achieve the effect, but the easiest I could think of atm.