I'm trying to replace the first few seconds of a video with a different one, while retaining the audio from the first.
This didn't work for me (the last frame of the overlay is retained after it finishes) https://stackoverflow.com/questions/35269387/ffmpeg-overlay-one-video-onto-another-video
I also tried doing it in multiple steps:
INTRO_TIME=$(/usr/bin/ffmpeg -i intro.mkv 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,// )
rm temp1.mkv temp2.mkv
/usr/bin/ffmpeg -i $1 -i intro.mkv -filter_complex "overlay" -shortest -c:a flac -c:v libx264 -crf 18 -t ${INTRO_TIME} temp1.mkv
/usr/bin/ffmpeg -accurate_seek -ss ${INTRO_TIME} -i $1 -c:a flac -c:v libx264 temp2.mkv
DIR=$(pwd);
/usr/bin/ffmpeg -f concat -safe 0 -i <(echo file ${DIR}/temp1.mkv; echo file ${DIR}/temp2.mkv) -c copy $2
But this appears to be corrupted after the intro ends (the audio plays but the video doesn't. N.B. both temp files look ok)
Ideally I'd like the last frame of the intro to be frozen and then faded out to reveal the original video underneath.
Also, the original video(s) can be quite long, so if there's a way to do it without re-encoding the bulk of the original video, even better. (I realise re-encoding may be necessary for the duration of the intro, and maybe a few seconds beyond that)
overlay=eof_action=pass
to keep the overlay input from freezing on top after its runtime, and drop theshortest=1
. Re-encoding just the affected portion of the main video is possible but it is tedious to get it right.