fq
fq copied to clipboard
mpeg_ts: Rewrite and cleanup
@bbgdzxng1 have a look
With this is can do:
➜ fq git:(mpeg_ts_wip) ✗ go run . -C -d bytes 'tobytes[0:188*100000] | mpeg_ts | .pes[12].payload | mpeg_pes_packet | .gap0 | avc_au | d({line_bytes:10})' ~/Downloads/dtvcc/<redacted>.ts
│00 01 02 03 04 05 06 07 08 09│0123456789│.[0:8]: (avc_au)
0x000a│ 00│ .│ [0]: raw bits
0x0014│00 00 01 │... │
│00 01 02 03 04 05 06 07 08 09│0123456789│ [1]{}: nalu (avc_nalu)
0x0014│ 09 │ . │ forbidden_zero_bit: false
0x0014│ 09 │ . │ nal_ref_idc: 0
0x0014│ 09 │ . │ nal_unit_type: "aud" (9) (Access unit delimiter)
0x0014│ f0 │ . │ data: raw bits
0x0014│ 00 00 00 01 │ .... │ [2]: raw bits
│00 01 02 03 04 05 06 07 08 09│0123456789│ [3]{}: nalu (avc_nalu)
│00 01 02 03 04 05 06 07 08 09│0123456789│ sei{}: (avc_sei)
0x00│04 │. │ payload_type: "user_data_registered_itu_t_t35" (4)
0x00│ 47 │ G │ payload_size: 71
0x00│ b5 00 31 47 41 39 34 03│ ..1GA94.│ data: raw bits
0x00│54 00 fc 80 80 fd 80 80 fa 00│T.........│
0x01│00 fa 00 00 fa 00 00 fa 00 00│..........│
* │until 0x48.7 (71) │ │
0x04│ 80│ │ .│ │ rbsp_trailing_bits: raw bits
0x0014│ 06│ .│ forbidden_zero_bit: false
0x0014│ 06│ .│ nal_ref_idc: 0
0x0014│ 06│ .│ nal_unit_type: "sei" (6) (Supplemental enhancement information)
0x001e│04 47 b5 00 31 47 41 39 34 03│.G..1GA94.│ data: raw bits
0x0028│54 00 fc 80 80 fd 80 80 fa 00│T.........│
* │until 0x67.7 (74) │ │
0x0064│ 00 00 01 │ ... │ [4]: raw bits
│00 01 02 03 04 05 06 07 08 09│0123456789│ [5]{}: nalu (avc_nalu)
│00 01 02 03 04 05 06 07 08 09│0123456789│ sei{}: (avc_sei)
0x00│01 │. │ payload_type: "pic_timing" (1)
0x00│ 01 │ . │ payload_size: 1
0x00│ 32 │ 2 │ data: raw bits
0x00│ 80│ │ .│ │ rbsp_trailing_bits: raw bits
0x0064│ 06 │ . │ forbidden_zero_bit: false
0x0064│ 06 │ . │ nal_ref_idc: 0
0x0064│ 06 │ . │ nal_unit_type: "sei" (6) (Supplemental enhancement information)
0x0064│ 01 01│ ..│ data: raw bits
0x006e│32 80 │2. │
0x006e│ 00 00 01 │ ... │ [6]: raw bits
│00 01 02 03 04 05 06 07 08 09│0123456789│ [7]{}: nalu (avc_nalu)
0x006e│ 41 │ A │ forbidden_zero_bit: false
0x006e│ 41 │ A │ nal_ref_idc: 2
0x006e│ 41 │ A │ nal_unit_type: "slice" (1) (Coded slice of a non-IDR picture)
│ │ │ slice_header{}:
0x006e│ 9a │ . │ first_mb_in_slice: 0
0x006e│ 9a │ . │ slice_type: "p" (5)
0x006e│ 9a │ . │ pic_parameter_set_id: 0
0x006e│ 9a c4 93 4b│ ...K│ data: raw bits
0x0078│64 42 bf fe bd 00 00 03 00 00│dB........│
0x0082│03 00 00 3e 36 24 00 27 99 f7│...>6$.'..│
* │until 0x5d4.7 (end) (1377) │ │
So with some manual trickery (the mpeg_pes_packet decoder is broken) we can get to the nalu:s
Some questions:
- Currently the ts decoder codes into 3 arrays
packetsfor raw ts packets,tablesfor reassembled psi and later dvb tables,pesfor reassembled elementary stream packets. Does the structure and names make sense?pesandtablesalso has some metadata per reassembled packets, like indexpacketsthey come from, pid, program and stream type - ts stream as suppose to be very error resilient, not sure how to map that in fq. use options/heurisics to know when to give up?
- Probably need a
decode_samplesoption, a 600mb ts file now uses 16gb ram, can probably improve that somewhat but it will use lots of memory. Also some general fq improvement might improve this some. - See code for various TODOs
@bbgdzxng1 hey have not forgotten about this and t35 subtitles, just been busy and got a bit stuck with the ts decoder, so many decisions how to handle errors and broken stuff 😬