Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long 608 Captions are are not displayed properly, and sometimes not at all. #5952

Closed
5 tasks done
jcekstrom opened this issue Nov 3, 2023 · 3 comments · Fixed by #5953
Closed
5 tasks done

Long 608 Captions are are not displayed properly, and sometimes not at all. #5952

jcekstrom opened this issue Nov 3, 2023 · 3 comments · Fixed by #5953

Comments

@jcekstrom
Copy link

What version of Hls.js are you using?

1.4.12

What browser (including version) are you using?

Firefox 119.0, Edge 118.0.2088.69, Chrome 119.6045.105

What OS (including version) are you using?

Win11

Test stream

https://storage.ekstech.net/video/long_caption_test/master.m3u8

Configuration

{
  "debug": true,
  "enableWorker": true,
  "lowLatencyMode": true,
  "backBufferLength": 90
}

Additional player setup steps

https://hlsjs.video-dev.org/demo defaults

Checklist

Steps to reproduce

  1. Open https://hlsjs.video-dev.org/demo
  2. Paste https://storage.ekstech.net/video/long_caption_test/master.m3u8 into the stream bar.
  3. Click Apply
  4. Pause and turn on English Captions

Expected behaviour

1
00:00:00,534 --> 00:00:02,001
A long 3 line caption is coming...

00:00:02,334 --> 00:00:04,501

  • There are three lines to
  • this caption. Can you see
  • ALL THREE LINE?!?!?!

2
00:00:04,803 --> 00:00:06,002
Did you see the 3 lines?

What actually happened?

It displayed caption #1 and #3, but the long caption, #2 is lost.

This is due to the fact that cea-608 is embedded into 2 separate cea-708 packets as which are then embedded as user_data_registered_itu_t_t35 into the sei_rbsp() as sei_message() according to the ITU-T H.264 spec.

There are a few small problems with the implementation found in src/utils/mp4-tools.ts:974 parseSEIMesageFromNALu(...):
1- All sei_message payload_type are restricted to 8 bits/1 byte, yet the parsing logic ignores this, allowing for payloadType to have values larger than 255.
2- The parsing logic for the payloadSize will not always parse all the data associated with a single sei_message, which will cause the parsing to be off, and the corruption of parsing of any sei_message following the first.

Console output

Using Hls.js config: Object
logger.ts:74 [log] > Debug logs enabled for "Hls instance" in hls.js version 1.4.12
hls.ts:410 [log] > stopLoad
hls.ts:379 [log] > loadSource:https://storage.ekstech.net/video/long_caption_test/master.m3u8
stream-controller.ts:569 [log] > [stream-controller]: Trigger BUFFER_RESET
hls.ts:351 [log] > attachMedia
level-controller.ts:269 [log] > [level-controller]: manifest loaded, 1 level(s) found, first bitrate: 545965
buffer-controller.ts:148 [log] > 1 bufferCodec event(s) expected
hls.ts:400 [log] > startLoad(-1)
level-controller.ts:351 [log] > [level-controller]: Switching to level 0 from level -1
level-controller.ts:520 [log] > [level-controller]: Loading level index 0 with URI 1/1 https://storage.ekstech.net/video/long_caption_test/profile.m3u8
base-stream-controller.ts:1777 [log] > [stream-controller]: STOPPED->IDLE
base-stream-controller.ts:1777 [log] > [subtitle-stream-controller]: STOPPED->IDLE
stream-controller.ts:634 [log] > [stream-controller]: Level 0 loaded [0,0], cc [0, 0] duration:6.006
buffer-controller.ts:800 [log] > [buffer-controller]: Media source opened
buffer-controller.ts:692 [log] > [buffer-controller]: Updating Media Source duration to 6.006
base-stream-controller.ts:743 [log] > [stream-controller]: Loading fragment 0 cc: 0 of [0-0] level: 0, target: 0
base-stream-controller.ts:1777 [log] > [stream-controller]: IDLE->FRAG_LOADING
transmuxer-interface.ts:85 [log] > injecting Web Worker for "main"
transmuxer-interface.ts:227 [log] > [transmuxer-interface, main]: Starting new transmux session for sn: 0 p: -1 level: 0 id: 1
        discontinuity: true
        trackSwitch: true
        contiguous: false
        accurateTimeOffset: true
        timeOffset: 0
        initSegmentChange: true
