Giter Club home page Giter Club logo

scte-35_superkabuki's Introduction

SuperKabuki

SCTE-35 Inserter

SCTE-35 Ad Insertion

SCTE-35 Packet Injection for MPEGTS.

Latest Version is v.0.0.63 Released Wed Jun 5 08:50:29 PM EDT 2024

Install

python3 -mpip install superkabuki

Heads up! upgrade threefive to 2.4.55

python3 -mpip install --upgrade threefive
  • and / or
pypy3 -mpip install --upgrade threefive

Cli Options

a@debian:~/SuperKabuki$ superkabuki -h

usage: superkabuki [-h] [-i INPUT] [-o OUTPUT] [-s SIDECAR] [-p SCTE35_PID] [-t] [-v]

options:
  -h, --help            show this help message and exit
  
  -i INPUT, --input INPUT
                        Input source, like "/home/a/vid.ts" or "udp://@235.35.3.5:3535" or
                        "https://futzu.com/xaa.ts" (default sys.stdin.buffer)
                        
  -o OUTPUT, --output OUTPUT
                        Output file (default sys.stdout.buffer)
                        
  -s SIDECAR, --sidecar SIDECAR
                        Sidecar file for SCTE35 (default sidecar.txt)
                        
  -p SCTE35_PID, --scte35_pid SCTE35_PID
                        Pid for SCTE-35 packets, can be hex or integer. (default 0x86)
                        
  -t, --time_signals    Flag to insert Time Signal cues at iframes.
  
  -v, --version         Show version
  • Use Superkabuki to insert time signal cues at every iframe.
superkabuki -i your_video.ts -o output.ts -t -p 0x197
  • verify with threefive ( installs with superkabuki )
threefive output.ts

Sidecar Files

  • Load scte35 cues from a Sidecar file.
a@debian:~/x9k3$ cat sidecar.txt

38103.868589, /DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ== 
38199.918911, /DAsAAAAAAAAAP/wDwUAAABef0/+zPACTQAAAAAADAEKQ1VFSbGfMTIxIxGolm0= 
  • line format for sidecar file is insert_pts, cue ,

    • like 38103.868589, /DAxAAAAAAAAAP/wFAUAAABdf+/+zHRtOn4Ae6DOAAAAAAAMAQpDVUVJsZ8xMjEqLYemJQ==
  • pts is the insert time for the cue, cue can be base64,hex, int, or bytes.

  • The insert_pts has to be valid for the video, meaning if your insert_pts is 38103.868589, the video PTS has to be less than 38103.868589 for the cue to be inserted.

  • SuperKabuki with a sidecar file sidecar.txt, and SCTE-35 pid 0x86

superkabuki -i input_file -s sidecar.txt -p 0x86

Encoding SCTE-35 Cues

scte-35_superkabuki's People

Contributors

futzu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scte-35_superkabuki's Issues

Unable to insert SCTE-35 in TV stream

I think it's better to create a new topic to discuss this issue that i've mentioned before.

I have a TV stream as my input, but SCTE35 was never inserted. Below is the outputs of my superkabuki command :

Reading rcvbuf_size of 212992
Setting rcvbuf_size to 3489660928



Reading rcvbuf_size of 212992
Setting rcvbuf_size to 3489660928



Output File:	output.ts
PMT Section Length: 55
Program Number: 671
PCR PID: 6119
Program Info Length: 12

Added Registration Descriptor:
	b'\x05\x04CUEI'

Found Streams:
	Stream Type: 27  PID: 6116  EI Len:  20
	Stream Type: 3  PID: 6117  EI Len:  0

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

I can see the PID PCR are much bigger from the output of threefive show of the TV stream, :

(ffmpeg7_kabuki59) imagecuetone@imagecuetone-Virtual-Machine:~/detect_stream_insert_35$ threefive show udp://@229.0.0.7:9000

Reading rcvbuf_size of 212992
Setting rcvbuf_size to 3489660928



Program: 671
    Service:	CTINews-HD              
    Provider:	DiviCom Customer
    Pid:		6115
    Pcr Pid:	6119
    Streams:
					Pid: 6116[0x17e4]	Type: 0x1b AVC Video
					Pid: 6117[0x17e5]	Type: 0x3 MP2 Audio

Even if i used my ffmpeg delay command to delay the TV stream and use its output as the input for superkabuki command, SCTE35 was still never inserted.

