Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg converting m4s to mp4

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?

like image 531
programming freak Avatar asked Oct 08 '18 14:10

programming freak


3 Answers

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
like image 74
sunapi386 Avatar answered Oct 16 '22 14:10

sunapi386


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
like image 2
mail2subhajit Avatar answered Oct 16 '22 12:10

mail2subhajit


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
like image 2
aalku Avatar answered Oct 16 '22 13:10

aalku