base-stream-controller.ts:386 [log] > [stream-controller]: Loaded fragment 0 of level 0
timeline-chart.ts:754 Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true. See: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently
drawLineX @ timeline-chart.ts:754
/favicon.ico:1 
        
        
       Failed to load resource: the server responded with a status of 404 ()
6408d0c0-7602-49c8-bfc2-f77096b95cfb:542 [log] > Debug logs enabled for "main" in hls.js version 1.4.12
transmuxer-interface.ts:379 [log] > [mp4-remuxer]: ISGenerated flag reset
transmuxer-interface.ts:379 [log] > [mp4-remuxer]: initPTS & initDTS reset
transmuxer-interface.ts:379 [log] > [mp4-remuxer]: reset next timestamp
transmuxer-interface.ts:379 [log] > manifest codec:mp4a.40.2, ADTS type:2, samplingIndex:3
transmuxer-interface.ts:379 [log] > parsed codec:mp4a.40.5, rate:48000, channels:2
base-stream-controller.ts:1777 [log] > [stream-controller]: FRAG_LOADING->PARSING
stream-controller.ts:1275 [log] > [stream-controller]: Init audio buffer, container:audio/mp4, codecs[selected/level/parsed]=[mp4a.40.2/mp4a.40.2/mp4a.40.5]
stream-controller.ts:1286 [log] > [stream-controller]: Init video buffer, container:video/mp4, codecs[level/parsed]=[avc1.64001e/avc1.64001e]
buffer-controller.ts:765 [log] > [buffer-controller]: creating sourceBuffer(audio/mp4;codecs=mp4a.40.2)
buffer-controller.ts:765 [log] > [buffer-controller]: creating sourceBuffer(video/mp4;codecs=avc1.64001e)
audio-stream-controller.ts:128 [log] > [audio-stream-controller]: InitPTS for cc: 0 found from main: 0
transmuxer-interface.ts:379 [log] > [transmuxer.ts]: Flushed fragment 0 of level 0
base-stream-controller.ts:1777 [log] > [stream-controller]: PARSING->PARSED
base-stream-controller.ts:572 [log] > [stream-controller]: Buffered main sn: 0 of level 0 (frag:[0.000-6.059] > buffer:[0.000-6.040])
base-stream-controller.ts:1777 [log] > [stream-controller]: PARSED->IDLE
buffer-controller.ts:544 [log] > [buffer-controller]: audio sourceBuffer now EOS
buffer-controller.ts:544 [log] > [buffer-controller]: video sourceBuffer now EOS
buffer-controller.ts:551 [log] > [buffer-controller]: Queueing mediaSource.endOfStream()
base-stream-controller.ts:1777 [log] > [stream-controller]: IDLE->ENDED
buffer-controller.ts:568 [log] > [buffer-controller]: Calling mediaSource.endOfStream()
buffer-controller.ts:819 [log] > [buffer-controller]: Media source ended

Chrome media internals output

No response

@jcekstrom jcekstrom added Bug Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Nov 3, 2023
@jcekstrom
Copy link
Author

long_caption_test.zip

Here are the relevant files for the test, should the link to the test go missing in the future.

@robwalch robwalch added Confirmed and removed Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Nov 3, 2023
@robwalch
Copy link
Collaborator

robwalch commented Nov 3, 2023

Hi Joey,

Thanks for the detailed bug report and sample.

This is due to the fact that cea-608 is embedded into 2 separate cea-708 packets as which are then embedded as user_data_registered_itu_t_t35 into the sei_rbsp() as sei_message() according to the ITU-T H.264 spec.

There are a few small problems with the implementation found in src/utils/mp4-tools.ts:974 parseSEIMesageFromNALu(...):
1- All sei_message payload_type are restricted to 8 bits/1 byte, yet the parsing logic ignores this, allowing for payloadType to have values larger than 255.
2- The parsing logic for the payloadSize will not always parse all the data associated with a single sei_message, which will cause the parsing to be off, and the corruption of parsing of any sei_message following the first.

As you seem to have a good handle on the issue and what is unique about these captions would you consider providing a fix in the form of a PR?

jcekstrom pushed a commit to jcekstrom/hls.js that referenced this issue Nov 3, 2023
In mp4-tools.ts

* Fixed parsing for sei_message, by always consuming the entire message,
  before parsing the message according to payload_type

* Fixed payloadType / payloadSize parsing to ensure they never exceed
  255, as the field is restricted to 8 bytes.
robwalch pushed a commit that referenced this issue Nov 22, 2023
In mp4-tools.ts

* Fixed parsing for sei_message, by always consuming the entire message,
  before parsing the message according to payload_type

