mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-29 03:43:50 +02:00
Add read/write support for track disposition information
This commit is contained in:
@@ -44,7 +44,7 @@ import {
|
||||
Sample,
|
||||
} from './isobmff-muxer';
|
||||
import { parseOpusIdentificationHeader } from '../codec-data';
|
||||
import { MetadataTags, RichImageData } from '../tags';
|
||||
import { MetadataTags, RichImageData } from '../metadata';
|
||||
|
||||
export class IsobmffBoxWriter {
|
||||
private helper = new Uint8Array(8);
|
||||
@@ -421,7 +421,12 @@ export const tkhd = (
|
||||
matrix = IDENTITY_MATRIX;
|
||||
}
|
||||
|
||||
return fullBox('tkhd', +needsU64, 3, [
|
||||
let flags = 0x2; // Track in movie
|
||||
if (trackData.track.metadata.disposition?.default !== false) {
|
||||
flags |= 0x1; // Track enabled
|
||||
}
|
||||
|
||||
return fullBox('tkhd', +needsU64, flags, [
|
||||
u32OrU64(creationTime), // Creation time
|
||||
u32OrU64(creationTime), // Modification time
|
||||
u32(trackData.track.id), // Track ID
|
||||
|
||||
@@ -86,13 +86,13 @@ import {
|
||||
readU8,
|
||||
readAscii,
|
||||
} from '../reader';
|
||||
import { MetadataTags, RichImageData } from '../tags';
|
||||
import { DEFAULT_TRACK_DISPOSITION, MetadataTags, RichImageData, TrackDisposition } from '../metadata';
|
||||
|
||||
type InternalTrack = {
|
||||
id: number;
|
||||
demuxer: IsobmffDemuxer;
|
||||
inputTrack: InputTrack | null;
|
||||
isDefault: boolean;
|
||||
disposition: TrackDisposition;
|
||||
timescale: number;
|
||||
durationInMovieTimescale: number;
|
||||
durationInMediaTimescale: number;
|
||||
@@ -317,7 +317,7 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
this.readContiguousBoxes(this.moovSlice);
|
||||
|
||||
// Put default tracks first
|
||||
this.tracks.sort((a, b) => Number(b.isDefault) - Number(a.isDefault));
|
||||
this.tracks.sort((a, b) => Number(b.disposition.default) - Number(a.disposition.default));
|
||||
|
||||
for (const track of this.tracks) {
|
||||
// Modify the edit list offset based on the previous segment durations. They are in different
|
||||
@@ -655,7 +655,9 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
id: -1,
|
||||
demuxer: this,
|
||||
inputTrack: null,
|
||||
isDefault: false,
|
||||
disposition: {
|
||||
...DEFAULT_TRACK_DISPOSITION,
|
||||
},
|
||||
info: null,
|
||||
timescale: -1,
|
||||
durationInMovieTimescale: -1,
|
||||
@@ -703,7 +705,7 @@ export class IsobmffDemuxer extends Demuxer {
|
||||
// Spec says disabled tracks are to be treated like they don't exist, but in practice, they are treated
|
||||
// more like non-default tracks.
|
||||
const trackEnabled = !!(flags & 0x1);
|
||||
track.isDefault = trackEnabled;
|
||||
track.disposition.default = trackEnabled;
|
||||
|
||||
// Skip over creation & modification time to reach the track ID
|
||||
if (version === 0) {
|
||||
@@ -2350,6 +2352,10 @@ abstract class IsobmffTrackBacking implements InputTrackBacking {
|
||||
return this.internalTrack.timescale;
|
||||
}
|
||||
|
||||
getDisposition() {
|
||||
return this.internalTrack.disposition;
|
||||
}
|
||||
|
||||
async computeDuration() {
|
||||
const lastPacket = await this.getPacket(Infinity, { metadataOnly: true });
|
||||
return (lastPacket?.timestamp ?? 0) + (lastPacket?.duration ?? 0);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { RichImageData } from '../tags';
|
||||
import { RichImageData } from '../metadata';
|
||||
import { textDecoder } from '../misc';
|
||||
import { FileSlice, readAscii, readBytes, readI32Be, readU16Be, readU32Be, readU64Be, readU8 } from '../reader';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user