ffmpeg converting m4s to mp4

22,157

Solution 1

This works

Combine the m4s segments together into one file, making sure the file order is correct. E.g.

cat video-0.m4s >> all.m4s
cat video-1.m4s >> all.m4s
cat video-2.m4s >> all.m4s
cat video-3.m4s >> all.m4s
cat video-4.m4s >> all.m4s
cat video-5.m4s >> all.m4s
cat video-6.m4s >> all.m4s
cat video-7.m4s >> all.m4s
cat video-8.m4s >> all.m4s
cat video-9.m4s >> all.m4s
cat video-10.m4s >> all.m4s

And then do all your conversions at once.

ffmpeg -i all.m4s -c copy video.mp4

This doesn't

I get the same issue (could not find corresponding trex) trying the streaming method.

I had all the files I wanted in a all.txt file, which contained

file 'video-0.m4s'
file 'video-1.m4s'
file 'video-2.m4s'
file 'video-3.m4s'
file 'video-4.m4s'
file 'video-5.m4s'
file 'video-6.m4s'
file 'video-7.m4s'
file 'video-8.m4s'
file 'video-9.m4s'
file 'video-10.m4s'

And I tried ffmpeg -f concat -safe 0 -i all.txt -c copy video.mp4, resulting in the same issue.

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] Auto-inserting h264_mp4toannexb bitstream filter
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] could not find corresponding track id 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] could not find corresponding trex
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55fde2d0c520] error reading header
[concat @ 0x55fde2cff900] Impossible to open 'rifle-1.m4s'
[concat @ 0x55fde2cff900] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, concat, from 'all.txt':
[... omitted ...]
all.txt: Input/output error

Solution 2

First file to be concatenated the initialization segment, followed by other segment file.

windows powershell:

Sort and list the Video files

 Get-ChildItem -name v1*.m4s| Sort-Object { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) } > list.txt

Audio files

 Get-ChildItem -name a1*.m4s| Sort-Object { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) } > list.txt

( refer : How to sort by file name the same way Windows Explorer does?)

 type *init*.mp4 list.txt > Filename.mp4

Linux :

 ls -1v v1*.m4s > list.txt
 cat *init*.mp4 list.txt > Filename.mp4

Solution 3

I agree with the other answers but I found a case that is slightly different. Concatenating the m4s files I got the same could not find corresponding trex error.

I got this m3u8 playlist:

#EXTM3U
#EXT-X-VERSION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="/mypath/something.mp4"
#EXTINF:3.000,
something001.m4s
#EXTINF:3.000,
something002.m4s
#EXTINF:3.000,
something003.m4s
#EXTINF:3.000,
something004.m4s
#EXT-X-ENDLIST

And I had to concatenate all of them starting with the mp4 file. The mp4 file was only 1.1kB and had no video but only the headers, I guess.

After concatenating the files it may be played by some softwares but it's not very compatible so then you have to let ffmpeg fix it for you.

This worked for me:

ffmpeg -i allgluedtogetherinorder.mp4 -vcodec copy -strict -2 video_out.mp4

UPDATE: If your ffmpeg had the m3u support activated at compile time then you can convert the playlist to mp4 and it will resolve everything and give you a perfect video. You may need to edit the paths to the files in the m3u files so it can find them. Then:

ffmpeg -i playlist.m3u -vcodec copy -strict -2 video_out.mp4
Share:
22,157
programming freak
Author by

programming freak

beginner python developer, who loves play with codes and explore new areas to know what is happening

Updated on September 26, 2021

Comments

  • programming freak
    programming freak over 2 years

    I'm working on DASH, trying to optimize QoE for the end user.

    I had a video and encoded it using ffmpeg into different bitrates and everything is fine, and the video is playable using dash.

    What I want is to combine the received segments from the users into one m4s and convert that m4s to mp4.

    I tried a lot of ways in ffmpeg, but it always give me this error:

    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x9a9e500] could not find corresponding track id 1
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x9a9e500] could not find corresponding trex
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x9a9e500] error reading header
    test2.m4s: Invalid data found when processing input
    

    segment_1.m4s is there.

    How can I resolve this issue?

  • programming freak
    programming freak over 4 years
    Yes same issue all files in same place but still gives error
  • mail2subhajit
    mail2subhajit over 4 years
    Please check if all your data is present init.mp4 - sps,pps etc.
  • user8783065
    user8783065 about 4 years
    How about init segment? what needs to do for init segment?
  • Louis Maddox
    Louis Maddox over 3 years
    @user8783065 you concatenate the m4s files after the init segment, I do for x in *.dash *.m4s; do cat $x >> output.mp4; done where the init segment is a .dash file