futzu / SCTE-35_HLS_x9k3

HLS and SCTE-35 x9k3 is a HLS Segmenter with SCTE 35, and Live Streaming from Non-Live Soures and Looping.
67 stars 17 forks source link

Can't make sidecar pts and cue to working as expected #31

Closed cisiwen closed 8 months ago

cisiwen commented 8 months ago

Hi futzu

FIrst i want to say is Merry christmas and happy new year! and scte35-threefive is amazing projects

i am working on splicing segments to insert cue points. i use simple example from readme file x9k3 -i segment11.ts -s sidecar.txt

the segment11.ts is a 6 seconds segment with 25fps and GOP of 25 and ffprobe output for the segment with iframe information Input #0, mpegts, from segment11.ts: Duration: 00:00:06.07, start: 66.116444, bitrate: 3159 kb/s Program 1 Stream #0:0[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 99 kb/s Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1DAR 16:9], 25 fps, 25 tbr, 90k tbn`

1:frame,I 26:frame,I 51:frame,I 76:frame,I 101:frame,I 126:frame,I

and inside my sidecar file i have this 68.191111, /DAWAAAAAAAAAP/wBQb+AF2lcAAAYGVbDg==

i want x9k3 to splice this segement into 2 segments with first one 2 seconds and second one 4 seconds but it always give me 3 segements in 2 seconds duration. any ideas it is possible with x9k3 or am i using tool wrong.

here is the segments and sidecar file https://github.com/cisiwen/x9k3_help_needed/tree/main

thanks

Winston

futzu commented 8 months ago

Merry Christmas and let me say, that is a solid description of the issue, with supporting details, I appreciate it.

let me show you an easier way to check iframes https://github.com/futzu/iframes

a@fu:~/x9k3_help_needed$ iframes segment11.ts 
66.191111
67.191111
68.191111
69.191111
70.191111
71.191111

You do understand that a time signal needs a segmentation descriptor to generate a CUE-OUT tag, right?

what you're saying is reasonable, and I'm not sure why it's not behaving that way. let me think on this for a minute,

futzu commented 8 months ago

Man, I think you just gave me a great idea. Currently, when x9k3 encounters an iframe, it makes segment level decisions. what I'm thinking I need ot do is make those segment level decisions, iframe level decisions and simplify what happens at the segment level to just slicing. ...... I am talking to myself here. Give me the weekend, and I can probably sort this out.,

cisiwen commented 8 months ago

You do understand that a time signal needs a segmentation descriptor to generate a CUE-OUT tag, right?

I am new to SCTE35 so at the moment i am try to learn as more as i can. from your scte35-threefive example i found some SCTE35 encoding code. i use the encode_time_signal.py example to create the SCTE35 signal which i believe it doesn't containers descriptor. will explore more from your example to see how i add segmentation descriptor.

cisiwen commented 8 months ago

Hi Adrian

really appreciate your time and help during the new year time!

let me explain the work i am facing, after hls video being created, we need allow people to change and update the cue point at the any position. it is hard we don't want re-encode the whole video. so we decide to use 1 iframe interval. at the moment we use ffmpeg to split the video and re-assembly the hls manifest with discontinuity tag. seem working but it is not good solution.

until i meet with the x9k3, it allow us to remove the discontinuity tag, it is really something i have been looking long time if it can sub-segment a segment into 2 segments with user control the duration of first sub-segment and rest duration all for second sub-segment.

Curious from the readme Segments are cut on iframes. if we don't have 1s iframe interval video. x9k3 wan't do second accuracy splicing. it will splice at the nearest iframe position right?

thanks

cisiwen commented 8 months ago

I use your iframe finder, it is much quicker than ffprobe

futzu commented 8 months ago

v0.2.39 should work correctly . FYI if you want 6 second segments use -t 6

