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?
-
KSV HDS downloader is similar, I would ask him http://stream-recorder.com/forum/adobe-hds-downloader-t14823.html – Zombo May 06 '14 at 04:48
-
@StevenPenny Do you mean HDS fragments are similar to ones defined in DASH-AVC/264?! – Drake Guan May 06 '14 at 10:48
-
The concept is similar. Beyond that I dont know. – Zombo May 06 '14 at 11:08
-
can someone answer this question? https://stackoverflow.com/questions/55701262/combine-specific-mpeg-dash-segments-ex-int-mp4-seg-1-m4s-seg-3-m4s-into-one – Liquid Apr 19 '19 at 07:47
3 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.

- 1,208
- 9
- 14
-
1The concatenated file won't be the same to the original file though. – Drake Guan Nov 19 '14 at 15:16
-
Could you also explain How to do in windows ? I tried type command but it did not work. type segment-1.m4s segment-2.m4s > final.mp4 this command executed successfully, it created the mp4 file as well but when I run it then it is not running saying file corrupted or not supported error. – Rupesh Kumar Tiwari Mar 02 '16 at 03:18
-
I've also found that the `cat` implementation of Windows does not work as expected for this. I ended up using a Linux machine or the `cat` version provided by Cygwin (https://www.cygwin.com/) – Daniel Mar 03 '16 at 09:42
-
@DrakeGuan _"concatenated file won't be the same to the original file"_ Why? – 3dGrabber Apr 15 '19 at 11:17
-
@3dGrabber, wow this is a 5-year-old question! I'd say Daniel is right for the concatenation: 1) it is playable; 2) it might be similar to the mp4 file (before it is packaged/segmented). – Drake Guan Apr 18 '19 at 03:47
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

- 21
- 3
-
2Did not work for me like that, I had to enable binary mode for copy: `copy /B ...` – user136036 Dec 27 '17 at 17:40
I use a less technical way which rename both audio and video segment to .mp4 and .ogg in Command Prompt and then join'em in a video editing software than export as .mp4 format. Although this way is less technical but it's easy for newbies in Information Technology.

- 1