Commit 878ce18
committed
Handle negative ctts sample_offset values in mp4 parsing
Summary:
Some encodings like H.264 and H.265 support negative offsets.
We cannot rely on the version field since some encoders incorrectly set
ctts version to 0 instead of 1 even when using signed offsets.
Leigitimate positive values are relatively small so we can assume the value is signed.
The unsigned to signed conversion could have been gated based on the encoding. However I chose not to since large positive values exceeding 2^31 is unrealistic.
For reference the stsd and ctts boxes from a video:
stsd box: Container:
size = 233
type = b'stsd' (total 4)
data = Container:
version = 0
flags = 0
entries = ListContainer:
Container:
format = b'hvc1' (total 4)
ctts box Container:
size = 128480
type = b'ctts' (total 4)
data = Container:
version = 0
flags = 0
entries = ListContainer:
Container:
sample_count = 1
sample_offset = 0
Container:
sample_count = 1
sample_offset = 60
Container:
sample_count = 1
sample_offset = 0
Container:
sample_count = 1
sample_offset = 4294967256
Container:
sample_count = 1
sample_offset = 42949672761 parent ceca21d commit 878ce18
File tree
3 files changed
+28
-1
lines changed- mapillary_tools/mp4
- tests
- data/videos
- unit
3 files changed
+28
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
10 | 18 | | |
11 | 19 | | |
12 | 20 | | |
| |||
192 | 200 | | |
193 | 201 | | |
194 | 202 | | |
195 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
196 | 210 | | |
197 | 211 | | |
198 | 212 | | |
| |||
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
0 commit comments