wangf1978 / DumpTS

Extract elementary stream from all kinds of media files, show inside media meta information and reconstruct Transport-Stream, ISOBMFF, Matroska and MMT media files
MIT License
59 stars 15 forks source link

MMTP Payload reading of MFU doesn't follow spec #3

Closed trollcop closed 1 month ago

trollcop commented 5 years ago

Here:

https://github.com/wangf1978/DumpTS/blob/master/src/MMT.h#L2264

The code is called with TLV packet of length say 0x200, but in my sample MMT file ends up reading > 0xb300 bytes because it doesn't keep track of tlv packet size boundary.

You need to assemble the packets , instead of just reading payload_bytes.

Here's a sample mmt file which causes this issue - https://mega.nz/#!sQUzyK7Q!w88OVKujO5s6j_0g6M4exIav2uUg2fJ5cBSR9LyX8OA

command line which causes bug:

dumpts sample.mmts --srcfmt=mmt --output=test.hevc --outputfmt=es --pid=0xa001

This also requires my earlier PR about >12bit pid numbers.

wangf1978 commented 5 years ago

I will have a look later, thanks for reporting this issue.

wangf1978 commented 5 years ago

You can use the command line:

dumpts sample.mmts --showinfo

to show the layout of mmts, and you can see packet_id 0xa001 may lies at 2 CID(1 and 2).

So you need specify the CID with below command line

dumpts sample.mmts --srcfmt=mmt --output=test.hevc --outputfmt=es --pid=0xa001 --CID==1
or
dumpts sample.mmts --srcfmt=mmt --output=test.hevc --outputfmt=es --pid=0xa001 --CID==2
trollcop commented 5 years ago

Yes, sure, but that still doesn't change the fact that code doesn't handle fragmented MPU/MFU packets and tries to read entire PayloadLength which may span several TLV packets:

DumpTS.exe .\sample.mmts --srcfmt=mmt --output=test.hevc --outputfmt=es --pid=0xa001 --cid=1

[MMT/TLV] TLV header should start with 0x7F at file position: 223119.
Total cost: 31.321500 ms
Total input TLV packets: 127.
Total MMT/TLV packets with the packet_id(0XA001): 120
Total MFUs in MMT/TLV packets with the packet_id(0XA001): 119
MMT-TLVassociation commented 4 years ago

A quick fix to line2245 of MMT.h will resolve the error. back.data_unit_length = left_payload_data_len; //bs.GetWord();

Error: [MMT/TLV] TLV header should start with 0x7F at file position: 223119.

MMT-TLVassociation commented 4 years ago

I'm trying to separate MPU/MFU packets by CID, but CID option is not implemented and cannot be processed in the current DumpTS version. The file is here https://mega.nz/#!gp4zFCyK!nrta0WqY0xyoEXBVmft4OCbrHGoQFNgsLpF9QmBJUVM In this sample MMT/TLV stream, there are two TV channels in one TLV stream. One is CID=1, the another CID=2. I need output hevc file separately.

MMT-TLVassociation commented 4 years ago

Sorry. CID option is working, but CID=1, not CID==1. I can output hevc file for CID=1 or CID=2 now.

MMT-TLVassociation commented 4 years ago

Just added "CID", at std::string str_arg_prefixes[] in DumpTS.cpp

wangf1978 commented 4 years ago

Thanks, can you push your changes? I didn't test these case in my previous implementation, in current code, I found it already supported "CID"

MMT-TLVassociation commented 4 years ago

Thank you. I've sent a pull request.

By the way, the DumpTS's output .hevc needs a conversion to NAL unit headers. Some users in Japan reporting these codes for DumpTS's output. http://codepad.org/OWrYQuW6 (Code name dt2nal) The code adds NAL unit header for the output of DumpTS hevc file (pid=0xa001 for example)

For audio output (pid=0xa041 for example), the output file by DumpTS needs header conversion by the code below, http://codepad.org/AIjzS9dV (Code name dt2aac) The audio is LOAS file format.

After converting headers, users are merging Video output& Audio output files using MKVToolNix. MKVToolNix output video&audio Synthesized MKV file.

I think you can watch a video in this file for CID=2, https://mega.nz/#!gp4zFCyK!nrta0WqY0xyoEXBVmft4OCbrHGoQFNgsLpF9QmBJUVM

CID=1 is the another channel in this TLV stream, it's encrypted channel. (You can't watch)