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

Last x9k3 not working correctly with Mpeg2 #6

Closed sergeyshulga closed 1 year ago

sergeyshulga commented 1 year ago

Hello. Uses latest x9k3 and threefive. H264 working ok, but Mpeg2 splits with different segments duration(not 2 default seconds). It happened on file or live UDP streams. Looks like it cannot found i-frames in stream.

H264 file https://www.dropbox.com/s/5qswgdnt22ykp6d/test1.ts?dl=0 C:\Python>python.exe x9k3.py -i test1.ts ./seg0.ts start: 45.693333 duration: 2.160000 stream diff: 2.1 28998 ./seg1.ts start: 47.853333 duration: 2.160000 stream diff: 4.2 58997 ./seg2.ts start: 50.013333 duration: 2.160000 stream diff: 6.3 91995 ./seg3.ts start: 52.173333 duration: 2.160000 stream diff: 8.5 25993 ./seg4.ts start: 54.333333 duration: 2.160000 stream diff: 10. 658992 ./seg5.ts start: 56.493333 duration: 2.160000 stream diff: 12. 79299 ./seg6.ts start: 58.653333 duration: 2.160000 stream diff: 14. 925989 ./seg7.ts start: 60.813333 duration: 2.160000 stream diff: 17. 059987 ./seg8.ts start: 62.973333 duration: 2.160000 stream diff: 19. 192986 ./seg9.ts start: 65.133333 duration: 2.160000 stream diff: 21. 325984 ./seg10.ts start: 67.293333 duration: 2.160000 stream diff: 23. 459983 ./seg11.ts start: 69.453333 duration: 2.160000 stream diff: 25. 592981 ./seg12.ts start: 71.613333 duration: 2.160000 stream diff: 27. 72698 ./seg13.ts start: 73.773333 duration: 2.160000 stream diff: 29. 860978 ./seg14.ts start: 75.933333 duration: 2.160000 stream diff: 31. 993977 ./seg15.ts start: 78.093333 duration: 2.160000 stream diff: 34. 124975 ./seg16.ts start: 80.253333 duration: 2.160000 stream diff: 36. 257974 ./seg17.ts start: 82.413333 duration: 2.160000 stream diff: 38. 390972 ./seg18.ts start: 84.573333 duration: 2.160000 stream diff: 40. 52197 ./seg19.ts start: 86.733333 duration: 2.160000 stream diff: 42. 653969 ./seg20.ts start: 88.893333 duration: 2.160000 stream diff: 44. 784967 ./seg21.ts start: 91.053333 duration: 2.160000 stream diff: 46. 913965 ./seg22.ts start: 93.213333 duration: 2.160000 stream diff: 49. 045963 ./seg23.ts start: 95.373333 duration: 2.160000 stream diff: 51. 175962 ./seg24.ts start: 97.533333 duration: 2.160000 stream diff: 53. 30796 ./seg25.ts start: 99.693333 duration: 2.160000 stream diff: 55. 437959 ./seg26.ts start: 101.853333 duration: 2.160000 stream diff: 57. 569957 ./seg27.ts start: 104.013333 duration: 2.160000 stream diff: 59. 701955 ./seg28.ts start: 106.173333 duration: 2.160000 stream diff: 61. 831954

MPEG2 file https://www.dropbox.com/s/v5vrnlbqpqsc7xn/test2_mp2.ts?dl=0 C:\Python>python.exe x9k3.py -i test2_mp2.ts ./seg0.ts start: 170.317311 duration: 24.480000 stream diff: 23. 890966

futzu commented 1 year ago

Do you remember the last version that worked for you?

futzu commented 1 year ago

Dude, you have to come up with a new clip, Ive seen that one too many times :)

The encoding is all jacked up is the problem.

test2 8608k bitrate 50fps mpeg2video and mpeg1 audio

Nothing likes that video.

* if I encode test2 as mpeg2video

