futzu / SCTE-35_SuperKabuki

SCTE-35 Inserter for MPEGTS. SuperKabuki is SCTE-35 Packet Injection for Ad Insertion, powered by threefive.
https://github.com/futzu/SuperKabuki
BSD 2-Clause "Simplified" License
12 stars 2 forks source link

Problem with the -p command #5

Closed Avencheng closed 6 months ago

Avencheng commented 8 months ago

Hi Good to see the new version is released! But I have a little problem the command

aven.cheng@MacBook-Pro detect_stream_insert_35 % superkabuki -i independent_frame.ts -o output.ts -s sidecar.txt -p 0x86
usage: superkabuki [-h] [-i INPUT] [-o OUTPUT] [-s SIDECAR] [-p SCTE35_PID]
                   [-t] [-v]
superkabuki: error: argument -p/--scte35_pid: invalid int value: '0x86'

I also tried using 134 instead of 0x86, still not working

aven.cheng@MacBook-Pro detect_stream_insert_35 % superkabuki -i independent_frame.ts -o output.ts -s sidecar.txt -p 134

Writing output.ts
Traceback (most recent call last):
  File "/Users/aven.cheng/anaconda3/envs/python39/bin/superkabuki", line 7, in <module>
    sk.encode()
  File "/Users/aven.cheng/anaconda3/envs/python39/lib/python3.9/site-packages/superkabuki.py", line 194, in encode
    pid = self._parse_info(pkt)
  File "/Users/aven.cheng/anaconda3/envs/python39/lib/python3.9/site-packages/threefive/stream.py", line 481, in _parse_info
    self._parse_tables(pkt, pid)
  File "/Users/aven.cheng/anaconda3/envs/python39/lib/python3.9/site-packages/threefive/stream.py", line 467, in _parse_tables
    return self._parse_pmt(pay, pid)
  File "/Users/aven.cheng/anaconda3/envs/python39/lib/python3.9/site-packages/superkabuki.py", line 336, in _parse_pmt
    pay = self._chk_partial(pay, pid, self.PMT_TID)
AttributeError: 'SuperKabuki' object has no attribute 'PMT_TID'

Can you tell where am I did wrong? Thanks!

futzu commented 7 months ago

I am so sorry. Those are the two issues I set out to fix specifically, what's even worse is that I was testing it the whole time. I think I just got lost on the version of the file. I'll get you an update here tonight.

futzu commented 7 months ago

Try v0.0.55. I just pushed it.

python3 -m pip install --upgrade superkabuki
futzu commented 7 months ago

Let me know how it goes.

Avencheng commented 7 months ago

Yes, it works! Thanks a lot~

aven.cheng@MacBook-Pro detect_stream_insert_35 % superkabuki -i independent_frame.ts -o output.ts -s sidecar.txt -p 0x86
Writing output.ts
Program Number 1
PCR PID 256
Registration Descriptor added b'\x05\x04CUEI'
Streams Found:
Stream Type: 27  PID: 256  EI Len:  0
Stream Type: 15  PID: 257  EI Len:  6
Stream Added:
Stream Type: 134 PID: 134 EI Len:  3

But I prefer that it will show the inserted cue like before :)

aven.cheng@MacBook-Pro detect_stream_insert_35 % superkabuki -i independent_frame.ts -o output.ts -s sidecar.txt -p 0x86
Writing output.ts
Program Number 1
PCR PID 256
Registration Descriptor added b'\x05\x04CUEI'
Streams Found:
Stream Type: 27  PID: 256  EI Len:  0
Stream Type: 15  PID: 257  EI Len:  6
Stream Added:
Stream Type: 134 PID: 134 EI Len:  0
(27.9667, '/DAvAAAAAAAA///wFAUAAAABf+/+ACZoCH4AUsz1AAAAAAAKAAhDVUVJAAABNVqtIJI=')
(284.0, '/DAqAAAAAAAA///wDwUAAAABf0/+AYYDwAAAAAAACgAIQ1VFSQAAATVNVNSc')
futzu commented 7 months ago

