-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(captions): parse in-band captions from fmp4 segments (#197)
* initial parsing out of NAL units * Fixing syntax error * Move caption parsing out into another file * Add parsing/probing of mp4 containers to get caption timing data * Added parsing out of sample table. Pushed captions onto CaptionStream * Cleaning up: - Move discardEmulationPreventionBytes to captionsParser - Cleanup functions in mp4Probe. - Now only parseEmbeddedCaptions is exported for captions - Now handles multiple traks and ignores non-video traks - Renamed functions: captionTracksFromInit -> parseInitForCaptionMetadata, captionTracksFromSegment -> parseSegmentForSamples, captionNals -> parseCaptionNals * Add troubleshooting guide * Parse through segment only once: - in probe.js, combined functions parseSegmentForSamples and parseCaptionNals. - Renamed parseSegmentForSamples -> parseCaptionNals. - linting fixes * Cleaning up in probe.js and created mp4/captions-parser.js: - Use existing timescale() method. - Only use video track timescales, parse the segment only once rather than for each video track. - Moving all caption parsing methods to new file captions-parser.js * In mp4/captions-parser.js: - Using parseTfdt instead of parseDecodeTime - Using parseHdlr instead of parseHandlerType - Using parseTfhd from mp4Inspector instead In mp4-inspector.js: - Added durationIsEmpty and defaultBaseIsMoof flag handling to parseTfhd * In mp4/captions-parser.js: - Parse samples from all truns - Use parseTrun instead of oldParseSamples * Renamed m2ts/captions-parser.js -> tools/cea708-parser.js * Sort samples and fail fast if no video traks * mp4/captions-parser.js: remove unused code and add comments tools/mp4-inspector.js: add comments to parse.trun * mp4-inspector: revert changes to nalParse m2ts/caption-stream.js, mp4/captions-parser.js, tools/cea708-parser.js, tools/mp4-inspector.js: clean up imports/exports * - Added a captions debugging page - Added a test content creation doc - Updated doc/captions.md with more information * Update docs * Adding a few starter tests: one with real content, another with generated content * Using only needed parts of real test segment. Using correct init test segment. * Fixing linting errors for test, expanding test a bit * Use a different segment that can be reduced in size more easily * Add a bit more to captions doc * Adding function contracts to: mp4/captions-parser.js * Use moved test util methods in caption-stream.test.js * Update test content doc to use a specific format * update test-content doc * Update test-content.md * Fail fast if video track doesn't have captions. Added sensible unit tests * captions-parser.js: Handle SEIs that match the last sample test/captions-parser.test.js: Made a more complex test out of generated test data * Update to captions-parser: - Return both the active streams and the captions from the caption-parser. - Update tests * Use the first video track found only * captions-parser: fixing bugs - making sure all sample properties have default values * Update test-content.md * CR comments: - corrections to test-content guide and troubleshooting guide - renamed cea708-parser -> caption-packet-parser * Captions-parser: - restructure to persist CaptionStream across segments - rework mapping of pts/dts for SEI packets - fix tests * Update test-content.md * Allow setting an init segment instead of parsing both init and segment each time * In captions-parser.js: modify parse's signature to take videoTrackIds and timescales * Use shift instead of splice * CaptionsParser -> CaptionParser
- Loading branch information
1 parent
6d7173e
commit 7ad13aa
Showing
16 changed files
with
13,611 additions
and
230 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Creating Test Content | ||
|
||
## Table of Contents | ||
|
||
- [CEA-608 Content](#creating-cea-608-content) | ||
|
||
## Creating CEA-608 Content | ||
|
||
- Use ffmpeg to create an MP4 file to start with: | ||
|
||
`ffmpeg -f lavfi -i testsrc=duration=300:size=1280x720:rate=30 -profile:v baseline -pix_fmt yuv420p output.mp4` (no audio) | ||
|
||
`ffmpeg -f lavfi -i testsrc=duration=300:size=1280x720:rate=30 -profile:v baseline -pix_fmt yuv420p -filter_complex "anoisesrc=d=300" output.mp4` (audio + video) | ||
|
||
This uses ffmpeg's built-in `testsrc` source which generates a test video pattern with a color and timestamp. For this example, we are using a duration of `300` seconds, a size of `1280x720` and a framerate of `30fps`. We also specify extra settings `profile` and `pix_fmt` to force the output to be encoded using `avc1.42C01F`. | ||
|
||
- Create an [srt file](#srt) with the captions you would like to see with their timestamps. | ||
|
||
- Use ffmpeg to convert `ouput.mp4` to a flv file: | ||
|
||
`ffmpeg -i output.mp4 -acodec copy -vcodec copy output.flv` | ||
|
||
- Use [libcaption](#libcaption) to embed the captions into the flv: | ||
|
||
`flv+srt output.flv captions.srt with-captions.flv` | ||
|
||
- Use ffmpeg to convert `with-captions.flv` to mp4 | ||
|
||
`ffmpeg -i with-captions.flv -acodec copy -vcodec copy with-captions.mp4` | ||
|
||
- Use [Bento4](#bento4) to convert the file into a FMP4 file: | ||
|
||
`bento4 mp4fragment with-captions.mp4 \ | ||
--verbosity 3 \ | ||
--fragment-duration 4000 \ | ||
--timescale 90000 \ | ||
with-captions-fragment.mf4` | ||
|
||
Then do *either* of the following: | ||
|
||
- Use [Bento4](#bento4) to split the file into an init segment and a fmp4 media segments: | ||
|
||
`bento4 mp4split --verbose \ | ||
--init-segment with-captions-init.mp4 \ | ||
--media-segment segs/with-captions-segment-%llu.m4s \ | ||
with-captions-fragment.mf4` | ||
|
||
- Use [Bento4](#bento4) to create a DASH manifest: | ||
|
||
`bento4 mp4dash -v \ | ||
--mpd-name=with-captions.mpd \ | ||
--init-segment=with-captions-init.mp4 \ | ||
--subtitles | ||
with-captions-fragment.mf4` | ||
|
||
This will create a DASH MPD and media segments in a new directory called `output`. | ||
|
||
|
||
[srt]: https://en.wikipedia.org/wiki/SubRip#SubRip_text_file_format | ||
[libcaption]: https://github.com/szatmary/libcaption | ||
[bento4]: https://www.bento4.com/documentation/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Troubleshooting Guide | ||
|
||
## Table of Contents | ||
- [608/708 Caption Parsing](caption-parsing) | ||
|
||
## 608/708 Caption Parsing | ||
|
||
**I have a stream with caption data in more than one field, but only captions from one field are being returned** | ||
|
||
You may want to confirm the SEI NAL units are constructed according to the CEA-608 or CEA-708 specification. Specifically: | ||
|
||
- that control codes/commands are doubled | ||
- control codes starting from 0x14, 0x20 and ending with 0x14, 0x2f in field 1 are replaced with 0x15, 0x20 to 0x15, 0x2f when used in field 2 | ||
- control codes starting from 0x1c, 0x20 and ending with 0x1c, 0x2f in field 1 are replaced with 0x1d, 0x20 to 0x1d, 0x2f when used in field 2 | ||
|
||
[caption-parsing]: /docs/troubleshooting.md#608/708-caption-parsing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.