a@fu:~/x9k3_help_needed$  x9k3 -i segment11.ts -s sidecar.txt -t 6
loading  68.191111,/DAlAAAAAAAAAP/wFAUAAAADf+/+AF2lcP4ABX5AAAMAAAAAORYtAQ==
{
    "info_section": {
        "table_id": "0xfc",
        "section_syntax_indicator": false,
        "private": false,
        "sap_type": "0x3",
        "sap_details": "No Sap Type",
        "section_length": 37,
        "protocol_version": 0,
        "encrypted_packet": false,
        "encryption_algorithm": 0,
        "pts_adjustment_ticks": 0,
        "pts_adjustment": 0.0,
        "cw_index": "0x0",
        "tier": "0xfff",
        "splice_command_length": 20,
        "splice_command_type": 5,
        "descriptor_loop_length": 0,
        "crc": "0x39162d01"
    },
    "command": {
        "command_length": 20,
        "command_type": 5,
        "name": "Splice Insert",
        "time_specified_flag": true,
        "pts_time": 68.191111,
        "pts_time_ticks": 6137200,
        "break_auto_return": true,
        "break_duration": 4.0,
        "break_duration_ticks": 360000,
        "splice_event_id": 3,
        "splice_event_cancel_indicator": false,
        "out_of_network_indicator": true,
        "program_splice_flag": true,
        "duration_flag": true,
        "splice_immediate_flag": false,
        "unique_program_id": 3,
        "avail_num": 0,
        "avail_expected": 0
    },
    "descriptors": []
}

./seg0.ts:   start: 66.191111   end: 68.191111   duration: 2.000000
#EXT-X-CUE-OUT = 4.0
./seg1.ts:   start: 68.191111   end: 72.191111   duration: 4.000000
futzu commented 8 months ago

The procedure your describing is not going to fix your CUE-OUT-CONT tags, and there are several other potential probl;ems. You'd probably be better off just changing the sidecar file and then just do the whole video with x9k3. x9k3 can take the ffmpeg generated m3u8 file as input.

x9k3 -i ffmpeg_generated.m3u8   -t6  -o output_directory -s sidecar.txt

As far as encoding goes , if you can use a splice insert, you can use threefive.encode.mk_splice_insert mk_splice_insert(event_id, pts=None, duration=None, out=False)

from threefive.encode import mk_splice_insert

# This is a CUE-OUT at 68.191111, for 60 seconds
cue-out= mk_splice_insert(event_id=1, pts =68.191111,duration=60.0,out=True).encode()
print(cue-out)
'/DAlAAAAAAAAAP/wFAUAAAABf+/+AF2lcP4AUmXAAAEAAAAAqY0bkg=='

# This is the CUE-IN
cue-in= mk_spice_insert(event_id=1, pts=128.191111,out=False).encode()
print(cue-in)
'/DAgAAAAAAAAAP/wDwUAAAABf0/+ALALMAABAAAAALhvRkU='
futzu commented 8 months ago

try this to make your cues

adbreak.py.gz

optional arguments: -h, --help show this help message and exit -d DURATION, --duration DURATION duration of ad break [default: 60.0] -p PTS, --pts PTS start pts for ad break [default: 0.0] -s SIDECAR, --sidecar SIDECAR Sidecar file of SCTE-35 (pts,cue) pairs. [default:sidecar.txt]


run it like :
```lua
python3 adbreak.py  -d 60 -p 68.191111 -s sidecar.txt

your sidecar will have the CUE-OUT and CUE-IN.

a@fu:~/x9k3_help_needed$ cat sidecar.txt
68.191111,/DAlAAAAAAAAAP/wFAUAAAABf+/+AF2lcP4AUmXAAAEAAAAAqY0bkg==  # CUE-OUT
128.191111,/DAgAAAAAAAAAP/wDwUAAAABf0/+ALALMAABAAAAALhvRkU=     # CUE-IN

x9k3 will make a CUE-OUT , all the CUE-OUT-CONT tags, and a CUE-IN.

cisiwen commented 8 months ago

Hi Adrian i tried the the latest change, now it works perfect for me, and the convenient script of adbreak.py make creating sidecar file easier. sometime i will try to do whole video with x9k3. looks the new update also fixed the last sub segment freezing in latest videojs http streaming player.

thanks for your help and the X9K3 project

Winston

futzu commented 8 months ago

Sure man , you gave me what I needed, that makes it easy.

upgrade to 0.2.41, it's even better and adbreak installs with x9k3.


a@fu:~$ adbreak -h
usage: adbreak [-h] [-d DURATION] [-p PTS] [-s SIDECAR]

optional arguments:
  -h, --help            show this help message and exit
  -d DURATION, --duration DURATION
                        set duration of ad break. [ default: 60.0 ]
  -p PTS, --pts PTS     set start pts for ad break. Not setting pts will
                        generate a Splice Immediate CUE-OUT. [ default: 0.0 ]
  -s SIDECAR, --sidecar SIDECAR
                        Sidecar file of SCTE-35 (pts,cue) pairs. [ default:
                        sidecar.txt ]
a@fu:~$