<p>You can use the concat demuxer in ffmpeg to do this. For accurate splicing, re-encoding is needed which is what the commands below do.</p>

<p><strong>Step 1</strong> Prepare the concat text file</p>

<p>You must first create a plaintext file, say, <code>concat.txt</code>, like this</p>

<pre><code>file 'LargeClip.mp4'
inpoint 0.0
duration 10.0
file 'SmallClip.mp4'
inpoint 0.0
outpoint 2.0
file 'LargeClip.mp4'
inpoint 12.0
duration 5.0
file 'SmallClip.mp4'
inpoint 23.0
duration 4.0
file 'LargeClip.mp4'
inpoint 21.0
</code></pre>

<p>This shows the first 10 seconds of LargeClip, then the first two seconds of smallclip, then resumes the Largeclip at 12:00, shows it for 5 seconds, then splices in 23:00 to 27:00 of small clip, switches back to LargeClip at its 21:00 and keeps it till its end. These timecodes, in seconds, refer to the source file timecode, not of the assembled output.</p>

<p>Make sure that the sync of LargeClip isn't broken, i.e. after switching to SmallClip for 12 seconds, you want to resume LargeClip 12 seconds later from where you left it off.</p>

<p><strong>Step 2</strong> Concat the video streams</p>

<p>This command will skip the audio since we don't to splice the audio streams.</p>

<pre><code>ffmpeg -f concat -i concat.txt -an -c:v libx264 -crf 23 -fflags +genpts spliced-vid.mp4
</code></pre>

<p><strong>Step 3</strong> Insert the audio from LargeClip</p>

<pre><code>ffmpeg -i spliced-vid.mp4 -i LargeClip.mp4 -c copy -map 0:v -map 1:a Final.mp4 
</code></pre>

CC BY-SA 3.0
2016-02-11T11:59:01.380Z
This looks like a wonderful answer - I will try it out and mark as an answer assuming it works.  Thanks!!
WoogieBoogie
CC BY-SA 3.0
2016-02-11T22:20:07.603Z
that worked thanks...with the small caveat that "duration" didn't seem to work, I replaced that with "outpoint" all the way through and it worked fine.
WoogieBoogie
CC BY-SA 3.0
2016-02-11T10:20:22.027Z
2016-02-11T10:20:22.027Z
Gyan
<p>I need to replace video in a larger mp4 file with a smaller mp4 clip - but leaving the original (larger clip) audio intact.</p>

<p>So for example I might want the first 2 seconds of SmallClip.mp4 to replace the video in LargeClip.mp4 starting at (say) 10 seconds in to LargeClip.mp4.</p>

<p>The format of both clips is likely to be identical, so I'm hoping I can copy instead of decoding for speed etc (I'll have to do it a lot).</p>

<p>Finally, I might want to do exactly the same thing but in several places in LargeClip.mp4 - all places in the output getting the video replaced with the same input clip's video.  I'd be happy to do this in multiple oerations if neccessary but if it were possible on one command so much the better :)</p>

<p>I'm reading up on the options for ffmpeg but I'm new to it and haven't figured it out yet.  Any help much appreciated!</p>

CC BY-SA 3.0
2016-02-10T15:17:54.173Z
Copying is only feasible if the resume point(s) of the large MP4 is a keyframe. Otherwise, this can be done in a couple of steps.
Gyan
CC BY-SA 3.0
2016-02-11T08:59:23.310Z
That's good to know - but how to output the small video clip at a certain point in in the large clip?  I can't figure it out.
WoogieBoogie
<ffmpeg><mp4>
inserting video clip into another video but keep original audio
WoogieBoogie
# inserting video clip into another video but keep original audio

(Asked by: username_0 on 2016-02-10)

I need to replace video in a larger mp4 file with a smaller mp4 clip - but leaving the original (larger clip) audio intact.

So for example I might want the first 2 seconds of SmallClip.mp4 to replace the video in LargeClip.mp4 starting at (say) 10 seconds in to LargeClip.mp4.

The format of both clips is likely to be identical, so I'm hoping I can copy instead of decoding for speed etc (I'll have to do it a lot).

Finally, I might want to do exactly the same thing but in several places in LargeClip.mp4 - all places in the output getting the video replaced with the same input clip's video. I'd be happy to do this in multiple oerations if neccessary but if it were possible on one command so much the better :)

I'm reading up on the options for ffmpeg but I'm new to it and haven't figured it out yet. Any help much appreciated!

**Tags:** ffmpeg, mp4

> **Comments:**
> **username_1**: Copying is only feasible if the resume point(s) of the large MP4 is a keyframe. Otherwise, this can be done in a couple of steps.  
> **username_0**: That's good to know - but how to output the small video clip at a certain point in in the large clip?  I can't figure it out.  

---

## 1 answers

### Answer by username_1 on 2016-02-11. Score: 3 | Accepted answer

You can use the concat demuxer in ffmpeg to do this. For accurate splicing, re-encoding is needed which is what the commands below do.
Step 1 Prepare the concat text file
You must first create a plaintext file, say, concat.txt, like this
file 'LargeClip.mp4'
inpoint 0.0
duration 10.0
file 'SmallClip.mp4'
inpoint 0.0
outpoint 2.0
file 'LargeClip.mp4'
inpoint 12.0
duration 5.0
file 'SmallClip.mp4'
inpoint 23.0
duration 4.0
file 'LargeClip.mp4'
inpoint 21.0

This shows the first 10 seconds of LargeClip, then the first two seconds of smallclip, then resumes the Largeclip at 12:00, shows it for 5 seconds, then splices in 23:00 to 27:00 of small clip, switches back to LargeClip at its 21:00 and keeps it till its end. These timecodes, in seconds, refer to the source file timecode, not of the assembled output.
Make sure that the sync of LargeClip isn't broken, i.e. after switching to SmallClip for 12 seconds, you want to resume LargeClip 12 seconds later from where you left it off.
Step 2 Concat the video streams
This command will skip the audio since we don't to splice the audio streams.
ffmpeg -f concat -i concat.txt -an -c:v libx264 -crf 23 -fflags +genpts spliced-vid.mp4

Step 3 Insert the audio from LargeClip
ffmpeg -i spliced-vid.mp4 -i LargeClip.mp4 -c copy -map 0:v -map 1:a Final.mp4

> **Comments:**
> **username_0**: This looks like a wonderful answer - I will try it out and mark as an answer assuming it works.  Thanks!!  
> **username_0**: that worked thanks...with the small caveat that "duration" didn't seem to work, I replaced that with "outpoint" all the way through and it worked fine.  

---

