[FFmpeg-user] Assembling files from several input files
Lou
lou at lrcd.com
Tue Apr 8 20:48:21 CEST 2014
On Tue, 8 Apr 2014 12:07:46 +0200
Werner Robitza <werner.robitza at gmail.com> wrote:
> Let's assume I have four files:
>
> video1.mp4
> video2.mp4
> audio1.m4a
> audio2.m4a
>
> What would a simple command be that could concatenate/mux the files in such
> a way that it contains:
>
> video1 from 0 to 20 seconds, video 2 from 20 to 30 seconds
> audio1 from 0 to 10 seconds, audio2 from 10 to 30
>
> Basically, I need to freely mux/concatenate parts of different sources. I
> know I could cut the video parts individually before, then concat them into
> a final video, then do the same with audio, and finally encode and mux
> everything, but would it be possible to do that in one filter expression?
Hi Werner,
Maybe not simple, but this can be done with the (a)trim, (a)setpts, and
concat filters:
ffmpeg -i v1.mp4 -i v2.mp4 -i a1.m4a -i a2.m4a -filter_complex \
"[0:v]trim=0:20,setpts=PTS-STARTPTS[v0]; \
[1:v]trim=20:30,setpts=PTS-STARTPTS[v1]; \
[2:a]atrim=0:10,asetpts=PTS-STARTPTS[a0]; \
[3:a]atrim=10:30,asetpts=PTS-STARTPTS[a1]; \
[v0][v1]concat=n=2:v=1:a=0[vcat]; \
[a0][a1]concat=n=2:v=0:a=1[acat]" \
-map "[vcat]" -map "[acat]" output.mp4
You may need to add other filters like aformat if the inputs are
too dissimilar.
More information about the ffmpeg-user
mailing list