I'll put that back, sorry about that, I have been trying to sort the PMT a bit. ffmpeg tsduck and threefive all recognize the SCTE-35 stream from SuperKabuki , but mediainfo doesn't and I'm not sure why. I add the registration descriptor and all that, but mediainfo doesn't seem to see it at all. I guess it doesn't really matter since everyone else sees it just fine.
My point being, I was printing out a bunch of debug stuff for the PMT so I turned off as much output as I could.
I'll turn it back on and I also have an update to preserve Adaptive Field Control values if present in PMT packets. I'll do a new build tonight probably.

Avencheng commented 7 months ago

Awesome! Thanks for that me know. I really appreciate all your works ~

Avencheng commented 7 months ago

Hi~ I just gave a try of v.0.0.57, but there are two problems.

First, the insert_pts printed in terminal is not the exact same as my sidecar.txt, I don't know if it will have any impact.

aven.cheng@MacBook-Pro detect_stream_insert_35 % superkabuki -i independent_frame.ts -o output.ts -s sidecar.txt -p 0x86

Output File:    output.ts
PMT Section Length: 29
Program Number: 1
PCR PID: 256
Program Info Length: 0

Added Registration Descriptor:
    b'\x05\x04CUEI'

Found Streams:
    Stream Type: 27  PID: 256  EI Len:  0
    Stream Type: 15  PID: 257  EI Len:  6

Added Stream:
    Stream Type: 134 PID: 134 EI Len:  3

Inserted Cue:
    @20.133333, /DAvAAAAAAAA///wFAUAAAABf+/+ABtriH4AUsz1AAAAAAAKAAhDVUVJAAABNWA0vuQ=

Inserted Cue:
    @276.0, /DAqAAAAAAAA///wDwUAAAABf0/+AXsHQAAAAAAACgAIQ1VFSQAAATWCWsHw

here is the content of my sidecar.txt.

aven.cheng@MacBook-Pro detect_stream_insert_35 % cat sidecar.txt
19.9667,/DAvAAAAAAAA///wFAUAAAABf+/+ABtriH4AUsz1AAAAAAAKAAhDVUVJAAABNWA0vuQ=
276.0,/DAqAAAAAAAA///wDwUAAAABf0/+AXsHQAAAAAAACgAIQ1VFSQAAATWCWsHw

Second, I have no problem with using threefive to verify the output.ts ( the PTS also looks fine).

aven.cheng@MacBook-Pro detect_stream_insert_35 % threefive output.ts
{
    "info_section": {
        "table_id": "0xfc",
        "section_syntax_indicator": false,
        "private": false,
        "sap_type": "0x03",
        "sap_details": "No Sap Type",
        "section_length": 47,
        "protocol_version": 0,
        "encrypted_packet": false,
        "encryption_algorithm": 0,
        "pts_adjustment_ticks": 0,
        "pts_adjustment": 0.0,
        "cw_index": "0xff",
        "tier": "0x0fff",
        "splice_command_length": 20,
        "splice_command_type": 5,
        "descriptor_loop_length": 10,
        "crc": "0x6034bee4"
    },
    "command": {
        "command_length": 20,
        "command_type": 5,
        "name": "Splice Insert",
        "time_specified_flag": true,
        "pts_time": 19.966667,
        "pts_time_ticks": 1797000,
        "break_auto_return": false,
        "break_duration": 60.293567,
        "break_duration_ticks": 5426421,
        "splice_event_id": 1,
        "splice_event_cancel_indicator": false,
        "out_of_network_indicator": true,
        "program_splice_flag": true,
        "duration_flag": true,
        "splice_immediate_flag": false,
        "event_id_compliance_flag": true,
        "unique_program_id": 0,
        "avail_num": 0,
        "avail_expected": 0
    },
    "descriptors": [
        {
            "tag": 0,
            "descriptor_length": 8,
            "name": "Avail Descriptor",
            "identifier": "CUEI",
            "provider_avail_id": 309
        }
    ],
    "packet_data": {
        "pid": "0x86",
        "program": 1,
        "pts_ticks": 1806000,
        "pts": 20.066667
    }
}
{
    "info_section": {
        "table_id": "0xfc",
        "section_syntax_indicator": false,
        "private": false,
        "sap_type": "0x03",
        "sap_details": "No Sap Type",
        "section_length": 42,
        "protocol_version": 0,
        "encrypted_packet": false,
        "encryption_algorithm": 0,
        "pts_adjustment_ticks": 0,
        "pts_adjustment": 0.0,
        "cw_index": "0xff",
        "tier": "0x0fff",
        "splice_command_length": 15,
        "splice_command_type": 5,
        "descriptor_loop_length": 10,
        "crc": "0x825ac1f0"
    },
    "command": {
        "command_length": 15,
        "command_type": 5,
        "name": "Splice Insert",
        "time_specified_flag": true,
        "pts_time": 276.0,
        "pts_time_ticks": 24840000,
        "splice_event_id": 1,
        "splice_event_cancel_indicator": false,
        "out_of_network_indicator": false,
        "program_splice_flag": true,
        "duration_flag": false,
        "splice_immediate_flag": false,
        "event_id_compliance_flag": true,
        "unique_program_id": 0,
        "avail_num": 0,
        "avail_expected": 0
    },
    "descriptors": [
        {
            "tag": 0,
            "descriptor_length": 8,
            "name": "Avail Descriptor",
            "identifier": "CUEI",
            "provider_avail_id": 309
        }
    ],
    "packet_data": {
        "pid": "0x86",
        "program": 1,
        "pts_ticks": 24837000,
        "pts": 275.966667
    }
}