* Fixed payloadType / payloadSize parsing to ensure they never exceed
  255, as the field is restricted to 8 bytes.
@robwalch robwalch linked a pull request Nov 28, 2023 that will close this issue
2 tasks
@robwalch robwalch added the Verify Fixed An unreleased bug fix has been merged and should be verified before closing. label Nov 28, 2023
@robwalch robwalch added this to the 1.5.0 milestone Nov 28, 2023
@robwalch
Copy link
Collaborator

robwalch commented Dec 7, 2023

Closing as fixed in v1.5.0-beta.1

@robwalch robwalch closed this as completed Dec 7, 2023
@robwalch robwalch removed the Verify Fixed An unreleased bug fix has been merged and should be verified before closing. label Dec 7, 2023
eowino added a commit to DiceTechnology/hls.js that referenced this issue Jan 15, 2024
* chore(deps): update dependency chromedriver to v118 (video-dev#5919)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency lint-staged to v15 (video-dev#5920)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update tjenkinson/gh-action-auto-merge-dependency-updates action to v1.3.5 (video-dev#5922)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency lint-staged to v15.0.1

* chore(deps): update dependency lint-staged to v15.0.2

* chore(deps): update dependency chromedriver to v118.0.1

* chore(deps): update dependency @rollup/plugin-replace to v5.0.4

* chore(deps): update dependency wrangler to v3.13.2

* chore(deps): update dependency wrangler to v3.14.0

* chore(deps): update dependency @types/chai to v4.3.9

* chore(deps): update dependency @rollup/plugin-commonjs to v25.0.7

* chore(deps): update typescript-eslint monorepo to v6.8.0

* chore(deps): update typescript-eslint monorepo to v6.9.0

* chore(deps): update dependency @types/mocha to v10.0.3

* chore(deps): update dependency @types/chart.js to v2.9.39

* chore(deps): update dependency @types/sinon-chai to v3.2.11

* chore(deps): update dependency sinon to v16.1.1

* chore(deps): update dependency eslint-plugin-import to v2.29.0

* chore(deps): update dependency sinon to v16.1.3

* chore(deps): update dependency eslint to v8.52.0

* chore(deps): update dependency wrangler to v3.15.0

* chore(deps): update dependency @rollup/plugin-replace to v5.0.5

* Add named exports for classes and enums to ESM output
Resolves video-dev#5630

* chore(deps): update dependency @microsoft/api-documenter to v7.23.10

* chore(deps): update dependency @microsoft/api-extractor to v7.38.1

* chore(deps): update dependency @microsoft/api-documenter to v7.23.11

* chore(deps): update dependency @microsoft/api-extractor to v7.38.2

* chore(deps): update typescript-eslint monorepo to v6.9.1

* chore(deps): update typescript-eslint monorepo to v6.10.0

* chore(deps): update dependency eslint to v8.53.0

* Update README.md

* Update README.md

* Update README.md

* chore(deps): update dependency @types/mocha to v10.0.4

* chore(deps): update dependency selenium-webdriver to v4.15.0

* chore(deps): update dependency @types/chart.js to v2.9.40

* chore(deps): update dependency @types/chai to v4.3.10

* chore(deps): update dependency @types/sinon-chai to v3.2.12

* Fix detach attach behavior dropping one of two SourceBuffers

* Use Content Steering Pathways to manage Redundant Streams (video-dev#5970)

* Use Content Steering Pathways to manage Redundant Streams and resolve their errors
* Ensure correct Pathway penalization on Playlist loading errors
* Do not reload Content Steering manifest while media is ended or detached

* chore(deps): update babel monorepo to v7.23.3

* Remove use of `self` from `enableLogger` (video-dev#5936)

Fixes video-dev#5905

* Refactor CMCD controller and tests to use the common media library utilities (video-dev#5903)

* refactor CMCD controller and test to use common media library
* update build script to transpile the @svta package
* add ability to specify cmcd keys

* chore(deps): update dependency lint-staged to v15.1.0

* chore(deps): update dependency @microsoft/api-extractor to v7.38.3

* chore(deps): update typescript-eslint monorepo to v6.11.0

* chore(deps): update typescript-eslint monorepo to v6.12.0

* chore(deps): update dependency @microsoft/api-documenter to v7.23.12

* Fix regression introduced with video-dev#5689 Lazy init CEA608 parsers found in video-dev#5953 (video-dev#5986)

* Fix issues with long cea608 captions. video-dev#5952

In mp4-tools.ts

* Fixed parsing for sei_message, by always consuming the entire message,
  before parsing the message according to payload_type

* Fixed payloadType / payloadSize parsing to ensure they never exceed
  255, as the field is restricted to 8 bytes.

* chore(deps): update dependency node to v20 (video-dev#5928)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency sinon to v17 (video-dev#5944)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update actions/setup-node action to v4 (video-dev#5948)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency chromedriver to v119 [security] (video-dev#5965)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency prettier to v3.1.0 (video-dev#5983)

* chore(deps): update dependency prettier to v3.1.0

* Run prettier

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tom Jenkinson <[email protected]>

* Configure typescript, eslint and prettier caches (video-dev#5990)

* Rollup 4 (video-dev#5886)

* Update karma-rollup-preprocessor to version that works in watch mode (video-dev#5991)

* chore(deps): update dependency @svta/common-media-library to v0.5.1

* chore(deps): update dependency wrangler to v3.16.0

* chore(deps): update dependency wrangler to v3.17.1

* chore(deps): update dependency rollup to v4.5.2

* chore(deps): update dependency eslint to v8.54.0

* API enhancements for audio and subtitle selection
Resolves video-dev#5532

* Remove note about "canplay" that references code removed from the example (related to autoplay policy)
Closes video-dev#3153

* Fix issues parsing sei_messages

In mp4-tools.ts

* Fixed parsing for sei_message to remove the incorrect masking to 8
  bits for the sei message size.

* Remove SEI payload type masking

* chore(deps): update dependency @types/chart.js to v2.9.41

* chore(deps): update dependency @types/chai to v4.3.11

* chore(deps): update dependency @types/mocha to v10.0.5

* chore(deps): update dependency @types/mocha to v10.0.6

* Expand isSupported check to test other codecs
Resolves video-dev#6004

* Add `videoPreference` config option for HDR/SDR VIDEO-RANGE selection and priority
Resolves video-dev#2489

* Recover from media error after MediaSource ended following SourceBuffer update error event

* Fix exception on 2019 Tizen where MediaCapabilities is undefined

* Add `isMSESupported` check
Add named exports for and expose statically: `isSupported`, `isMSESupported`, and `getMediaSource`

* chore(deps): update dependency @rollup/plugin-alias to v5.1.0

* chore(deps): update dependency rollup to v4.6.0

* chore(deps): update dependency rollup to v4.6.1

* chore(deps): update typescript-eslint monorepo to v6.13.0

* chore(deps): update typescript-eslint monorepo to v6.13.2

* chore(deps): update babel monorepo to v7.23.5

* Remove use of deprecated WebKitDataCue and hand Cue instantiation and custom property setting errors
Fixes video-dev#6020

* Add polyfill for isSafeInteger

* Fix esds box parsing for for usac audio

* Update README Compatibility section

* chore(deps): update dependency @svta/common-media-library to v0.6.0

* chore(deps): update dependency wrangler to v3.18.0

* chore(deps): update dependency wrangler to v3.19.0

* chore(deps): update dependency eslint to v8.55.0

* chore(deps): update dependency eslint-config-prettier to v9.1.0

* chore(deps): update dependency lint-staged to v15.2.0

* chore(deps): update dependency @microsoft/api-documenter to v7.23.13

* chore(deps): update dependency @microsoft/api-extractor to v7.38.4

* chore(deps): update dependency @microsoft/api-extractor to v7.38.5

* chore(deps): update dependency @microsoft/api-documenter to v7.23.14

* Use addEventListener for MediaKeySession events
video-dev#6034

* chore(deps): update dependency selenium-webdriver to v4.16.0

* fix(latency-controller): only sync live stream

* chore(deps): update actions/github-script action to v7 (video-dev#5996)

* Ignore #EXT-X-INDEPENDENT-SEGMENTS so that it is not added to Fragment tagList

* Fix handling of the DATERANGE END-ON-NEXT attribute

* chore(deps): update dependency rollup to v4.7.0

* chore(deps): update dependency rollup to v4.9.0

* Store deployments in json file, and generate md and txt file from that (video-dev#6044)

* Fix deployment branch update commit messages

Just noticed this has been broken for a while

* Fix path to deployment readme script

* Fix path to script again

* Add the final `/` at the end of deployment url

* Remove tab at end of deployments readme

Which is causing the list to be really spaced out for some reason

* chore(deps): update dependency typescript to v5.3.3 (video-dev#5999)

* chore(deps): update dependency typescript to v5.3.3

* Include api extractor changes

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tom Jenkinson <[email protected]>

* Exclude PS4 from TextDecoder use

On PS4 TextDecoder is defined but it is partially implemented and does not function properly. This will force manual decoding approach for PS4 platform.

* Ignore #EXT-X-INDEPENDENT-SEGMENTS (video-dev#6047)

Fixes video-dev#6039

* chore(deps): update babel monorepo to v7.23.6

* chore(deps): update dependency prettier to v3.1.1

* chore(deps): update typescript-eslint monorepo to v6.14.0

* chore(deps): update typescript-eslint monorepo to v6.15.0

* chore(deps): update dependency wrangler to v3.20.0

* chore(deps): update dependency wrangler to v3.22.0

* Fix base-stream-controller onHandlerDestroying callback evocation
Remove circular references left after destroying player

* chore(deps): update dependency eslint-plugin-import to v2.29.1

* chore(deps): update dependency eslint to v8.56.0

* chore(deps): update dependency @svta/common-media-library to v0.6.1

* chore(deps): update dependency rollup to v4.9.1

* chore(deps): update dependency @microsoft/api-documenter to v7.23.15

* chore(deps): update dependency @microsoft/api-extractor to v7.39.0

* chore(deps): update dependency chromedriver to v120 (video-dev#6052)

* chore(deps): update github/codeql-action action to v3 (video-dev#6058)

* chore(deps): update dependency wrangler to v3.22.1

* Abort fetch loader as long as loading has not ended
Fixes video-dev#6054

* chore(deps): update dependency chromedriver to v120.0.1

* chore(deps): update typescript-eslint monorepo to v6.16.0

* chore(deps): update typescript-eslint monorepo to v6.17.0

* chore(deps): update babel monorepo to v7.23.7

* chore(deps): update dependency rollup to v4.9.2

* chore(deps): update dependency rollup to v4.9.4

* Fix codec parsing for AVC streams (video-dev#6077)

* Force auto level on emergency switch down (video-dev#6082)

Update estimates on frag load timeout
Do not abort request in _abandonRulesCheck
Remove two segment forward buffer length limit in _abandonRulesCheck
Reset estimate when candidate bitrate is lower than adjusted estimate
Resolves video-dev#6079

* chore(deps): update dependency wrangler to v3.22.2

* chore(deps): update dependency wrangler to v3.22.4

* chore(deps): update dependency @microsoft/api-documenter to v7.23.16

* chore(deps): update dependency @microsoft/api-extractor to v7.39.1

* Null CMCD callbacks on destroy (video-dev#6098)

* Fix regression where subtitle options with AUTOSELECT and FORCED are enabled at start (video-dev#6094)

* Do not enable subtitle options with AUTOSELECT=YES attribute
* Update and add initial selection tests for subtitle-controller
* Only pick forced subtitle option if it is the only one
Add default field to audio and subtitle selection options and forced field to subtitle selection option
* Address TextTrack change event overriding subtitle preference
Fix _TRACKS_UPDATED and _TRACK_SWITCH event order when preference is selected
* Do not auto select subtitle options with FORCED=YES attribute

* Update artifact actions (video-dev#6099)

* Update functional tests to run on Safari using MacOS 13 (video-dev#6101)

* Update functional tests to run on Safari using MacOS 13

* Skip smooth switch test in Safari on streams with overlapping appends

* Omit VOD "ended" event tests with overlapping appends from Safari

* chore(deps): update dependency chai to v4.4.0

* chore(deps): update dependency chai to v4.4.1

* chore(deps): update typescript-eslint monorepo to v6.18.0

* chore(deps): update typescript-eslint monorepo to v6.18.1

* Use AAC SBR (HE-AAC) workaround on Pale Moon (video-dev#6111)

---------

Co-authored-by: hlsjs-ci <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Rob Walch <[email protected]>
Co-authored-by: Rob Walch <[email protected]>
Co-authored-by: Casey Occhialini <[email protected]>
Co-authored-by: Joey Ekstrom <[email protected]>
Co-authored-by: Tom Jenkinson <[email protected]>
Co-authored-by: Tom Jenkinson <[email protected]>
Co-authored-by: Evan Burton <[email protected]>
Co-authored-by: 曾智锋 <[email protected]>
Co-authored-by: Agajan Jumakuliyev <[email protected]>
Co-authored-by: Jakub Perżyło <[email protected]>
Co-authored-by: Pat Nafarrete <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants