Last x9k3 not working correctly with Mpeg2
sergeyshulga opened this issue · 14 comments
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
Do you remember the last version that worked for you?
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.
- gopchop says test2 has issues
parse_MPEG2_program_stream @ 0(0.00%): expecting pack_start_code, got 0x47 0x03 0xE9 0x11
parse_MPEG2_program_stream @ 102400(0.24%): garbage data seen from 0 to 102400.
parse_MPEG2_program_stream @ 102400(0.24%): More than 100K of garbage -- aborting parse.
parse_MPEG2_program_stream @ 102400(0.24%): expecting MPEG_program_end_code marker (length 4)
No Groups of Pictures found!
- tsreport says test2 has issues
2068: TS Packet 12 PID 03e9 stream type not identified
2256: TS Packet 13 PID 03e9 stream type not identified
2444: TS Packet 14 PID 03e9 stream type not identified
2632: TS Packet 15 PID 03e9 stream type not identified
2820: TS Packet 16 PID 03e9 stream type not identified
3008: TS Packet 17 PID 03e9 stream type not identified
3196: TS Packet 18 PID 03e9 stream type not identified
3384: TS Packet 19 PID 03ea stream type not identified
Adaptation field len 95 [flags 00]
3572: TS Packet 20 PID 03ea [pusi] stream type not identified
- ffmpeg say test2 has issues
[mpeg2video @ 0x5569d995c600] Invalid frame dimensions 0x0.
[mpeg2video @ 0x5569d9e0cf80] ac-tex damaged at 73 9
[mpeg2video @ 0x5569d9e0cf80] Warning MVs not available
[mpeg2video @ 0x5569d9e0cf80] concealing 320 DC, 320 AC, 320 MV errors in P frame
test2_mp2.ts?dl=0: corrupt input packet in stream 1
[mpeg2video @ 0x5569d9e0cf80] ac-tex damaged at 79 23
[mpeg2video @ 0x5569d9e0cf80] Warning MVs not available
[mpeg2video @ 0x5569d9e0cf80] concealing 536 DC, 536 AC, 536 MV errors in I frame
test2_mp2.ts?dl=0: corrupt decoded frame in stream 1
[mpegts @ 0x5569d9954c80] PES packet size mismatch0:02:36.48 bitrate=N/A speed=N/A
[mpegts @ 0x5569d9954c80] Packet corrupt (stream = 2, dts = 15487678).
[mp1 @ 0x5569d9b5a480] Header missing
Error while decoding stream #0:2: Invalid data found when processing input
[mpegts @ 0x5569d9954c80] Packet corrupt (stream = 1, dts = 15510358).
test2_mp2.ts?dl=0: corrupt input packet in stream 1
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 69 42
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 3
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 2 4
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 5
[mpeg2video @ 0x5569d9e0cf80] Invalid mb type in B-frame at 1 6
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 7
[mpeg2video @ 0x5569d9e0cf80] ac-tex damaged at 3 8
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 9
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 10
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 12 12
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 13
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 14
[mpeg2video @ 0x5569d9e0cf80] ac-tex damaged at 9 15
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 16
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 17
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 18
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 19
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 20
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 15 21
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 22
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 7 23
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 28 24
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 7 25
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 26
[mpeg2video @ 0x5569d9e0cf80] ac-tex damaged at 2 27
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 28
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 29
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 30
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 31
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 32
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 33
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 34
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 35
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 36
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 1 37
[mpeg2video @ 0x5569d9e0cf80] slice mismatch
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 39
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 40
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 41
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 42
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 1 43
[mpeg2video @ 0x5569d9e0cf80] 00 motion_type at 0 44
[mpeg2video @ 0x5569d9e0cf80] ac-tex damaged at 0 45
[mpeg2video @ 0x5569d9e0cf80] Warning MVs not available
- if I encode test2 as mpeg2video
ffmpeg -copyts -i test2_mp2.ts\?dl\=0 -c:v mpeg2video -c:a aac -map 0 -y test2-mpeg2v.ts
- x9k3 has no problem
x9k3 -i test2-mpeg2v.ts
./seg0.ts start: 164.760000 duration: 2.140000 stream diff: 2.129197
./seg1.ts start: 166.900000 duration: 2.000000 stream diff: 4.12144
./seg2.ts start: 168.900000 duration: 2.120000 stream diff: 6.234695
./seg3.ts start: 171.020000 duration: 2.060000 stream diff: 8.288027
./seg4.ts start: 173.080000 duration: 2.180000 stream diff: 10.463874
./seg5.ts start: 175.260000 duration: 2.040000 stream diff: 12.495723
./seg6.ts start: 177.300000 duration: 2.040000 stream diff: 14.529787
./seg7.ts start: 179.340000 duration: 2.120000 stream diff: 16.643476
./seg8.ts start: 181.460000 duration: 2.080000 stream diff: 18.71938
./seg9.ts start: 183.540000 duration: 2.080000 stream diff: 20.794641
./seg10.ts start: 185.620000 duration: 2.000000 stream diff: 22.789957
./seg11.ts start: 187.620000 duration: 2.080000 stream diff: 24.863782
./seg12.ts start: 189.700000 duration: 2.120000 stream diff: 26.979175
./seg13.ts start: 191.820000 duration: 2.200000 stream diff: 29.173732
./seg14.ts start: 194.020000 duration: 2.040000 stream diff: 31.210031
./seg15.ts start: 196.060000 duration: 2.120000 stream diff: 33.327196
./seg16.ts start: 198.180000 duration: 2.040000 stream diff: 35.362404
./seg17.ts start: 200.220000 duration: 2.120000 stream diff: 37.478496
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
Actually, you dont even need to re-encoded,
try this:
ffmpeg -i test2_mp2.ts\?dl\=0 -c copy -map 0 -y tested2.ts
- x9k3
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
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.
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
I can show you how to changes iframes.py to act like it used to, x9k3 uses iframes.py to find the iframes
Shit. I just figured it out. Give me a minute to check things.
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
Wow! You fix it?
Well, sort of, give me a minute.
python3 -mpip install --upgrade x9k3
- use -S or --shulga to enable shulga mode iframe detection.
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)
- Normal Mode
a@debian:~/bfm/mo$ x9k3 -i test2.m2ts
./seg0.ts start: 162.917311 duration: 7.400000 stream diff: 7.349554
./seg1.ts start: 170.317311 duration: 24.480000 stream diff: 31.664721
- Shulga mode
a@debian:~/bfm/mo$ x9k3 -S -i test2.m2ts
./seg0.ts start: 162.917311 duration: 2.000000 stream diff: 1.983146
./seg1.ts start: 164.917311 duration: 2.000000 stream diff: 3.963401
./seg2.ts start: 166.917311 duration: 2.000000 stream diff: 5.949247
./seg3.ts start: 168.917311 duration: 2.000000 stream diff: 7.935945
./seg4.ts start: 170.917311 duration: 2.000000 stream diff: 9.922964
./seg5.ts start: 172.917311 duration: 2.000000 stream diff: 11.909577
./seg6.ts start: 174.917311 duration: 2.000000 stream diff: 13.896203
./seg7.ts start: 176.917311 duration: 2.000000 stream diff: 15.883031
./seg8.ts start: 178.917311 duration: 2.000000 stream diff: 17.870347
./seg9.ts start: 180.917311 duration: 2.000000 stream diff: 19.856962
./seg10.ts start: 182.917311 duration: 2.000000 stream diff: 21.844224
./seg11.ts start: 184.917311 duration: 2.000000 stream diff: 23.831459
./seg12.ts start: 186.917311 duration: 2.000000 stream diff: 25.818354
./seg13.ts start: 188.917311 duration: 2.000000 stream diff: 27.805685
./seg14.ts start: 190.917311 duration: 2.000000 stream diff: 29.792341
./seg15.ts start: 192.917311 duration: 2.000000 stream diff: 31.779493
./seg16.ts start: 194.917311 duration: 2.000000 stream diff: 33.765898
./seg17.ts start: 196.917311 duration: 2.000000 stream diff: 35.753143
./seg18.ts start: 198.917311 duration: 2.000000 stream diff: 37.74043
Yes, tested with H264 and Mpeg2 udp in -S mode - seems all works correctly now. Thank you, man!
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 :)