Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine MPEG-DASH segments (ex, init.mp4 + segments.m4s) back to a full source.mp4?

GPAC, http://gpac.wp.mines-telecom.fr/, can be used to do video segmentation along with MPEG-DASH spec. One type of results is a combination of init files (ex, init.mp4) and several roughly fixed-duration segments (ex, segment-%d.m4s). What if I just got those results and I like to reverse/combine them back to one full source.mp4 file? Can I use GPAC or ffmpeg for this?

like image 739
Drake Guan Avatar asked May 06 '14 04:05

Drake Guan


People also ask

How do I combine M4S files?

In Linux and macOS terminals, you can use the cat command to combine multiple M4S files into a single file. In Windows command prompt, you can use the type or copy commands. When you combine your M4S files, be sure to combine them in the correct order.

What is M4S format?

An M4S file is a small segment of a video that is streamed over the internet using the MPEG-DASH streaming technique.

What is DASH initialization segment?

What is the structure of a Dash video initialization segment? The initialization segment contains information required to initialize the video decoder. The initialization segment is optional (refer to ISO/IEC 23009-1). For ISO BMFF (commonly known as mp4) this includes the moov box (specified in ISO/IEC 14496-12).


2 Answers

You can just use the cat command or similar tools to do this job:

cat init.mp4 > source.mp4
cat segment-1.m4s >> source.mp4
cat segment-2.m4s >> source.mp4
...

To do this automatically for all segments in the current folder, the following command can be used:

cat init.mp4 $(ls -vx segment-*.m4s) > source.mp4

The -v parameter for ls sorts the output naturally (i.e. 1, 2, ..., 10, ..., 100), otherwise it sorts lexically (i.e. 1, 10, 100, 2, ...). The -x parameter puts the output on a line instead of columns.

like image 161
Daniel Avatar answered Oct 23 '22 02:10

Daniel


Under Windows cmd shell you can use the copy command for file concatenation in the following way:

copy init.mp4 +segment*.m4s source.mp4

"help copy" does provide you all options

like image 26
Ralf Bialozyt Avatar answered Oct 23 '22 00:10

Ralf Bialozyt