```lua
ffmpeg -copyts  -i  test2_mp2.ts\?dl\=0 -c:v mpeg2video -c:a aac -map 0  -y  test2-mpeg2v.ts
futzu commented 1 year ago

ffmpeg finds the iframes, so I'm sure it can be done, however, it's just not worth my time to figure it out not when there is a simple fix. If you use -map 0 it will keep the SCTE-35 Stream , even though ffmpeg changes the stream type to 0x06, x9k3 will still be able to parse the SCTE35 out. threefive and ffmpeg

ffmpeg -copyts  -i  test2_mp2.ts\?dl\=0 -c:v mpeg2video -c:a aac -map 0  -y  test2-mpeg2v.ts
futzu commented 1 year ago

Actually, you dont even need to re-encoded, try this:

ffmpeg -i test2_mp2.ts\?dl\=0  -c copy -map 0 -y  tested2.ts

a@debian:~/bfm/mo$ x9k3 -i tested2.ts
./seg0.ts           start: 1.840000 duration: 2.160000  stream diff: 2.14437
./seg1.ts           start: 4.000000 duration: 2.160000  stream diff: 4.288976
./seg2.ts           start: 6.160000 duration: 2.160000  stream diff: 6.436259
./seg3.ts           start: 8.320000 duration: 2.160000  stream diff: 8.582556
./seg4.ts          start: 10.480000 duration: 2.160000  stream diff: 10.729193
./seg5.ts          start: 12.640000 duration: 2.160000  stream diff: 12.876002
./seg6.ts         start: 14.800000  duration: 2.160000  stream diff: 15.021905
./seg7.ts         start: 16.960000  duration: 2.160000  stream diff: 17.16888
./seg8.ts         start: 19.120000  duration: 2.160000  stream diff: 19.315207
./seg9.ts         start: 21.280000  duration: 2.160000  stream diff: 21.462161
./seg10.ts  start: 23.440000    duration: 2.160000  stream diff: 23.608117
./seg11.ts  start: 25.600000    duration: 2.160000  stream diff: 25.754877
./seg12.ts  start: 27.760000    duration: 2.160000  stream diff: 27.900893
./seg13.ts  start: 29.920000    duration: 2.160000  stream diff: 30.047836
./seg14.ts  start: 32.080000    duration: 2.160000  stream diff: 32.193586
./seg15.ts  start: 34.240000    duration: 2.160000  stream diff: 34.338997
./seg16.ts  start: 36.400000    duration: 2.160000  stream diff: 36.486096
sergeyshulga commented 1 year ago

Strange that mpeg2 ts file worked ok before. We use it in issue #1. Ffmpeg/ffprobe show some issues on that clip, but TSreader or StreamGuru have no errors. It created with MainConcept encoder, and i tried change different options, but not have success to make mpeg2 stream readable for x9k3 ((. Not want to use ffmpeg in pipe between encoder and x9k3. But i think its not too important to use HLS with Mpeg2 segments in 2022, thank you for your time.

futzu commented 1 year ago

I know what you mean about having to use ffmpeg, I know why it used to work, because I had it wrong :) That was the first thing I did when I saw what the video was.It's in the iframe detection, so I was just going to put it back the same way,but when I tested it, my iframes did not line up with what ffmpeg said. I dont think I was actually hitting the iframes, that video has a gop size of like 12 according to ffmpeg, so I think it worked, because even if I missed the iframe, it was less than 0.25 seconds to the next one.

It was 2 seconds on the nose, every time , and that never happens with iframes

https://user-images.githubusercontent.com/87797497/175749076-7b0cdc17-93eb-4050-8d6b-cb61e05cbc15.png

I can show you how to changes iframes.py to act like it used to, x9k3 uses iframes.py to find the iframes

futzu commented 1 year ago

Shit. I just figured it out. Give me a minute to check things.

futzu commented 1 year ago

cat index.m3u8

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXTINF:2.160,
seg0.ts
#EXTINF:2.160,
seg1.ts
#EXTINF:2.160,
seg2.ts
#EXTINF:2.160,
seg3.ts
#EXTINF:2.160,
seg4.ts
#EXTINF:2.160,
seg5.ts
#EXTINF:2.160,
seg6.ts
#EXTINF:2.160,
seg7.ts
#EXTINF:2.160,
seg8.ts
#EXTINF:2.160,
seg9.ts
#EXTINF:2.160,
seg10.ts
#EXTINF:2.160,
seg11.ts
#EXTINF:2.160,
seg12.ts
#EXTINF:2.160,
seg13.ts
#EXTINF:2.160,
seg14.ts
#EXTINF:2.160,
seg15.ts
#EXTINF:2.160,
seg16.ts
#EXT-X-ENDLIST
sergeyshulga commented 1 year ago

Wow! You fix it?

futzu commented 1 year ago

Well, sort of, give me a minute.

futzu commented 1 year ago
python3 -mpip install --upgrade x9k3
a@debian:~/build/x9k3$ x9k3 -h
usage: x9k3 [-h] [-i INPUT] [-o OUTPUT_DIR] [-s SIDECAR] [-t TIME]
            [-T HLS_TAG] [-w WINDOW_SIZE] [-d] [-l] [-r] [-S] [-v] [-p]

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"
  -o OUTPUT_DIR, --output_dir OUTPUT_DIR
                        Directory for segments and index.m3u8 ( created if it
                        does not exist )
  -s SIDECAR, --sidecar SIDECAR
                        Sidecar file of scte35 cues. each line contains PTS,
                        Cue
  -t TIME, --time TIME  Segment time in seconds ( default is 2)
  -T HLS_TAG, --hls_tag HLS_TAG
                        x_scte35, x_cue, x_daterange, or x_splicepoint
                        (default x_cue)
  -w WINDOW_SIZE, --window_size WINDOW_SIZE
                        sliding window size(default:5)
  -d, --delete          delete segments ( enables --live )
  -l, --live            Flag for a live event ( enables sliding window m3u8 )
  -r, --replay          Flag for replay (looping) ( enables --live and
                        --delete )
  -S, --shulga          Flag to enable Shulga iframe detection mode                  <-- Shulga mode 
  -v, --version         Show version
  -p, --program_date_time
                        Flag to add Program Date Time tags to index.m3u8 (
                        enables --live)
futzu commented 1 year ago
sergeyshulga commented 1 year ago

Yes, tested with H264 and Mpeg2 udp in -S mode - seems all works correctly now. Thank you, man!

futzu commented 1 year ago

You were a big help to me testing everything when I started x9k3, I figure I owe you at least your own command line switch :)