Reputation: 888
Hey guys so I'm making this command for ffmpeg which objective is to create a overlay of 2 videos and a couple images but now I need to mute the first video while the second one is playing. Would this be possible to do in ffmpeg in a single filter complex with out having to run ffmpeg to mute and then run it again for the overlays?
My current filter complex in case it helps understand what im doing
-filter_complex
"[0]crop='min(ih,iw)':'min(ih,iw)':'iw/2':'ih/2'[cropped];
[1]trim=end_frame=1,
geq='st(3,pow(X-(W/2),2)+pow(Y-(H/2),2));if(lte(ld(3),pow(min(W/2,H/2),2)),255,0)':128:128,
setpts=N/FRAME_RATE/TB[mask];
[1][mask]alphamerge[cutout];
[cropped][cutout]overlay=x='{x}':y='{y}'[v];
[0][1]amix=2[a]"
-map "[v]"
-map "[a]
Very resumed what Im looking for is a way to mute the first video for the total length of the second video and then unmute.
Upvotes: 0
Views: 321
Reputation: 5523
A couple ideas. Both of which you need to know the start and end time of the overlay
-filter_complex \
...
[0]asegment=20[kill][keep]; \
[kill]anullsink; \
[keep]adelay=20000,[1]amix=2[a]"
Then set -ss
/-t
/-to
on the audio-only input to only load what you want to hear, and use adelay
filter to make the audio start at the time specified by -ss
filter.
ffmpeg -an -i video1.mp4 -i video2.mp4 -ss 20 -vn -i video1.mp4 \
-filter_complex ...;[2]adelay=20000:1,[1]amix=2[a] \
...
If video2 goes into the middle of the output video, you need to add another audio-only input for the second video1 audio segment.
2a. Use -f concat
or concat
Using this idea of specifying input file multiple times, you can use various stream concatenation methods.
asendcmd
and astreamselect
-filter_complex \
...
asendcmd='[0:a]asendcmd='20 astreamselect map 1', \
[1:a]astreamselect=inputs=2:map=0[a]
Video2 placed in the middle of video1, you need to use start-stop [enter] ..., [leave] ...
command for asendcmd
.
Curious to see if others have a better solution.
Upvotes: 1