Lets say I have sample video named "samplevideo"
and sample audio named "sampleaudio"
. I want to replace the audio of the samplevideo with the sampleaudio starting from 5 sec to 12 sec. Until 5 sec mark the video audio won't change, then sampleaudio starts and lasts for 7 sec.
I tried to come up with ffmpeg command that solves this problem:
ffmpeg -i samplevideo.mp4 -i sampleaudio.aac -ss 20 -map 0:v -map 1:a -c:v copy output.mp4
Problem:
It cuts video starting from 20 sec time mark. What I want is to persist the video and the original audio stream until it hits desired time mark and then use sampleaudio until desired end time.
I would appreciate any help.
Just use amix with selective muting.
ffmpeg -i samplevideo.mp4 -i sampleaudio.aac \
-filter_complex "[0:a]volume=0:enable=between(t\,5\,12)[a0];\
[1:a]atrim=0:7,adelay=5s:all=1[a1];\
[a0][a1]amix=normalize=0:duration=first[aout]"
-map 0:v -map [aout] -c:v copy output.mp4
Use ffmpeg 5.0