FFMPEG, itsoffset with overlay command not working

2019-09-16 19:45发布

问题:

I managed to overlay two videos one by another with the overlay command and use a nullsrc command to play both video till both of them ended with the following command:

./ffmpeg -i first.MOV -i second.MOV -filter_complex "nullsrc=size=1280x400:duration=30[bg];[0]scale=640:-1,pad=1280:400[first];[bg][first]overlay=0:0[base];[1]scale=640:-1[second];[base][second]overlay=640:0" output.mp4

Now what I wanted to do is to delay one of the overlay till the other one finishes. For this as far as I know the command is itsoffset, so I modified to use this:

./ffmpeg -i first.MOV -itsoffset 5 -i second.MOV -filter_complex "nullsrc=size=1280x400:duration=30[bg];[0]scale=640:-1,pad=1280:400[first];[bg][first]overlay=0:0[base];[1]scale=640:-1[second];[base][second]overlay=640:0" output.mp4

Now my only problem with this is that I want to show the first frame of the delayed video till it starts... And even though somewhere I read that this should do it, it won't. It leaves it blank till the input starts.

Any idea how could I add the first frame of second video till the itsoffset starts the video?

Update1: I may found a cheat around it, but the problem with it it's really slow in the first second or so.

./ffmpeg -i first.MOV -i second.MOV -itsoffset 5 -i second.MOV -filter_complex "color=size=1280x400:duration=30[bg];[1]select=eq(n\,0),scale=640:-1[fg];[bg][fg]overlay=640:0[bgc];[0]scale=640:-1[first];[bgc][first]overlay=0:0[firstb];[2]scale=640:-1[second];[firstb][second]overlay=640:0" output.mp4

Not to mention later on I need to dynamically create the command line string which would be really painful like this.

回答1:

For solution I ended up something like this:

./ffmpeg -i first.MOV -i second.MOV -itsoffset 5 -i second.MOV -filter_complex "color=size=1280x400:duration=30[bg];[1]select=eq(n\,0),scale=640:-1[fg];[bg][fg]overlay=640:0[bgc];[0]scale=640:-1[first];[bgc][first]overlay=0:0[firstb];[2]scale=640:-1[second];[firstb][second]overlay=640:0" output.mp4

The only problem with this I got was that for some reason the audio waasn't delayed and the overlaying images got lagging and the timestep was a bit messed up. Finally I just figured out that I need to use -async 1 and it started working like a magic. First frame showing up from the begining, audio delayed with video etc.

So the final command should look like this:

./ffmpeg -i first.MOV -i second.MOV -itsoffset 5 -i second.MOV -filter_complex "color=size=1280x400:duration=30[bg];[1]select=eq(n\,0),scale=640:-1[fg];[bg][fg]overlay=640:0[bgc];[0]scale=640:-1[first];[bgc][first]overlay=0:0[firstb];[2]scale=640:-1[second];[firstb][second]overlay=640:0" -async 1 output.mp4


回答2:

your command working perfectly in case of video but audio of second input is not playing.



标签: video ffmpeg