The ffmpeg delay command:
ffmpeg -re -i 'udp://@229.0.0.7:9000?overrun_nonfatal=1&fifo_size=50000000' -filter_complex "[0:v]tpad=start_duration=2[v];[0:a]adelay=2s:all=true[a]" -map "[v]" -map "[a]" -vcodec libx264 -f mpegts 'udp://229.0.0.7:9001?pkt_size=1316'

The output of threefive show of the delay stream:

(ffmpeg7_kabuki59) imagecuetone@imagecuetone-Virtual-Machine:~/detect_stream_insert_35$ threefive show udp://@229.0.0.7:9001

Reading rcvbuf_size of 212992
Setting rcvbuf_size to 3489660928

Program: 1
    Service:	Service01
    Provider:	FFmpeg
    Pid:		4096
    Pcr Pid:	256
    Streams:
					Pid: 256[0x100]	Type: 0x1b AVC Video
					Pid: 257[0x101]	Type: 0x3 MP2 Audio

How can I deal with this issue? Thanks.

SuperKabuki loses TS codec and stream information

When running in a simple form:

$ python -m superkabuki -i /tmp/0_2319569.ts -o output.ts -t
Writing output.ts

The new output.ts information does not match the original.

OUTPUT

$ mediainfo output.ts
General
ID                                       : 1 (0x1) 
Complete name                            : output.ts
Format                                   : MPEG-TS
File size                                : 98.8 KiB