But it comes out an error message when I using DVB Inspector to inspect the output.ts. error_massage

It seems that DVB Inspector can not recognize any PMT and SCTE-35 in output.ts, this is never happened before. DVB

futzu commented 7 months ago

Two separate issues.

  1. Difference in Splice Point PTS

    • it is working correctly. All Splice Points are at iframes.

    • SuperKabuki is displaying the actual Splice Point PTS.

    • SuperKabuki always rounds up to the next iframe.

    • When you switch media, like to an ad, you have to start on iframes.

    • If you want to make your video life easier in general, set your GOP size to your frame rate. You get an iframe every second. Yes it does increase your bit rate a little, but in my opinion it's worth it.

  2. PMT errors.

    • I've known there is a problem, but I haven't been able to track it down. I've been move stuff around trying to fix it or break it, so I'd at least get an error. It looks like I have succeeded at producing an error.
    • I'm super busy today, but I'll look at as soon as I can.
    • I believe this is related to my AFC change, which I'll probably just roll back.
futzu commented 7 months ago

Hey man, good call on having the Sidecar Cues put back in the output. That's why the first issue was fast to resolve, the info we needed was easy to reach.

futzu commented 7 months ago

I have to ask, why are you using DVB Inspector? I'm not a fan.

futzu commented 7 months ago

I think I got it. Let me play with it a little.

image

Avencheng commented 7 months ago

I have to ask, why are you using DVB Inspector? I'm not a fan.

I don't have any good reason LOL, just because someone suggest me to use it, and I'm just a beginner of MPEG-TS and SCTE-35, What tool do you recommend?

futzu commented 7 months ago

pip up to 0.0.59

tsanalyze is pretty good.


a@slow:~/SuperKabuki$ tsanalyze sk-wbrb.ts 

===============================================================================
|  TRANSPORT STREAM ANALYSIS REPORT                                           |
|=============================================================================|
|  Transport Stream Id: .......... 1 (0x0001)  |  Services: .............. 1  |
|  Bytes: ......................... 2,776,008  |  PID's: Total: .......... 6  |
|  TS packets: ....................... 14,766  |         Clear: .......... 6  |
|     With invalid sync: .................. 0  |         Scrambled: ...... 0  |
|     With transport error: ............... 0  |         With PCR's: ..... 1  |
|     Suspect and ignored: ................ 0  |         Unreferenced: ... 0  |
|-----------------------------------------------------------------------------|
|  Transport stream bitrate, based on ....... 188 bytes/pkt    204 bytes/pkt  |
|  User-specified: ................................... None             None  |
|  Estimated based on PCR's: ................ 2,200,460 b/s    2,387,733 b/s  |
|  Selected reference bitrate: .............. 2,200,460 b/s    2,387,733 b/s  |
|-----------------------------------------------------------------------------|
|  Broadcast time: ................................... 10 sec (0 min 10 sec)  |
|-----------------------------------------------------------------------------|
|  Srv Id  Service Name                              Access          Bitrate  |
|  0x0001  Service01 .................................... C    2,182,429 b/s  |
|                                                                             |
|  Note 1: C=Clear, S=Scrambled                                               |
|  Note 2: Unless specified otherwise, bitrates are based on 188 bytes/pkt    |
===============================================================================

