1
1
mirror of https://github.com/wader/fq.git synced 2024-10-07 00:48:44 +03:00

mp4: mvhd,tkhd,mdhd,mehd: Add version 1 support

Also fix incorrect mehd decode
This commit is contained in:
Mattias Wadman 2022-05-09 21:38:40 +02:00
parent e2577ec9b5
commit 2e328180ae
3 changed files with 146 additions and 21 deletions

View File

@ -222,12 +222,22 @@ func init() {
})
},
"mvhd": func(_ *decodeContext, d *decode.D) {
d.FieldU8("version")
version := d.FieldU8("version")
d.FieldU24("flags")
d.FieldU32("creation_time", quicktimeEpoch)
d.FieldU32("modification_time", quicktimeEpoch)
d.FieldU32("time_scale")
d.FieldU32("duration")
switch version {
case 0:
d.FieldU32("creation_time", quicktimeEpoch)
d.FieldU32("modification_time", quicktimeEpoch)
d.FieldU32("time_scale")
d.FieldU32("duration")
case 1:
d.FieldU64("creation_time", quicktimeEpoch)
d.FieldU64("modification_time", quicktimeEpoch)
d.FieldU32("time_scale")
d.FieldU64("duration")
default:
return
}
d.FieldFP32("preferred_rate")
d.FieldFP16("preferred_volume")
d.FieldUTF8("reserved", 10)
@ -264,13 +274,25 @@ func init() {
},
"tref": decodeBoxes,
"tkhd": func(ctx *decodeContext, d *decode.D) {
d.FieldU8("version")
var trackID uint32
version := d.FieldU8("version")
d.FieldU24("flags")
d.FieldU32("creation_time", quicktimeEpoch)
d.FieldU32("modification_time", quicktimeEpoch)
trackID := uint32(d.FieldU32("track_id"))
d.FieldU32("reserved1")
d.FieldU32("duration")
switch version {
case 0:
d.FieldU32("creation_time", quicktimeEpoch)
d.FieldU32("modification_time", quicktimeEpoch)
trackID = uint32(d.FieldU32("track_id"))
d.FieldU32("reserved1")
d.FieldU32("duration")
case 1:
d.FieldU64("creation_time", quicktimeEpoch)
d.FieldU64("modification_time", quicktimeEpoch)
trackID = uint32(d.FieldU32("track_id"))
d.FieldU32("reserved1")
d.FieldU64("duration")
default:
return
}
d.FieldRawLen("reserved2", 8*8)
d.FieldU16("layer")
d.FieldU16("alternate_group")
@ -289,13 +311,23 @@ func init() {
},
"mdia": decodeBoxes,
"mdhd": func(_ *decodeContext, d *decode.D) {
d.FieldU8("version")
version := d.FieldU8("version")
d.FieldU24("flags")
// TODO: timestamps
d.FieldU32("creation_time", quicktimeEpoch)
d.FieldU32("modification_time", quicktimeEpoch)
d.FieldU32("time_scale")
d.FieldU32("duration")
switch version {
case 0:
d.FieldU32("creation_time", quicktimeEpoch)
d.FieldU32("modification_time", quicktimeEpoch)
d.FieldU32("time_scale")
d.FieldU32("duration")
case 1:
d.FieldU64("creation_time", quicktimeEpoch)
d.FieldU64("modification_time", quicktimeEpoch)
d.FieldU32("time_scale")
d.FieldU64("duration")
default:
return
}
d.FieldStrFn("language", decodeLang)
d.FieldU16("quality")
},
@ -997,12 +1029,13 @@ func init() {
d.FieldFormat("data", id3v2Format, nil)
},
"mehd": func(_ *decodeContext, d *decode.D) {
d.FieldU8("version")
flags := d.FieldU24("flags")
if flags&0b1 != 0 {
d.FieldU64("fragment_duration")
} else {
version := d.FieldU8("version")
d.FieldU24("flags")
switch version {
case 0:
d.FieldU32("fragment_duration")
case 1:
d.FieldU64("fragment_duration")
}
},
"pssh": func(_ *decodeContext, d *decode.D) {

Binary file not shown.

View File

@ -0,0 +1,92 @@
$ fq -d mp4 ddv mvhd-tkhd-mdhd-mehd-v1
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: mvhd-tkhd-mdhd-mehd-v1 (mp4) 0x0-0x137.7 (312)
| | | boxes[0:5]: 0x0-0x137.7 (312)
| | | [0]{}: box 0x0-0x17.7 (24)
0x000|00 00 00 18 |.... | size: 24 0x0-0x3.7 (4)
0x000| 66 74 79 70 | ftyp | type: "ftyp" (File type and compatibility) 0x4-0x7.7 (4)
0x000| 69 73 6d 6c | isml | major_brand: "isml" 0x8-0xb.7 (4)
0x000| 00 00 00 01| ....| minor_version: 1 0xc-0xf.7 (4)
| | | brands[0:2]: 0x10-0x17.7 (8)
0x010|70 69 66 66 |piff | [0]: "piff" brand (Protected Interoperable File Format) 0x10-0x13.7 (4)
0x010| 69 73 6f 32 | iso2 | [1]: "iso2" brand (All files based on the 2004 edition of the ISO file format) 0x14-0x17.7 (4)
| | | [1]{}: box 0x18-0x8f.7 (120)
0x010| 00 00 00 78 | ...x | size: 120 0x18-0x1b.7 (4)
0x010| 6d 76 68 64| mvhd| type: "mvhd" (Movie header, overall declarations) 0x1c-0x1f.7 (4)
0x020|01 |. | version: 1 0x20-0x20.7 (1)
0x020| 00 00 00 | ... | flags: 0 0x21-0x23.7 (3)
0x020| 00 00 00 00 62 79 64 94 | ....byd. | creation_time: 1652122772 (1956-05-11T18:59:32Z) 0x24-0x2b.7 (8)
0x020| 00 00 00 00| ....| modification_time: 1652122772 (1956-05-11T18:59:32Z) 0x2c-0x33.7 (8)
0x030|62 79 64 94 |byd. |
0x030| 00 98 96 80 | .... | time_scale: 10000000 0x34-0x37.7 (4)
0x030| 00 00 00 06 2c e9 8a ab| ....,...| duration: 26523306667 0x38-0x3f.7 (8)
0x040|00 01 00 00 |.... | preferred_rate: 1 0x40-0x43.7 (4)
0x040| 01 00 | .. | preferred_volume: 1 0x44-0x45.7 (2)
0x040| 00 00 00 00 00 00 00 00 00 00| ..........| reserved: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 0x46-0x4f.7 (10)
| | | matrix_structure{}: 0x50-0x73.7 (36)
0x050|00 01 00 00 |.... | a: 1 0x50-0x53.7 (4)
0x050| 00 00 00 00 | .... | b: 0 0x54-0x57.7 (4)
0x050| 00 00 00 00 | .... | u: 0 0x58-0x5b.7 (4)
0x050| 00 00 00 00| ....| c: 0 0x5c-0x5f.7 (4)
0x060|00 01 00 00 |.... | d: 1 0x60-0x63.7 (4)
0x060| 00 00 00 00 | .... | v: 0 0x64-0x67.7 (4)
0x060| 00 00 00 00 | .... | x: 0 0x68-0x6b.7 (4)
0x060| 00 00 00 00| ....| y: 0 0x6c-0x6f.7 (4)
0x070|40 00 00 00 |@... | w: 1 0x70-0x73.7 (4)
0x070| 00 00 00 00 | .... | preview_time: 0 0x74-0x77.7 (4)
0x070| 00 00 00 00 | .... | preview_duration: 0 0x78-0x7b.7 (4)
0x070| 00 00 00 00| ....| poster_time: 0 0x7c-0x7f.7 (4)
0x080|00 00 00 00 |.... | selection_time: 0 0x80-0x83.7 (4)
0x080| 00 00 00 00 | .... | selection_duration: 0 0x84-0x87.7 (4)
0x080| 00 00 00 00 | .... | current_time: 0 0x88-0x8b.7 (4)
0x080| ff ff ff ff| ....| next_track_id: 4294967295 0x8c-0x8f.7 (4)
| | | [2]{}: box 0x90-0xf7.7 (104)
0x090|00 00 00 68 |...h | size: 104 0x90-0x93.7 (4)
0x090| 74 6b 68 64 | tkhd | type: "tkhd" (Track header, overall information about the track) 0x94-0x97.7 (4)
0x090| 01 | . | version: 1 0x98-0x98.7 (1)
0x090| 00 00 07 | ... | flags: 7 0x99-0x9b.7 (3)
0x090| 00 00 00 00| ....| creation_time: 1652122772 (1956-05-11T18:59:32Z) 0x9c-0xa3.7 (8)
0x0a0|62 79 64 94 |byd. |
0x0a0| 00 00 00 00 62 79 64 94 | ....byd. | modification_time: 1652122772 (1956-05-11T18:59:32Z) 0xa4-0xab.7 (8)
0x0a0| 00 00 00 01| ....| track_id: 1 0xac-0xaf.7 (4)
0x0b0|00 00 00 00 |.... | reserved1: 0 0xb0-0xb3.7 (4)
0x0b0| 00 00 00 06 2c e9 8a ab | ....,... | duration: 26523306667 0xb4-0xbb.7 (8)
0x0b0| 00 00 00 00| ....| reserved2: raw bits 0xbc-0xc3.7 (8)
0x0c0|00 00 00 00 |.... |
0x0c0| 00 00 | .. | layer: 0 0xc4-0xc5.7 (2)
0x0c0| 00 00 | .. | alternate_group: 0 0xc6-0xc7.7 (2)
0x0c0| 00 00 | .. | volume: 0 0xc8-0xc9.7 (2)
0x0c0| 00 00 | .. | reserved3: 0 0xca-0xcb.7 (2)
| | | matrix_structure{}: 0xcc-0xef.7 (36)
0x0c0| 00 01 00 00| ....| a: 1 0xcc-0xcf.7 (4)
0x0d0|00 00 00 00 |.... | b: 0 0xd0-0xd3.7 (4)
0x0d0| 00 00 00 00 | .... | u: 0 0xd4-0xd7.7 (4)
0x0d0| 00 00 00 00 | .... | c: 0 0xd8-0xdb.7 (4)
0x0d0| 00 01 00 00| ....| d: 1 0xdc-0xdf.7 (4)
0x0e0|00 00 00 00 |.... | v: 0 0xe0-0xe3.7 (4)
0x0e0| 00 00 00 00 | .... | x: 0 0xe4-0xe7.7 (4)
0x0e0| 00 00 00 00 | .... | y: 0 0xe8-0xeb.7 (4)
0x0e0| 40 00 00 00| @...| w: 1 0xec-0xef.7 (4)
0x0f0|00 00 00 00 |.... | track_width: 0 0xf0-0xf3.7 (4)
0x0f0| 00 00 00 00 | .... | track_height: 0 0xf4-0xf7.7 (4)
| | | [3]{}: box 0xf8-0x123.7 (44)
0x0f0| 00 00 00 2c | ..., | size: 44 0xf8-0xfb.7 (4)
0x0f0| 6d 64 68 64| mdhd| type: "mdhd" (Media header, overall information about the media) 0xfc-0xff.7 (4)
0x100|01 |. | version: 1 0x100-0x100.7 (1)
0x100| 00 00 00 | ... | flags: 0 0x101-0x103.7 (3)
0x100| 00 00 00 00 62 79 64 94 | ....byd. | creation_time: 1652122772 (1956-05-11T18:59:32Z) 0x104-0x10b.7 (8)
0x100| 00 00 00 00| ....| modification_time: 1652122772 (1956-05-11T18:59:32Z) 0x10c-0x113.7 (8)
0x110|62 79 64 94 |byd. |
0x110| 00 98 96 80 | .... | time_scale: 10000000 0x114-0x117.7 (4)
0x110| 00 00 00 06 2c e9 8a ab| ....,...| duration: 26523306667 0x118-0x11f.7 (8)
0x120|4e e5 |N. | language: "swe" 0x120-0x121.7 (2)
0x120| 00 00 | .. | quality: 0 0x122-0x123.7 (2)
| | | [4]{}: box 0x124-0x137.7 (20)
0x120| 00 00 00 14 | .... | size: 20 0x124-0x127.7 (4)
0x120| 6d 65 68 64 | mehd | type: "mehd" (Movie extends header box) 0x128-0x12b.7 (4)
0x120| 01 | . | version: 1 0x12c-0x12c.7 (1)
0x120| 00 00 00| ...| flags: 0 0x12d-0x12f.7 (3)
0x130|00 00 00 06 2c e9 8a ab| |....,...| | fragment_duration: 26523306667 0x130-0x137.7 (8)
| | | tracks[0:1]: 0x138-NA (0)
| | | [0]{}: track 0x138-NA (0)
| | | id: 1 0x138-NA (0)
| | | samples[0:0]: 0x138-NA (0)