ref: f8e5a16a06c337bafb54921804a90fe4229ea3e9
parent: 7c5bc841307a98bc95654b281bb442852ac210ee
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Jun 30 08:29:04 EDT 2020
wip
--- a/iso.c
+++ b/iso.c
@@ -45,6 +45,13 @@
u64int modification;
u64int duration;
u32int timescale;
+ }mdhd;
+
+ struct {
+ u64int creation;
+ u64int modification;
+ u64int duration;
+ u32int timescale;
u32int rate;
u32int matrix[9];
u32int nexttrack;
@@ -191,6 +198,7 @@
BoxStbl = 0x7374626cu,
BoxCtts = 0x63747473u,
BoxStsd = 0x73747364u,
+ BoxEsds = 0x65736473u,
BoxStts = 0x73747473u,
BoxStsc = 0x73747363u,
BoxStco = 0x7374636fu,
@@ -217,7 +225,7 @@
b->type == BoxMfhd || b->type == BoxTfhd || b->type == BoxTfdt || b->type == BoxTrun || \
b->type == BoxStsd || b->type == BoxStts || b->type == BoxStss || b->type == BoxTkhd || \
b->type == BoxElst || b->type == BoxStsc || b->type == BoxStco || b->type == BoxCo64 || \
- b->type == BoxStsz || b->type == BoxCtts \
+ b->type == BoxStsz || b->type == BoxCtts || b->type == BoxEsds \
)
#define eBread(sz, e) if(Bread(f, d, (sz)) != (sz)){ werrstr(e); goto err; }
@@ -279,6 +287,11 @@
for(i = 0; i < b->ftyp.ncompat; i++)
fprint(2, "\t%.*s%T", dind, ind, b->ftyp.compat[i]);
fprint(2, "\n");
+ }else if(b->type == BoxMdhd){
+ fprint(2, "\t%.*screation\t%zd\n", dind, ind, b->mdhd.creation);
+ fprint(2, "\t%.*smodification\t%zd\n", dind, ind, b->mdhd.modification);
+ fprint(2, "\t%.*stimescale\t%ud\n", dind, ind, b->mdhd.timescale);
+ fprint(2, "\t%.*sduration\t%zd\n", dind, ind, b->mdhd.duration);
}else if(b->type == BoxMvhd){
fprint(2, "\t%.*screation\t%zd\n", dind, ind, b->mvhd.creation);
fprint(2, "\t%.*smodification\t%zd\n", dind, ind, b->mvhd.modification);
@@ -459,8 +472,8 @@
}
if(t->video.format != 0){
fprint(2, "video: format=%T resolution=%dx%d\n", t->video.format, t->video.width, t->video.height);
- werrstr("video: unknown format %T", t->video.format);
- return -1;
+ //werrstr("video: unknown format %T", t->video.format);
+ //return -1;
}
Binit(&out, 1, OWRITE);
@@ -537,15 +550,17 @@
eBread(2+2+4*3 + 2+2 + 4+4 + 4 + 2 + 32, "SampleEntry: video");
b->stsd.video.width = bu16(d+16);
b->stsd.video.height = bu16(d+18);
+ n -= 2+2+4*3 + 2+2 + 4+4 + 4 + 2 + 32;
memmove(&track.video, &b->stsd.video, sizeof(Video));
}else if(track.handlertype == HandlerAudio){
b->stsd.audio.format = fmt;
- /* reserved+id, ver+rev+vendor, channels+bps, ?+?, sample rate */
+ /* ver+rev+vendor, channels+bps, ?+?, sample rate */
eBread(2+4+2 + 2+2 + 2+2 + 4, "SampleEntry: audio");
b->stsd.audio.channels = bu16(d+8);
b->stsd.audio.samplerate = bu32(d+16)>>16;
+ n -= 2+4+2 + 2+2 + 2+2 + 4;
memmove(&track.audio, &b->stsd.audio, sizeof(Audio));
/* FIXME do we care about the rest? */
@@ -553,7 +568,7 @@
fprint(2, "SampleEntry: unknown handler type %T\n", track.handlertype);
}
- return n - sizeof(d);
+ return n;
err:
return -1;
}
@@ -584,7 +599,8 @@
printbox(b);
}else if(b->type == BoxMoov || b->type == BoxMvex || b->type == BoxTrak ||
b->type == BoxMdia || b->type == BoxMinf || b->type == BoxStbl ||
- b->type == BoxMoof || b->type == BoxTraf || b->type == BoxEdts){
+ b->type == BoxMoof || b->type == BoxTraf || b->type == BoxEdts ||
+ b->type == BoxDinf){
printbox(b);
dind++;
for(;;){
@@ -600,6 +616,28 @@
memset(&track, 0, sizeof(track));
}
dind--;
+ }else if(b->type == BoxMdhd){
+ n = b->version == 0 ? 16 : 28;
+ eBread(n, "short read");
+ p = d;
+
+ b->mdhd.creation = bu32(p); p += 4;
+ if(b->version == 1){
+ b->mdhd.creation = b->mdhd.creation<<32 | bu32(p); p += 4;
+ }
+
+ b->mdhd.modification = bu32(p); p += 4;
+ if(b->version == 1){
+ b->mdhd.modification = b->mdhd.modification<<32 | bu32(p); p += 4;
+ }
+
+ b->mdhd.timescale = bu32(p); p += 4;
+
+ b->mdhd.duration = bu32(p); p += 4;
+ if(b->version == 1){
+ b->mdhd.duration = b->mdhd.duration<<32 | bu32(p);
+ }
+ printbox(b);
}else if(b->type == BoxMvhd){
n = b->version == 0 ? 96 : 108;
eBread(n, "short read");
@@ -716,19 +754,31 @@
}
}
printbox(b);
+ }else if(b->type == BoxEsds){
+ eBread(3, "es id");
+ fprint(2, "# es id: %ud\n# es flags: 0x%02x\n", bu16(d+1), d[3]);
+ printbox(b);
}else if(b->type == BoxStsd){
eBread(4, "entry_count");
b->stsd.entrycount = bu32(d);
- for(u = 0; u < b->stsd.entrycount; u++){
- eBread(4, "size");
- n = bu32(d);
- eBread(4, "format");
- Bseek(f, 6+2, 1); /* skip reserved+id */
- n -= 8 + 6+2;
- n = sampleentry(f, b, bu32(d), n);
- Bseek(f, n, 1);
- }
+ eBread(4, "size");
+ n = bu32(d);
+ eBread(4, "format");
+ Bseek(f, 6+2, 1); /* skip reserved+id */
+ n -= 8 + 6+2;
+ n = sampleentry(f, b, bu32(d), n);
printbox(b);
+
+ dind += 2;
+ for(; n > 0;){
+ memset(&inner, 0, sizeof(inner));
+ if(parsebox(f, &inner, &eof) != 0)
+ goto err;
+ Bseek(f, inner.dstart+inner.dsz, 0);
+ if(inner.dstart+inner.dsz >= b->dstart+b->dsz)
+ break;
+ }
+ dind -= 2;
}else if(b->type == BoxStts){
eBread(4, "entry_count");
b->stts.entrycount = bu32(d);