===============================================================================
|  SERVICES ANALYSIS REPORT                                                   |
|=============================================================================|
|  Global PID's                                                               |
|  TS packets: 121, PID's: 2 (clear: 2, scrambled: 0)                         |
|-----------------------------------------------------------------------------|
|     PID  Usage                                     Access          Bitrate  |
|   Total  Global PID's ................................. C       18,032 b/s  |
|   Subt.  Global PSI/SI PID's (0x00-0x1F) .............. C       18,032 b/s  |
|  0x0000  PAT .......................................... C       15,051 b/s  |
|  0x0011  SDT/BAT ...................................... C        2,980 b/s  |
|=============================================================================|
|  Service: 0x0001 (1), TS: 0x0001 (1), Original Netw: 0xFF01 (65281)         |
|  Service name: Service01, provider: FFmpeg                                  |
|  Service type: 0x01 (Digital television service)                            |
|  TS packets: 14,645, PID's: 4 (clear: 4, scrambled: 0)                      |
|  PMT PID: 0x1000 (4096), PCR PID: 0x0100 (256)                              |
|-----------------------------------------------------------------------------|
|     PID  Usage                                     Access          Bitrate  |
|   Total  Digital television service ................... C    2,182,429 b/s  |
|  0x0086  SCTE 35 Splice Info .......................... C        1,639 b/s  |   <---  Added by SuperKabuki
|  0x0100  AVC video (1920x1080, high profile, level 4.0  C    2,025,806 b/s  |
|  0x0101  MPEG-2 AAC Audio (und) ....................... C      139,932 b/s  |
|  0x1000  PMT .......................................... C       15,051 b/s  |        <--- Rewritten by SuperKabuki
|          (C=Clear, S=Scrambled, +=Shared)                                   |
===============================================================================

===============================================================================
|  PIDS ANALYSIS REPORT                                                       |
|=============================================================================|
|  PID: 0x0000 (0)                                                       PAT  |
|-----------------------------------------------------------------------------|
|  Global PID                Transport:                Discontinuities:       |
|  Bitrate: .... 15,051 b/s  Packets: ........... 101  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: ............ 0  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  Sections:              |
|                                                      Unit start: ..... 101  |
|=============================================================================|
|  PID: 0x0011 (17)                                                  SDT/BAT  |
|-----------------------------------------------------------------------------|
|  Global PID                Transport:                Discontinuities:       |
|  Bitrate: ..... 2,980 b/s  Packets: ............ 20  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: ............ 0  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  Sections:              |
|                                                      Unit start: ...... 20  |
|=============================================================================|
|  PID: 0x0086 (134)                                     SCTE 35 Splice Info  |     < --- Added by SuperKabuki
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  Single Service PID        Transport:                Discontinuities:       |
|  Bitrate: ..... 1,639 b/s  Packets: ............ 11  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: ............ 0  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  Sections:              |
|                                                      Unit start: ...... 11  |
|=============================================================================|
|  PID: 0x0100 (256)                                               AVC video  |
|  PES stream id: 0xE0 (Video 0)                                              |
|  1920x1080, high profile, level 4.0, 4:2:0                                  |
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  Single Service PID        Transport:                Discontinuities:       |
|  Bitrate: . 2,025,806 b/s  Packets: ........ 13,594  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: .......... 448  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  PES:                   |
|                            TSrate: .. 2,200,460 b/s  Packets: ........ 301  |
|                                                      Inv.Start: ........ 0  |
|  Clock values range:                                                        |
|  PCR: ............... 152  PTS: ............... 301  DTS: ............ 245  |
|  from ........ 94,537,800  from ........... 384,132  from ........ 378,126  |
|  to ......... 364,808,100  to ........... 1,285,033  to ........ 1,279,027  |
|  Leaps: ............... 0  Leaps: ............... 0  Leaps: ............ 0  |
|=============================================================================|
|  PID: 0x0101 (257)                                  MPEG-2 AAC Audio (und)  |
|  PES stream id: 0xC0 (Audio 0)                                              |
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  Single Service PID        Transport:                Discontinuities:       |
|  Bitrate: ... 139,932 b/s  Packets: ........... 939  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: .......... 121  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  PES:                   |
|                                                      Packets: ......... 61  |
|                                                      Inv.Start: ........ 0  |
|  Clock values range:                                                        |
|                            PTS: ................ 61                         |
|                            from ........... 380,166                         |
|                            to ........... 1,276,806                         |
|                            Leaps: ............... 0                         |
|=============================================================================|
|  PID: 0x1000 (4096)                                                    PMT  |    <--- Rewritten by SuperKabuki
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  Single Service PID        Transport:                Discontinuities:       |
|  Bitrate: .... 15,051 b/s  Packets: ........... 101  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: ............ 0  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  Sections:              |
|                                                      Unit start: ..... 101  |
===============================================================================

===============================================================================
|  TABLES & SECTIONS ANALYSIS REPORT                                          |
|=============================================================================|
|  PID: 0x0000 (0)                                                       PAT  |
|-----------------------------------------------------------------------------|
|  0x00 (0, PAT), TID ext: 0x0001 (1)                                         |
|      Repetition: ...... 98  ms  Section cnt: ...... 101                     |
|      Min repet.: ...... 21  ms  Table cnt: ........ 101                     |
|      Max repet.: ..... 407  ms  Version: ............ 0                     |
|=============================================================================|
|  PID: 0x0011 (17)                                                  SDT/BAT  |
|-----------------------------------------------------------------------------|
|  0x42 (66, SDT Actual), TID ext: 0x0001 (1)                                 |
|      Repetition: ..... 485  ms  Section cnt: ....... 20                     |
|      Min repet.: ..... 229  ms  Table cnt: ......... 20                     |
|      Max repet.: ..... 690  ms  Version: ............ 0                     |
|=============================================================================|
|  PID: 0x0086 (134)                                     SCTE 35 Splice Info  |           <---  Added by  SuperKabuki
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  0xFC (252, SCTE 35 Splice Information)                                     |
|      Repetition: ..... 977  ms  Section cnt: ....... 11                     |
|      Min repet.: ..... 802  ms                                              |
|      Max repet.: .... 1027  ms                                              |
|=============================================================================|
|  PID: 0x1000 (4096)                                                    PMT  |     <--- Rewritten by SuperKabuki
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  0x02 (2, PMT), TID ext: 0x0001 (1)                                         |
|      Repetition: ...... 98  ms  Section cnt: ...... 101                     |
|      Min repet.: ...... 21  ms  Table cnt: ........ 101                     |
|      Max repet.: ..... 407  ms  Version: ............ 0                     |
===============================================================================
futzu commented 7 months ago

My beef with DVB Analyzer is mostly due to the "open source" version being a "lite" without any features.
That's not how open source works. That kind of thing makes open source software look badly, like it's a cheap version. Either make it open source or not, but don't use open source as a gimmick, that really pisses me off.

It's also written in Java.

"Java, C#, XML! that's the battle cry of the desperate and stupid" ~Bill Pitts

Did you try v0.0.59? it's pretty good man.

Oh, The problem you showed me from DVB inspector, that was just a typo, a 1 instead of a 0.

Avencheng commented 7 months ago

Hey ~ I just tried v0.0.59, it is awesome! And thanks for introducing tsanalyze to me, I'm gonna start using it.