Skip to content

Commit

Permalink
mp4: ctts v0 sample_offset seems to be signed in practice
Browse files Browse the repository at this point in the history
sample file from the wild has v0 as negatice offsets
ffmpeg mov.c ignored versions and always read as signed
  • Loading branch information
wader committed Dec 8, 2023
1 parent 11fc0f2 commit aadf26f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,10 +878,10 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
var i uint64
d.FieldStructArrayLoop("entries", "entry", func() bool { return i < entryCount }, func(d *decode.D) {
d.FieldS32("sample_count")
// ISO/IEC14496-12 says version 0 is unsigned and version 1 is signed
// in preactice it seems muxers write it as signed for both version
switch version {
case 0:
d.FieldU32("sample_offset")
case 1:
case 0, 1:
d.FieldS32("sample_offset")
}
i++
Expand Down
Binary file added format/mp4/testdata/ctts_v0_signed
Binary file not shown.
22 changes: 22 additions & 0 deletions format/mp4/testdata/ctts_v0_signed.fqtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$ fq -d mp4 -o force=true dv ctts_v0_signed
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: ctts_v0_signed (mp4) 0x0-0x30 (48)
| | | boxes[0:1]: 0x0-0x30 (48)
| | | [0]{}: box 0x0-0x30 (48)
0x00|00 00 00 30 |...0 | size: 48 0x0-0x4 (4)
0x00| 63 74 74 73 | ctts | type: "ctts" (Composition time to sample) 0x4-0x8 (4)
0x00| 00 | . | version: 0 0x8-0x9 (1)
0x00| 00 00 00 | ... | flags: 0 0x9-0xc (3)
0x00| 00 00 00 04| ....| entry_count: 4 0xc-0x10 (4)
| | | entries[0:4]: 0x10-0x30 (32)
| | | [0]{}: entry 0x10-0x18 (8)
0x10|00 00 00 01 |.... | sample_count: 1 0x10-0x14 (4)
0x10| 00 00 00 0a | .... | sample_offset: 10 0x14-0x18 (4)
| | | [1]{}: entry 0x18-0x20 (8)
0x10| 00 00 00 01 | .... | sample_count: 1 0x18-0x1c (4)
0x10| ff ff ff f6| ....| sample_offset: -10 0x1c-0x20 (4)
| | | [2]{}: entry 0x20-0x28 (8)
0x20|00 00 00 01 |.... | sample_count: 1 0x20-0x24 (4)
0x20| 00 00 00 0a | .... | sample_offset: 10 0x24-0x28 (4)
| | | [3]{}: entry 0x28-0x30 (8)
0x20| 00 00 00 01 | .... | sample_count: 1 0x28-0x2c (4)
0x20| ff ff ff f6| ....| sample_offset: -10 0x2c-0x30 (4)

0 comments on commit aadf26f

Please sign in to comment.