$ ffprobe output.ts
ffprobe version 4.3.5-0+deb11u1 Copyright (c) 2007-2022 the FFmpeg developers
...
[mpegts @ 0x55c230d77700] Could not find codec parameters for stream 2 (Unknown: none ([134][0][0][0] / 0x0086)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'output.ts':
Duration: 00:00:05.02, start: 1.445333, bitrate: 161 kb/s
  Program 1
    Stream #0:2[0x86]: Unknown: none ([134][0][0][0] / 0x0086)
    Stream #0:0[0x100]: Video: h264 (High), yuv420p(progressive), 256x144 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 60 tbc
  No Program
    Stream #0:1[0x101]: Audio: aac (LC), 48000 Hz, stereo, fltp, 37 kb/s
Unsupported codec with id 0 for input stream 2

ORIGINAL

$ mediainfo orig.ts
General
ID                                       : 1 (0x1)
Complete name                            : /tmp/0_2319569.ts
Format                                   : MPEG-TS
File size                                : 98.0 KiB
Duration                                 : 4 s 900 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 158 kb/s

Video
ID                                       : 256 (0x100)
Menu ID                                  : 1 (0x1)
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : 27
Duration                                 : 5 s 0 ms
Bit rate mode                            : Variable
Maximum bit rate                         : 96.0 kb/s
Width                                    : 256 pixels
Height                                   : 144 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Writing library                          : x264 core 148
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=4 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / vbv_maxrate=96 / vbv_bufsize=60 / crf_max=0.0 / nal_hrd=vbr / filler=0 / ip_ratio=1.40 / aq=1:1.00

Audio
ID                                       : 257 (0x101)
Menu ID                                  : 1 (0x1)
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Format version                           : Version 4
Muxing mode                              : ADTS
Codec ID                                 : 15-2
Duration                                 : 4 s 970 ms
Bit rate mode                            : Variable
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Delay relative to video                  : -22 ms

$ ffprobe orig.ts
ffprobe version 4.3.5-0+deb11u1 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
...
Input #0, mpegts, from '/tmp/0_2319569.ts':
  Duration: 00:00:05.02, start: 1.445333, bitrate: 159 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 256x144 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 60 tbc
    Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 37 kb/s

Problem with using Superkabuki to insert time signal cues at every iframe.

Hi Adrian,
This might be a stupid question,
I'm trying to inject SCTE-35 in ts, but I have an issue with the command :
superkabuki -i independent_frame_ts/0.ts -o output.ts -t
but it returns the output: scte35 pid must be set
I only have the PTS for cue-out and cue-in, not PID. What steps am i missing?

How can I output it as a stream ?

I have a stream as input, and also want to output it as a stream over UDP, but I got the error FileNotFoundError: [Errno 2] No such file or directory: 'udp://127.0.0.1:10002
How can I fix this? Thanks a lot!

stream = 'udp://127.0.0.1:10000'
sidecar_file = 'sidecar.txt'
sream_w_SCTE35 = 'udp://127.0.0.1:10002'

insert_35_cmd = [
'superkabuki',
'-i', stream,
'-o', sream_w_SCTE35,
'-s', sidecar_file,
'-p', '0x86'
]
subprocess.Popen(insert_35_cmd)

Problem with the -p command

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!

IndexError: index out of range

Hi! It's me again :)

I kept getting the same error after running my program for a while, and it never happened before. I used the following packages for superkabuki 0.0.59 :

Name                    Version                  Build  Channel
superkabuki              0.0.59                   pypi_0    pypi
threefive                2.4.35                   pypi_0    pypi
new-reader               0.1.9                    pypi_0    pypi
iframes                  0.0.7                    pypi_0    pypi

The error i got when i using 0.0.59.

PMT Section Length: 555
frame=67773 fps= 30 q=29.0 size=  821881kB time=00:37:39.15 bitrate=2980.2kbits/
frame=67788 fps= 30 q=29.0 size=  822227kB time=00:37:39.68 bitrate=2980.8kbits/
PMT Section Length: 555
frame=67804 fps= 30 q=29.0 size=  822537kB time=00:37:40.18 bitrate=2981.3kbits/
PMT Section Length: 555
Program Number: 54196
PCR PID: 7644
Program Info Length: 2114

Added Registration Descriptor:
	b'\x05\x04CUEI'
Traceback (most recent call last):
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki59/bin/superkabuki", line 7, in <module>
    sk.encode()
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki59/lib/python3.11/site-packages/superkabuki.py", line 214, in encode
    pid = self._parse_info(pkt)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki59/lib/python3.11/site-packages/threefive/stream.py", line 481, in _parse_info
    self._parse_tables(pkt, pid)
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki59/lib/python3.11/site-packages/threefive/stream.py", line 467, in _parse_tables
    return self._parse_pmt(pay, pid)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki59/lib/python3.11/site-packages/superkabuki.py", line 379, in _parse_pmt
    d_len = pay[idx]
            ~~~^^^^^
IndexError: index out of range

I also tried the older version (superkabuki 0.0.49), which I think was perfect as well, but now I got similar error as above, i used the following for superkabuki 0.0.49 :

Name                    Version                  Build  Channel
superkabuki              0.0.49                   pypi_0    pypi
threefive                2.4.1                    pypi_0    pypi
new-reader               0.1.7                    pypi_0    pypi
iframes                  0.0.7                    pypi_0    pypi

Interestingly, It suddenly insert all the cues which has already been inserted at the corresponding time. The error i got when i using 0.0.49.

frame=62097 fps= 30 q=29.0 size=  758738kB time=00:34:32.14 bitrate=2999.6kbits/
frame=62113 fps= 30 q=29.0 size=  758917kB time=00:34:32.67 bitrate=2999.5kbits/
frame=62127 fps= 30 q=29.0 size=  759065kB time=00:34:33.15 bitrate=2999.4kbits/
(1021.5, '/DAlAAAAAAAAAP/wFAUAAAAGf+/+BXrRGP4AUxWIAAABAAAAZiKZuA==')
(1081.47, '/DAgAAAAAAAAAP/wDwUAAAAGf0/+Bc0rIAAAAQAAADyDFPY=')
(1201.5, '/DAlAAAAAAAAAP/wFAUAAAAHf+/+BnICWP4AUxWIAAABAAAAOH3Kzg==')
(1261.47, '/DAgAAAAAAAAAP/wDwUAAAAHf0/+BsRcYAAAAQAAANwiLfo=')
(1381.5, '/DAlAAAAAAAAAP/wFAUAAAAIf+/+B2kzmP4AUxWIAAABAAAAKcImoA==')
(1441.47, '/DAgAAAAAAAAAP/wDwUAAAAIf0/+B7uNoAAAAQAAACFRBI0=')
(1561.5, '/DAlAAAAAAAAAP/wFAUAAAAJf+/+CGBk2P4AUxWIAAABAAAAtaZJUg==')
(1621.47, '/DAgAAAAAAAAAP/wDwUAAAAJf0/+CLK+4AAAAQAAAAkXOEo=')
(1741.5, '/DAlAAAAAAAAAP/wFAUAAAAKf+/+CVeWGP4AUxWIAAABAAAAZ2Ms2A==')
(1801.47, '/DAgAAAAAAAAAP/wDwUAAAAKf0/+CanwIAAAAQAAAMtpiWA=')
(1921.5, '/DAlAAAAAAAAAP/wFAUAAAALf+/+Ck7HWP4AUxWIAAABAAAAZqHzpQ==')
(1981.47, '/DAgAAAAAAAAAP/wDwUAAAALf0/+CqEhYAAAAQAAACK9yhM=')
frame=62143 fps= 30 q=29.0 size=  759240kB time=00:34:33.68 bitrate=2999.3kbits/
(181.467, '/DAgAAAAAAAAAP/wDwUAAAABf0/+APk04AAAAQAAAM/zvg0=')
(301.467, '/DAlAAAAAAAAAP/wFAUAAAACf+/+AZ4AYP4AUxWIAAABAAAARV7fnQ==')
(361.467, '/DAgAAAAAAAAAP/wDwUAAAACf0/+AfBmIAAAAQAAAOYaSes=')
(481.5, '/DAlAAAAAAAAAP/wFAUAAAADf+/+ApU9WP4AUxWIAAABAAAArzuq7A==')
(541.467, '/DAgAAAAAAAAAP/wDwUAAAADf0/+AueXYAAAAQAAABE4LA0=')
(661.5, '/DAlAAAAAAAAAP/wFAUAAAAEf+/+A4xumP4AUxWIAAABAAAAD8WPcA==')
(721.467, '/DAgAAAAAAAAAP/wDwUAAAAEf0/+A97IoAAAAQAAAO5rvlQ=')
(841.5, '/DAlAAAAAAAAAP/wFAUAAAAFf+/+BIOf2P4AUxWIAAABAAAARz8mWQ==')
(901.467, '/DAgAAAAAAAAAP/wDwUAAAAFf0/+BNX54AAAAQAAAIYvB5g=')
frame=62157 fps= 30 q=29.0 size=  759399kB time=00:34:34.16 bitrate=2999.3kbits/
frame=62173 fps= 30 q=29.0 size=  759572kB time=00:34:34.69 bitrate=2999.2kbits/
(121.433, '/DAlAAAAAAAAAP/wFAUAAAABf+/+AKbDaP4AUxWIAAABAAAAdWToAw==')
frame=62188 fps= 30 q=29.0 size=  759766kB time=00:34:35.17 bitrate=2999.3kbits/
frame=62204 fps= 30 q=29.0 size=  759928kB time=00:34:35.70 bitrate=2999.1kbits/
frame=62218 fps= 30 q=29.0 size=  760083kB time=00:34:36.18 bitrate=2999.1kbits/
frame=62234 fps= 30 q=29.0 size=  760261kB time=00:34:36.70 bitrate=2999.0kbits/
frame=62248 fps= 30 q=29.0 size=  760417kB time=00:34:37.18 bitrate=2998.9kbits/
frame=62264 fps= 30 q=29.0 size=  760610kB time=00:34:37.71 bitrate=2998.9kbits/
Program Number 18137
PCR PID 7857
Registration Descriptor added b'\x05\x04CUEI'
type: 73 len: 121 bytes: b'Iy\x10\xb6~\xccj\xd5\xc3v\x17\x93\x0cn\xe977\xe7\xe6\x89$@\x8d\x9b%\xbc\xb4d\xec2\xe7-\xf1\x07\x88\x8b\x1cG\x01\x00\x184\xa1^\xdc\x08))\xe6\xc19\x92|\xcb\xc8_dQ)s1\xd41\xf6g\xe0h\xd5~\x9c\xd3\xf1\x89M!\xda\x10\xd2\xb8O\xe6\x9a\xd1\xf2\xdd\xe7\xe3k\xff\xc7V\xf0Xm\x97\xe3ZI\xeb8\xa5'
Traceback (most recent call last):
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki49/bin/superkabuki", line 7, in <module>
    sk.encode()
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki49/lib/python3.11/site-packages/superkabuki.py", line 192, in encode
    pid = self._parse_info(pkt)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki49/lib/python3.11/site-packages/threefive/stream.py", line 459, in _parse_info
    self._parse_tables(pkt, pid)
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki49/lib/python3.11/site-packages/threefive/stream.py", line 445, in _parse_tables
    return self._parse_pmt(pay, pid)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/imagecuetone/anaconda3/envs/ffmpeg611_kabuki49/lib/python3.11/site-packages/superkabuki.py", line 358, in _parse_pmt
    d_type = pay[idx]
             ~~~^^^^^
IndexError: index out of range

Do you have any idea about what's going on? And let me know if you need more information. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.