Log in

View Full Version : How to concat m2ts according to mpls?


GabriellaChaos
19th January 2025, 03:32
I want to know how to correctly concatenate m2ts segments according to Intime/Outime specified in mpls playlist. I feel the Intime/Outtime fields in the mpls playitems might have unit in packets number, then how to seek to these package number in ffmpeg?

For example, I parsed the playlist in a mpls file into json below:


{
"Length": 306,
"NumberOfPlayItems": 2,
"NumberOfSubPaths": 1,
"PlayItems": [
{
"Length": 128,
"ClipInformationFileName": "00002",
"ClipCodecIdentifier": "M2TS",
"MiscFlags1": 1,
"IsMultiAngle": false,
"RefToSTCID": 0,
"INTime": 188955000,
"OUTTime": 308939865,
"UOMaskTable": 0,
"MiscFlags2": 0,
"StillMode": 0,
"STNTable": {
"Length": 94,
"NumberOfPrimaryVideoStreamEntries": 1,
"NumberOfPrimaryAudioStreamEntries": 2,
"NumberOfPrimaryPGStreamEntries": 1,
"NumberOfPrimaryIGStreamEntries": 1,
"NumberOfSecondaryAudioStreamEntries": 0,
"NumberOfSecondaryVideoStreamEntries": 0,
"NumberOfSecondaryPGStreamEntries": 0,
"PrimaryVideoStreamEntries": [
{
"StreamEntry": {
"Length": 9,
"StreamType": 1,
"RefToStreamPID": "0x1011"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 27,
"VideoFormat+FrameRate": 97
}
}
],
"PrimaryAudioStreamEntries": [
{
"StreamEntry": {
"Length": 9,
"StreamType": 1,
"RefToStreamPID": "0x1100"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 131,
"AudioFormat+SampleRate": 97,
"LanguageCode": "jpn"
}
},
{
"StreamEntry": {
"Length": 9,
"StreamType": 1,
"RefToStreamPID": "0x1101"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 128,
"AudioFormat+SampleRate": 49,
"LanguageCode": "jpn"
}
}
],
"PrimaryPGStreamEntries": [
{
"StreamEntry": {
"Length": 9,
"StreamType": 1,
"RefToStreamPID": "0x1200"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 144,
"LanguageCode": "jpn"
}
}
],
"SecondaryPGStreamEntries": [],
"PrimaryIGStreamEntries": [
{
"StreamEntry": {
"Length": 9,
"StreamType": 2,
"RefToSubPathID": 0,
"RefToSubClipID": 0,
"RefToStreamPID": "0x1400"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 145,
"LanguageCode": "jpn"
}
}
],
"SecondaryAudioStreamEntries": [],
"SecondaryVideoStreamEntries": []
}
},
{
"Length": 128,
"ClipInformationFileName": "00003",
"ClipCodecIdentifier": "M2TS",
"MiscFlags1": 1,
"IsMultiAngle": false,
"RefToSTCID": 0,
"INTime": 189000000,
"OUTTime": 189585585,
"UOMaskTable": 582090251837636608,
"MiscFlags2": 0,
"StillMode": 0,
"STNTable": {
"Length": 94,
"NumberOfPrimaryVideoStreamEntries": 1,
"NumberOfPrimaryAudioStreamEntries": 2,
"NumberOfPrimaryPGStreamEntries": 1,
"NumberOfPrimaryIGStreamEntries": 1,
"NumberOfSecondaryAudioStreamEntries": 0,
"NumberOfSecondaryVideoStreamEntries": 0,
"NumberOfSecondaryPGStreamEntries": 0,
"PrimaryVideoStreamEntries": [
{
"StreamEntry": {
"Length": 9,
"StreamType": 1,
"RefToStreamPID": "0x1011"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 27,
"VideoFormat+FrameRate": 97
}
}
],
"PrimaryAudioStreamEntries": [
{
"StreamEntry": {
"Length": 9,
"StreamType": 1,
"RefToStreamPID": "0x1100"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 131,
"AudioFormat+SampleRate": 97,
"LanguageCode": "jpn"
}
},
{
"StreamEntry": {
"Length": 9,
"StreamType": 1,
"RefToStreamPID": "0x1101"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 128,
"AudioFormat+SampleRate": 49,
"LanguageCode": "jpn"
}
}
],
"PrimaryPGStreamEntries": [
{
"StreamEntry": {
"Length": 9,
"StreamType": 1,
"RefToStreamPID": "0x1200"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 144,
"LanguageCode": "jpn"
}
}
],
"SecondaryPGStreamEntries": [],
"PrimaryIGStreamEntries": [
{
"StreamEntry": {
"Length": 9,
"StreamType": 2,
"RefToSubPathID": 0,
"RefToSubClipID": 0,
"RefToStreamPID": "0x1400"
},
"StreamAttributes": {
"Length": 5,
"StreamCodingType": 145,
"LanguageCode": "jpn"
}
}
],
"SecondaryAudioStreamEntries": [],
"SecondaryVideoStreamEntries": []
}
}
],
"SubPaths": [
{
"Length": 36,
"SubPathType": 3,
"MiscFlags1": 0,
"NumberOfSubPlayItems": 0,
"SubPlayItems": []
}
]


It references 2 m2ts files:
- 00002.m2ts from 188955000 to 308939865
- 00003.m2ts from 189000000 to 189585585

I would like to know what these integers mean, and how to concatenate these two segments into one m2ts (perhaps using ffmpeg or other tools). Appreciate your help!

Edit: I have to work with Linux(debian) cli tools, not tools with gui.

GabriellaChaos
21st January 2025, 10:42
I still have no idea about the unit. It seems like (308939865 - 188955000) / 45000 matches the duration of the 00002.m2ts in seconds. Maybe there is some kind of timebase information in the m2ts file?

Also, I mentioned that the IGStream with PID #0x1400 referenced in the mpls file does not exists in the list provided by ffprobe. What is IGStream? Why is it not in the m2ts file?

Z2697
21st January 2025, 21:42
That unit is 45000

m2ts timebase is 1/90000, period.

https://github.com/SAPikachu/igstools