mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Fix cslg box for QuickTime compatibility
This commit is contained in:
+4
-1
@@ -61,9 +61,12 @@
|
|||||||
bitrate: 320000
|
bitrate: 320000
|
||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
|
video: {
|
||||||
|
//forceReencode: true
|
||||||
|
},
|
||||||
trim: {
|
trim: {
|
||||||
start: 0,
|
start: 0,
|
||||||
end: 20
|
end: 10
|
||||||
},
|
},
|
||||||
onProgress: (event) => {
|
onProgress: (event) => {
|
||||||
progress.value = event.completion;
|
progress.value = event.completion;
|
||||||
|
|||||||
@@ -162,12 +162,6 @@ const u64 = (value: number) => {
|
|||||||
return [bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]] as number[];
|
return [bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]] as number[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const i64 = (value: number) => {
|
|
||||||
view.setInt32(0, Math.floor(value / 2 ** 32), false);
|
|
||||||
view.setInt32(4, value, false);
|
|
||||||
return [bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]] as number[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const fixed_8_8 = (value: number) => {
|
const fixed_8_8 = (value: number) => {
|
||||||
view.setInt16(0, 2 ** 8 * value, false);
|
view.setInt16(0, 2 ** 8 * value, false);
|
||||||
return [bytes[0], bytes[1]] as number[];
|
return [bytes[0], bytes[1]] as number[];
|
||||||
@@ -968,11 +962,11 @@ export const stco = (trackData: IsobmffTrackData) => {
|
|||||||
* composition time offset will be grouped.
|
* composition time offset will be grouped.
|
||||||
*/
|
*/
|
||||||
export const ctts = (trackData: IsobmffTrackData) => {
|
export const ctts = (trackData: IsobmffTrackData) => {
|
||||||
return fullBox('ctts', 0, 0, [
|
return fullBox('ctts', 1, 0, [
|
||||||
u32(trackData.compositionTimeOffsetTable.length), // Number of entries
|
u32(trackData.compositionTimeOffsetTable.length), // Number of entries
|
||||||
trackData.compositionTimeOffsetTable.map(x => [ // Time-to-sample table
|
trackData.compositionTimeOffsetTable.map(x => [ // Time-to-sample table
|
||||||
u32(x.sampleCount), // Sample count
|
u32(x.sampleCount), // Sample count
|
||||||
u32(x.sampleCompositionTimeOffset), // Sample offset
|
i32(x.sampleCompositionTimeOffset), // Sample offset
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
@@ -997,18 +991,31 @@ export const cslg = (trackData: IsobmffTrackData) => {
|
|||||||
|
|
||||||
for (let i = 0; i < trackData.samples.length; i++) {
|
for (let i = 0; i < trackData.samples.length; i++) {
|
||||||
const sample = trackData.samples[i]!;
|
const sample = trackData.samples[i]!;
|
||||||
compositionStartTime = Math.min(compositionStartTime, sample.timestamp);
|
compositionStartTime = Math.min(
|
||||||
compositionEndTime = Math.max(compositionEndTime, sample.timestamp + sample.duration);
|
compositionStartTime,
|
||||||
|
intoTimescale(sample.timestamp, trackData.timescale),
|
||||||
|
);
|
||||||
|
compositionEndTime = Math.max(
|
||||||
|
compositionEndTime,
|
||||||
|
intoTimescale(sample.timestamp + sample.duration, trackData.timescale),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const compositionToDtsShift = Math.max(-leastDecodeToDisplayDelta, 0);
|
const compositionToDtsShift = Math.max(-leastDecodeToDisplayDelta, 0);
|
||||||
|
|
||||||
return fullBox('cslg', 1, 0, [
|
if (compositionEndTime >= 2 ** 31) {
|
||||||
i64(compositionToDtsShift), // Composition to DTS shift
|
// For very large files, the composition end time can't be represented in i32, so let's just scrap the box in
|
||||||
i64(leastDecodeToDisplayDelta), // Least decode to display delta
|
// that case. QuickTime fails to read the file if there's a cslg box with version 1, so that's sadly not an
|
||||||
i64(greatestDecodeToDisplayDelta), // Greatest decode to display delta
|
// option.
|
||||||
i64(compositionStartTime), // Composition start time
|
return null;
|
||||||
i64(compositionEndTime), // Composition end time
|
}
|
||||||
|
|
||||||
|
return fullBox('cslg', 0, 0, [
|
||||||
|
i32(compositionToDtsShift), // Composition to DTS shift
|
||||||
|
i32(leastDecodeToDisplayDelta), // Least decode to display delta
|
||||||
|
i32(greatestDecodeToDisplayDelta), // Greatest decode to display delta
|
||||||
|
i32(compositionStartTime), // Composition start time
|
||||||
|
i32(compositionEndTime), // Composition end time
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user