user6230: 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)

user1871: A command of the form below will do it:
ffmpeg -i main.mkv -i intro.mkv
   -filter_complex "overlay=eof_action=pass[v]"
   -map "[v]" -map 0:a -c:v libx264 -crf 18 -c:a copy out.mkv

If your ffmpeg build is recent, you'll need to add another option:
overlay=eof_action=pass:repeatlast=0

6230: <p>I'm trying to replace the first few seconds of a video with a different one, while retaining the audio from the first.</p>

<p>This didn't work for me (the last frame of the overlay is retained after it finishes) <a href="https://stackoverflow.com/questions/35269387/ffmpeg-overlay-one-video-onto-another-video">https://stackoverflow.com/questions/35269387/ffmpeg-overlay-one-video-onto-another-video</a></p>

<p>I also tried doing it in multiple steps:</p>

<pre><code>INTRO_TIME=$(/usr/bin/ffmpeg -i intro.mkv 2&gt;&amp;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 &lt;(echo file ${DIR}/temp1.mkv; echo file ${DIR}/temp2.mkv) -c copy $2
</code></pre>

<p>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)</p>

<p>Ideally I'd like the last frame of the intro to be frozen and then faded out to reveal the original video underneath.</p>

<p>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)</p>
 1871: <p>A command of the form below will do it:</p>

<pre><code>ffmpeg -i main.mkv -i intro.mkv
   -filter_complex "overlay=eof_action=pass[v]"
   -map "[v]" -map 0:a -c:v libx264 -crf 18 -c:a copy out.mkv
</code></pre>

<p>If your ffmpeg build is recent, you'll need to add another option:</p>

<p><code>overlay=eof_action=pass:repeatlast=0</code></p>
