Skip to content

🎥 Make videos programmatically with React

correctness and confidence regarding `description`

Jonny Burger5658f845adeb
diff --git a/packages/media-parser/src/add-avc-profile-to-track.ts b/packages/media-parser/src/add-avc-profile-to-track.ts
index c4ef9432cb..33de87771a 100644
--- a/packages/media-parser/src/add-avc-profile-to-track.ts
+++ b/packages/media-parser/src/add-avc-profile-to-track.ts
@@ -15,5 +15,13 @@ export const addAvcProfileToTrack = (
...track,
codec: getCodecStringFromSpsAndPps(avc1Profile.sps),
codecPrivate: createSpsPpsData(avc1Profile),
+ // description should be undefined, since this signals to WebCodecs that
+ // the codec is in Annex B format, which is the case for AVI files
+ // https://www.w3.org/TR/webcodecs-avc-codec-registration/#videodecoderconfig-description
+
+ // ChatGPT 4.1: "Great question! The format of the H.264/AVC bitstream inside a ⁠.avi file is almost always in the "Annex B" format"
+ // (description is probably already undefined at this point, just writing this to be explicit)
+
+ description: undefined,
};
};
diff --git a/packages/media-parser/src/containers/transport-stream/handle-aac-packet.ts b/packages/media-parser/src/containers/transport-stream/handle-aac-packet.ts
index bb13b28635..7219809a73 100644
--- a/packages/media-parser/src/containers/transport-stream/handle-aac-packet.ts
+++ b/packages/media-parser/src/containers/transport-stream/handle-aac-packet.ts
@@ -65,7 +65,9 @@ export const handleAacPacket = async ({
codecEnum: 'aac',
codec: mapAudioObjectTypeToCodecString(audioObjectType),
// https://www.w3.org/TR/webcodecs-aac-codec-registration/
- description: undefined,
+ // WebCodecs spec says that description should be given for AAC format
+ // ChatGPT says that Transport Streams are always AAC, not ADTS
+ description: codecPrivate,
numberOfChannels: channelConfiguration,
sampleRate,
};
diff --git a/packages/media-parser/src/containers/transport-stream/handle-avc-packet.ts b/packages/media-parser/src/containers/transport-stream/handle-avc-packet.ts
index aeadf55b69..3eaa9d055e 100644
--- a/packages/media-parser/src/containers/transport-stream/handle-avc-packet.ts
+++ b/packages/media-parser/src/containers/transport-stream/handle-avc-packet.ts
@@ -62,6 +62,8 @@ export const handleAvcPacket = async ({
newOffset: startOffset,
});
+ const codecPrivate = createSpsPpsData(spsAndPps);
+
const track: Track = {
m3uStreamFormat: null,
rotation: 0,
@@ -69,7 +71,7 @@ export const handleAvcPacket = async ({
type: 'video',
timescale: MPEG_TIMESCALE,
codec: getCodecStringFromSpsAndPps(spsAndPps.sps),
- codecPrivate: createSpsPpsData(spsAndPps),
+ codecPrivate,
fps: null,
codedWidth: dimensions.width,
codedHeight: dimensions.height,
@@ -79,6 +81,9 @@ export const handleAvcPacket = async ({
displayAspectHeight: dimensions.height,
trakBox: null,
codecEnum: 'h264',
+ // ChatGPT: In a transport stream (⁠.ts), H.264 video is always stored in Annex B format
+ // WebCodecs spec says that description must be undefined for Annex B format
+ // https://www.w3.org/TR/webcodecs-avc-codec-registration/#videodecoderconfig-description
description: undefined,
sampleAspectRatio: {
denominator: sampleAspectRatio.height,
diff --git a/packages/media-parser/src/test/parse-m3u8.test.ts b/packages/media-parser/src/test/parse-m3u8.test.ts
index 85ce19bb1f..f793aebaf7 100644
--- a/packages/media-parser/src/test/parse-m3u8.test.ts
+++ b/packages/media-parser/src/test/parse-m3u8.test.ts
@@ -103,7 +103,7 @@ test('parse m3u8', async () => {
codec: 'mp4a.40.2',
codecPrivate: new Uint8Array([9, 144]),
codecEnum: 'aac',
- description: undefined,
+ description: new Uint8Array([9, 144]),
numberOfChannels: 2,
sampleRate: 48000,
timescale: 90000,
diff --git a/packages/media-parser/src/test/transportstream.test.ts b/packages/media-parser/src/test/transportstream.test.ts
index 4d2f5464c0..ef72fe3953 100644
--- a/packages/media-parser/src/test/transportstream.test.ts
+++ b/packages/media-parser/src/test/transportstream.test.ts
@@ -50,7 +50,7 @@ test('Transport stream', async () => {
timescale: 90000,
codecEnum: 'aac',
codec: 'mp4a.40.2',
- description: undefined,
+ description: new Uint8Array([9, 144]),
numberOfChannels: 2,
sampleRate: 48000,
});