Skip to content

🎥 Make videos programmatically with React

fix dimensions and duration

Jonny Burger304815e38684
diff --git a/packages/media-parser/src/containers/avc/interpret-sps.ts b/packages/media-parser/src/containers/avc/interpret-sps.ts
index c461205a2f..3a287d53ea 100644
--- a/packages/media-parser/src/containers/avc/interpret-sps.ts
+++ b/packages/media-parser/src/containers/avc/interpret-sps.ts
@@ -10,9 +10,16 @@ export const getDimensionsFromSps = (sps: SpsInfo) => {
const height = sps.pic_height_in_map_units_minus1;
const width = sps.pic_width_in_mbs_minus1;
+ // https://stackoverflow.com/questions/12018535/get-the-width-height-of-the-video-from-h-264-nalu
return {
- height: (height + 1) * 16,
- width: (width + 1) * 16,
+ height:
+ (height + 1) * 16 -
+ (sps.frame_crop_bottom_offset ?? 0) * 2 -
+ (sps.frame_crop_top_offset ?? 0) * 2,
+ width:
+ (width + 1) * 16 -
+ (sps.frame_crop_right_offset ?? 0) * 2 -
+ (sps.frame_crop_left_offset ?? 0) * 2,
};
};
diff --git a/packages/media-parser/src/test/parse-m3u8.test.ts b/packages/media-parser/src/test/parse-m3u8.test.ts
index e496541430..0f1387cfaa 100644
--- a/packages/media-parser/src/test/parse-m3u8.test.ts
+++ b/packages/media-parser/src/test/parse-m3u8.test.ts
@@ -60,11 +60,10 @@ test('parse m3u8', async () => {
acknowledgeRemotionLicense: true,
});
- expect(durationInSeconds).toBe(6);
+ expect(durationInSeconds).toBe(5.06667);
expect(dimensions).toEqual({
- // TODO: Why not 1000x1000?
- width: 1008,
- height: 1008,
+ width: 1000,
+ height: 1000,
});
expect(tracks.videoTracks).toEqual([
{
@@ -76,8 +75,8 @@ test('parse m3u8', async () => {
227, 6, 50, 192, 1, 0, 4, 104, 234, 239, 44,
]),
codecWithoutConfig: 'h264',
- codedHeight: 1008,
- codedWidth: 1008,
+ codedHeight: 1000,
+ codedWidth: 1000,
color: {
matrixCoefficients: 'bt470bg',
transferCharacteristics: null,
@@ -85,10 +84,10 @@ test('parse m3u8', async () => {
fullRange: true,
},
description: undefined,
- displayAspectHeight: 1008,
- displayAspectWidth: 1008,
+ displayAspectHeight: 1000,
+ displayAspectWidth: 1000,
fps: null,
- height: 1008,
+ height: 1000,
rotation: 0,
sampleAspectRatio: {
denominator: 1,
@@ -97,7 +96,7 @@ test('parse m3u8', async () => {
timescale: 90000,
trackId: 256,
trakBox: null,
- width: 1008,
+ width: 1000,
},
]);
expect(tracks.audioTracks).toEqual([