Using concat to join multiple .mp4 files into a single .mp4 file

Sebastian Dröge sebastian at centricular.com
Mon Apr 6 09:54:18 UTC 2020


On Sun, 2020-04-05 at 08:50 -0700, burt at burtbicksler.com wrote:
> 
> We found slomo's blog post and the first file related example
> basically just does a cat of two files so it doesn't of course play
> properly, it just plays the first clip in the output file and ends.

That depends on the file format, but for MP4 that's certainly true.

> The second example 
> gst-launch-1.0 concat name=c ! queue ! avdec_h264 ! queue !
> videoconvert ! videoscale ! autovideosink   filesrc location=1.mp4 !
> qtdemux ! h264parse ! c.   filesrc location=2.mp4 ! qtdemux !
> h264parse ! c.
> 
> Streams fine to the display but if I replace autovideosink with
> filesink location=foodoo.mp4 I get a very large .mp4 file (larger
> than the combined input files e.g. 64 Mbytes vs 398 Mbytes from this
> pipeline.  While the video "plays" it is blank.

You're decoding both streams and then dump the decoded raw video data
into a file. That's not going to work like this. The concat element is
not doing any magic, it's only concatenating two or more streams into a
continuous timeline.

> I asked on the IRC channel and received this pipeline:
> gst-launch-1.0 concat name=c ! queue ! qtmux ! filesink
> location=output.mp4  filesrc location=1.mp4 ! qtdemux ! h264parse !
> c.   filesrc location=2.mp4 ! qtdemux ! h264parse ! c.
> 
> But that fails with "WARNING: erroneous pipeline: could not link
> h264parse0 to c"

Check the debug logs for the reason why it is failing to link. Due to
how the pipeline string parser works, this is connecting concat with
the audio sink pad of qtmux, and that of course doesn't work for video.

That's why I usually recommend to write proper code for such pipelines,
it also makes everything more maintainable and debuggable.


The following pipeline works here for me:

gst-launch-1.0 concat name=c ! queue ! m.video_0 
    qtmux name=m ! filesink location=test.mp4
    filesrc location=in.mp4 ! qtdemux ! h264parse ! c.
    filesrc location=in.mp4 ! qtdemux ! h264parse ! c.

If you use different input files then you need to make sure that the
h264 streams of both are completely compatible as MP4 does not allow
stream format changes mid-stream. Specifically for H264 that means that
the SPS and PPS need to be the same.

-- 
Sebastian Dröge, Centricular Ltd · https://www.centricular.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 963 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20200406/a744a525/attachment.sig>


More information about the gstreamer-devel mailing list