Skip to content

🎥 Make videos programmatically with React

only put color if they are not default

Jonny Burger3c4640f91efd
diff --git a/packages/media-parser/src/boxes/webm/color.ts b/packages/media-parser/src/boxes/webm/color.ts
index 3d5f79c7cc..5166820ef3 100644
--- a/packages/media-parser/src/boxes/webm/color.ts
+++ b/packages/media-parser/src/boxes/webm/color.ts
@@ -1,6 +1,7 @@
import type {VideoTrackColorParams} from '../../get-tracks';
+import {truthy} from '../../truthy';
import {makeMatroskaBytes} from './make-header';
-import type {ColourSegment} from './segments/all-segments';
+import type {ColourSegment, PossibleEbml} from './segments/all-segments';
import {
getMatrixCoefficientsSegment,
getPrimariesSegment,
@@ -105,39 +106,47 @@ export const makeMatroskaColorBytes = ({
return makeMatroskaBytes({
type: 'Colour',
minVintWidth: null,
- value: [
- {
- type: 'TransferCharacteristics',
- value: {
- value: transferChracteristicsValue,
- byteLength: null,
+ value: (
+ [
+ transferChracteristicsValue === 2
+ ? null
+ : {
+ type: 'TransferCharacteristics',
+ value: {
+ value: transferChracteristicsValue,
+ byteLength: null,
+ },
+ minVintWidth: null,
+ },
+ matrixCoefficientsValue === 2
+ ? null
+ : {
+ type: 'MatrixCoefficients' as const,
+ value: {
+ value: matrixCoefficientsValue,
+ byteLength: null,
+ },
+ minVintWidth: null,
+ },
+ primariesValue === 2
+ ? null
+ : {
+ type: 'Primaries',
+ value: {
+ value: primariesValue,
+ byteLength: null,
+ },
+ minVintWidth: null,
+ },
+ {
+ type: 'Range',
+ value: {
+ value: rangeValue,
+ byteLength: null,
+ },
+ minVintWidth: null,
},
- minVintWidth: null,
- },
- {
- type: 'MatrixCoefficients',
- value: {
- value: matrixCoefficientsValue,
- byteLength: null,
- },
- minVintWidth: null,
- },
- {
- type: 'Primaries',
- value: {
- value: primariesValue,
- byteLength: null,
- },
- minVintWidth: null,
- },
- {
- type: 'Range',
- value: {
- value: rangeValue,
- byteLength: null,
- },
- minVintWidth: null,
- },
- ],
+ ] as PossibleEbml[]
+ ).filter(truthy),
});
};
diff --git a/packages/media-parser/src/truthy.ts b/packages/media-parser/src/truthy.ts
new file mode 100644
index 0000000000..e186dc6277
--- /dev/null
+++ b/packages/media-parser/src/truthy.ts
@@ -0,0 +1,5 @@
+type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T; // from lodash
+
+export function truthy<T>(value: T): value is Truthy<T> {
+ return Boolean(value);
+}