Skip to content

Commit

Permalink
feat: Add TS transmuxer (#5386)
Browse files Browse the repository at this point in the history
- Allow to have multiple transmuxers, but choose only the one that is
valid depending on whether it supports the codecs or not
- Supported codecs: AAC, AC-3, EC-3, H.264, MPEG/MP3
- It is prepared to allow more codecs in the future (HEVC/H.265) (no
muxed)
  • Loading branch information
avelad committed Aug 29, 2023
1 parent 7c2bfaa commit eec25b2
Show file tree
Hide file tree
Showing 41 changed files with 1,693 additions and 159 deletions.
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -283,10 +283,12 @@ Shaka Player supports:
- Raw MP3 to MP3 in MP4
- Raw AC-3 to AC-3 in MP4
- Raw EC-3 to EC-3 in MP4
- AAC in MPEG-2 TS to AAC in MP4,
with help from [mux.js][] v6.2.0+
- H.264 in MPEG-2 TS to H.264 in MP4,
with help from [mux.js][] v6.2.0+
- AAC in MPEG-2 TS to AAC in MP4
- AC-3 in MPEG-2 TS to AC-3 in MP4
- EC-3 in MPEG-2 TS to EC-3 in MP4
- MP3 in MPEG-2 TS to MP3 in MP4
- MP3 in MPEG-2 TS to raw MP3
- H.264 in MPEG-2 TS to H.264 in MP4
- Muxed AAC and H.264 in MPEG-2 TS to AAC and H.264 in MP4,
with help from [mux.js][] v6.2.0+

Expand Down
3 changes: 3 additions & 0 deletions build/types/transmuxer
Expand Up @@ -6,6 +6,9 @@
+../../lib/transmuxer/adts.js
+../../lib/transmuxer/ec3.js
+../../lib/transmuxer/ec3_transmuxer.js
+../../lib/transmuxer/h264.js
+../../lib/transmuxer/mp3_transmuxer.js
+../../lib/transmuxer/mpeg_audio.js
+../../lib/transmuxer/mpeg_ts_transmuxer.js
+../../lib/transmuxer/muxjs_transmuxer.js
+../../lib/transmuxer/ts_transmuxer.js
32 changes: 32 additions & 0 deletions externs/shaka/codecs.js
@@ -0,0 +1,32 @@
/**
* @typedef {{
* data: Uint8Array,
* packetLength: number,
* pts: ?number,
* dts: ?number
* }}
*
* @summary MPEG_PES.
* @property {Uint8Array} data
* @property {number} packetLength
* @property {?number} pts
* @property {?number} dts
*/
shaka.extern.MPEG_PES;


/**
* @typedef {{
* data: !Uint8Array,
* fullData: !Uint8Array,
* type: number,
* time: ?number
* }}
*
* @summary VideoNalu.
* @property {!Uint8Array} data
* @property {!Uint8Array} fullData
* @property {number} type
* @property {?number} time
*/
shaka.extern.VideoNalu;
3 changes: 3 additions & 0 deletions karma.conf.js
Expand Up @@ -242,7 +242,10 @@ module.exports = (config) => {
{pattern: 'test/test/assets/hls-raw-ec3/*', included: false},
{pattern: 'test/test/assets/hls-raw-mp3/*', included: false},
{pattern: 'test/test/assets/hls-ts-aac/*', included: false},
{pattern: 'test/test/assets/hls-ts-ac3/*', included: false},
{pattern: 'test/test/assets/hls-ts-ec3/*', included: false},
{pattern: 'test/test/assets/hls-ts-h264/*', included: false},
{pattern: 'test/test/assets/hls-ts-mp3/*', included: false},
{pattern: 'test/test/assets/hls-ts-muxed-aac-h264/*', included: false},
{pattern: 'dist/shaka-player.ui.js', included: false},
{pattern: 'dist/locales.js', included: false},
Expand Down
6 changes: 2 additions & 4 deletions lib/media/media_source_engine.js
Expand Up @@ -426,8 +426,7 @@ shaka.media.MediaSourceEngine = class {
shaka.util.MimeUtils.getFullTypeWithAllCodecs(
stream.mimeType, stream.codecs);
const TransmuxerEngine = shaka.transmuxer.TransmuxerEngine;
if (needTransmux &&
TransmuxerEngine.isSupported(mimeTypeWithAllCodecs, contentType)) {
if (needTransmux) {
const transmuxerPlugin =
TransmuxerEngine.findTransmuxer(mimeTypeWithAllCodecs);
if (transmuxerPlugin) {
Expand Down Expand Up @@ -1656,8 +1655,7 @@ shaka.media.MediaSourceEngine = class {
shaka.util.MimeUtils.getFullTypeWithAllCodecs(
stream.mimeType, stream.codecs);
const TransmuxerEngine = shaka.transmuxer.TransmuxerEngine;
if (needTransmux &&
TransmuxerEngine.isSupported(newMimeTypeWithAllCodecs, contentType)) {
if (needTransmux) {
const transmuxerPlugin =
TransmuxerEngine.findTransmuxer(newMimeTypeWithAllCodecs);
if (transmuxerPlugin) {
Expand Down
2 changes: 2 additions & 0 deletions lib/mss/mss_parser.js
Expand Up @@ -633,10 +633,12 @@ shaka.mss.MssParser = class {
}
/** @type {shaka.util.Mp4Generator.StreamInfo} */
const streamInfo = {
encrypted: stream.encrypted,
timescale: stream.mssPrivateData.timescale,
duration: stream.mssPrivateData.duration,
videoNalus: videoNalus,
audioConfig: new Uint8Array([]),
videoConfig: new Uint8Array([]),
data: null, // Data is not necessary for init segement.
stream: stream,
};
Expand Down
2 changes: 2 additions & 0 deletions lib/transmuxer/aac_transmuxer.js
Expand Up @@ -188,10 +188,12 @@ shaka.transmuxer.AacTransmuxer = class {

/** @type {shaka.util.Mp4Generator.StreamInfo} */
const streamInfo = {
encrypted: stream.encrypted && stream.drmInfos.length > 0,
timescale: sampleRate,
duration: duration,
videoNalus: [],
audioConfig: new Uint8Array([]),
videoConfig: new Uint8Array([]),
data: {
sequenceNumber: this.frameIndex_,
baseMediaDecodeTime: baseMediaDecodeTime,
Expand Down
2 changes: 2 additions & 0 deletions lib/transmuxer/ac3_transmuxer.js
Expand Up @@ -175,10 +175,12 @@ shaka.transmuxer.Ac3Transmuxer = class {

/** @type {shaka.util.Mp4Generator.StreamInfo} */
const streamInfo = {
encrypted: stream.encrypted && stream.drmInfos.length > 0,
timescale: sampleRate,
duration: duration,
videoNalus: [],
audioConfig: audioConfig,
videoConfig: new Uint8Array([]),
data: {
sequenceNumber: this.frameIndex_,
baseMediaDecodeTime: baseMediaDecodeTime,
Expand Down
2 changes: 2 additions & 0 deletions lib/transmuxer/ec3_transmuxer.js
Expand Up @@ -175,10 +175,12 @@ shaka.transmuxer.Ec3Transmuxer = class {

/** @type {shaka.util.Mp4Generator.StreamInfo} */
const streamInfo = {
encrypted: stream.encrypted && stream.drmInfos.length > 0,
timescale: sampleRate,
duration: duration,
videoNalus: [],
audioConfig: audioConfig,
videoConfig: new Uint8Array([]),
data: {
sequenceNumber: this.frameIndex_,
baseMediaDecodeTime: baseMediaDecodeTime,
Expand Down

0 comments on commit eec25b2

Please sign in to comment.