Skip to content

Commit

Permalink
mp4,avi: Trim spaces for type
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Apr 9, 2024
1 parent 2f858b1 commit 1784c43
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 39 deletions.
20 changes: 10 additions & 10 deletions format/mp4/boxes.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var subTypeNames = scalar.StrMapDescription{
"subp": "Subpicture",
"text": "Text",
"tmcd": "Time Code",
"url ": "URL",
"url": "URL",
"vide": "Video Track",
}

Expand Down Expand Up @@ -101,7 +101,7 @@ var dataFormatNames = scalar.StrMapDescription{
"encs": "Encrypted Systems stream",
"enct": "Encrypted Text",
"encv": "Encrypted/protected video",
"fdp ": "File delivery hints",
"fdp": "File delivery hints",
"fLaC": "Fres Lossless Audio Codec",
"g719": "ITU-T Recommendation G.719 (2008)",
"g726": "ITU-T Recommendation G.726 (1990)",
Expand Down Expand Up @@ -138,13 +138,13 @@ var dataFormatNames = scalar.StrMapDescription{
"Opus": "Opus audio coding",
"pm2t": "Protected MPEG-2 Transport",
"prtp": "Protected RTP Reception",
"raw ": "Uncompressed audio",
"raw": "Uncompressed audio",
"resv": "Restricted Video",
"rm2t": "MPEG-2 Transport Reception",
"rrtp": "RTP reception",
"rsrp": "SRTP Reception",
"rtmd": "Real Time Metadata Sample Entry(XAVC Format)",
"rtp ": "RTP Hints",
"rtp": "RTP Hints",
"s263": "ITU H.263 video (3GPP format)",
"samr": "Narrowband AMR voice",
"sawb": "Wideband AMR voice",
Expand Down Expand Up @@ -248,7 +248,7 @@ func decodeSampleFlags(d *decode.D) {

func decodeBoxWithParentData(ctx *decodeContext, d *decode.D, parentData any, extraTypeMappers ...scalar.StrMapper) {
var dataSize uint64
typeMappers := []scalar.StrMapper{boxDescriptions}
typeMappers := []scalar.StrMapper{scalar.ActualTrimSpace, boxDescriptions}
if len(extraTypeMappers) > 0 {
typeMappers = append(typeMappers, extraTypeMappers...)
}
Expand Down Expand Up @@ -519,7 +519,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
d.FieldU8("version")
d.FieldU24("flags")
d.FieldUTF8NullFixedLen("component_type", 4)
subType := d.FieldUTF8("component_subtype", 4, subTypeNames, scalar.ActualTrimSpace)
subType := d.FieldUTF8("component_subtype", 4, scalar.ActualTrimSpace, subTypeNames)
d.FieldUTF8NullFixedLen("component_manufacturer", 4)
d.FieldU32("component_flags")
d.FieldU32("component_flags_mask")
Expand Down Expand Up @@ -559,12 +559,12 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
var drefURL string
d.FieldStructArrayLoop("boxes", "box", func() bool { return i < entryCount }, func(d *decode.D) {
size := d.FieldU32("size")
typ := d.FieldUTF8("type", 4)
typ := d.FieldUTF8("type", 4, scalar.ActualTrimSpace)
d.FieldU8("version")
d.FieldU24("flags")
dataSize := size - 12
switch typ {
case "url ":
case "url":
drefURL = d.FieldUTF8("data", int(dataSize))
default:
d.FieldRawLen("data", int64(dataSize*8))
Expand All @@ -589,7 +589,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
d.FieldArrayLoop("boxes", func() bool { return i < entryCount }, func(d *decode.D) {
d.FieldStruct("box", func(d *decode.D) {
size := d.FieldU32("size")
dataFormat := d.FieldUTF8("type", 4, dataFormatNames)
dataFormat := d.FieldUTF8("type", 4, dataFormatNames, scalar.ActualTrimSpace)
subType := ""
if t := ctx.currentTrack(); t != nil {
t.sampleDescriptions = append(t.sampleDescriptions, sampleDescription{
Expand Down Expand Up @@ -1242,7 +1242,7 @@ func decodeBox(ctx *decodeContext, d *decode.D, typ string) {
if !d.End() {
d.FieldUTF8Null("content_encoding")
}
case "uri ":
case "uri":
d.FieldUTF8Null("item_uri_type")
}
}
Expand Down
4 changes: 2 additions & 2 deletions format/mp4/brands.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var brandDescriptions = scalar.StrMapDescription{
"dv3b": "DMB AF extending dv3a with 3GPP timed text, DID, TVA, REL, IPMP",
"dvr1": "DVB RTP",
"dvt1": "DVB Transport Stream",
"dxo ": "DxO ONE camera",
"dxo": "DxO ONE camera",
"emsg": "Event message box present",
"F4A": "Audio for Adobe Flash Player 9+ (.F4A)",
"F4B": "Audio Book for Adobe Flash Player 9+ (.F4B)",
Expand Down Expand Up @@ -160,7 +160,7 @@ var brandDescriptions = scalar.StrMapDescription{
"pana": "Panasonic Digital Camera",
"piff": "Protected Interoperable File Format",
"pnvi": "Panasonic Video Intercom Video Intercom",
"qt ": "QuickTime",
"qt": "QuickTime",
"risx": "Representation Index Segment used to index MPEG-2 TS based Media Segments",
"ROSS": "Ross Video Ross",
"sdv": "SD Video",
Expand Down
8 changes: 4 additions & 4 deletions format/mp4/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var boxDescriptions = scalar.StrMapDescription{
"irot": "Image rotation imir image mirroring",
"ispe": "Image spatial extents",
"j2kH": "JPEG 2000 header item property",
"jP ": "JPEG 2000 Signature",
"jP": "JPEG 2000 Signature",
"jp2c": "JPEG 2000 contiguous codestream",
"jp2h": "Header",
"jp2i": "Intellectual property information",
Expand Down Expand Up @@ -174,7 +174,7 @@ var boxDescriptions = scalar.StrMapDescription{
"pssh": "Protection system specific header",
"ptle": "Partial Top Level Entry",
"reel": "Name of the tape reel",
"res ": "Grid resolution",
"res": "Grid resolution",
"resc": "Grid resolution at which the image was captured",
"resd": "Default grid resolution at which the image should be displayed",
"rinf": "Restricted scheme information box",
Expand Down Expand Up @@ -255,12 +255,12 @@ var boxDescriptions = scalar.StrMapDescription{
"UITS": "Unique Identifier Technology Solution",
"ulst": "A list of UUID’s",
"urat": "User 'star' rating of the media",
"url ": "A URL",
"url": "A URL",
"uuid": "User-extension box",
"vmhd": "Video media header, overall information (video track only)",
"vwdi": "Multiview Scene Information",
"wide": "Expansion space reservation",
"xml ": "XML container",
"xml": "XML container",
"yrrc": "Year when media was recorded",

// from https://wiki.multimedia.cx/index.php/FFmpeg_Metadata
Expand Down
5 changes: 3 additions & 2 deletions format/mp4/mp4.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"cmp"
"embed"
"fmt"
"strings"

"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
Expand Down Expand Up @@ -465,14 +466,14 @@ func mp4Decode(d *decode.D) any {
if size < 8 {
d.Fatalf("first box size too small < 8")
}
firstType := d.UTF8(4)
firstType := strings.TrimSpace(d.UTF8(4))
switch firstType {
case "styp", // mp4 segment
"ftyp", // mp4 file
"free", // seems to happen
"moov", // seems to happen
"pnot", // video preview file
"jP ": // JPEG 2000
"jP": // JPEG 2000
default:
d.Errorf("no styp, ftyp, free or moov box found")
}
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/aac.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ $ fq -d mp4 dv aac.mp4
| | | boxes[0:1]: 0x413-0x41f (12)
| | | [0]{}: box 0x413-0x41f (12)
0x410| 00 00 00 0c | .... | size: 12 0x413-0x417 (4)
0x410| 75 72 6c 20 | url | type: "url " 0x417-0x41b (4)
0x410| 75 72 6c 20 | url | type: "url" 0x417-0x41b (4)
0x410| 00 | . | version: 0 0x41b-0x41c (1)
0x410| 00 00 01 | ... | flags: 1 0x41c-0x41f (3)
| | | data: "" 0x41f-0x41f (0)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/av1.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ $ fq -d mp4 dv av1.mp4
| | | boxes[0:1]: 0x1345-0x1351 (12)
| | | [0]{}: box 0x1345-0x1351 (12)
0x1340| 00 00 00 0c | .... | size: 12 0x1345-0x1349 (4)
0x1340| 75 72 6c 20 | url | type: "url " 0x1349-0x134d (4)
0x1340| 75 72 6c 20 | url | type: "url" 0x1349-0x134d (4)
0x1340| 00 | . | version: 0 0x134d-0x134e (1)
0x1340| 00 00| ..| flags: 1 0x134e-0x1351 (3)
0x1350|01 |. |
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/avc.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ $ fq -d mp4 dv avc.mp4
| | | boxes[0:1]: 0xf06-0xf12 (12)
| | | [0]{}: box 0xf06-0xf12 (12)
0x00f00| 00 00 00 0c | .... | size: 12 0xf06-0xf0a (4)
0x00f00| 75 72 6c 20 | url | type: "url " 0xf0a-0xf0e (4)
0x00f00| 75 72 6c 20 | url | type: "url" 0xf0a-0xf0e (4)
0x00f00| 00 | . | version: 0 0xf0e-0xf0f (1)
0x00f00| 00| .| flags: 1 0xf0f-0xf12 (3)
0x00f10|00 01 |.. |
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/dash.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ $ fq -d mp4 dv dash_audio_init.mp4
| | | boxes[0:1]: 0x1fa-0x206 (12)
| | | [0]{}: box 0x1fa-0x206 (12)
0x1f0| 00 00 00 0c | .... | size: 12 0x1fa-0x1fe (4)
0x1f0| 75 72| ur| type: "url " 0x1fe-0x202 (4)
0x1f0| 75 72| ur| type: "url" 0x1fe-0x202 (4)
0x200|6c 20 |l |
0x200| 00 | . | version: 0 0x202-0x203 (1)
0x200| 00 00 01 | ... | flags: 1 0x203-0x206 (3)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/flac.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ $ fq -d mp4 dv flac.mp4
| | | boxes[0:1]: 0x40b-0x417 (12)
| | | [0]{}: box 0x40b-0x417 (12)
0x400| 00 00 00 0c | .... | size: 12 0x40b-0x40f (4)
0x400| 75| u| type: "url " 0x40f-0x413 (4)
0x400| 75| u| type: "url" 0x40f-0x413 (4)
0x410|72 6c 20 |rl |
0x410| 00 | . | version: 0 0x413-0x414 (1)
0x410| 00 00 01 | ... | flags: 1 0x414-0x417 (3)
Expand Down
4 changes: 2 additions & 2 deletions format/mp4/testdata/fragmented.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ $ fq -d mp4 dv fragmented.mp4
| | | boxes[0:1]: 0x185-0x191 (12)
| | | [0]{}: box 0x185-0x191 (12)
0x00180| 00 00 00 0c | .... | size: 12 0x185-0x189 (4)
0x00180| 75 72 6c 20 | url | type: "url " 0x189-0x18d (4)
0x00180| 75 72 6c 20 | url | type: "url" 0x189-0x18d (4)
0x00180| 00 | . | version: 0 0x18d-0x18e (1)
0x00180| 00 00| ..| flags: 1 0x18e-0x191 (3)
0x00190|01 |. |
Expand Down Expand Up @@ -402,7 +402,7 @@ $ fq -d mp4 dv fragmented.mp4
| | | [0]{}: box 0x36d-0x379 (12)
0x00360| 00 00 00| ...| size: 12 0x36d-0x371 (4)
0x00370|0c |. |
0x00370| 75 72 6c 20 | url | type: "url " 0x371-0x375 (4)
0x00370| 75 72 6c 20 | url | type: "url" 0x371-0x375 (4)
0x00370| 00 | . | version: 0 0x375-0x376 (1)
0x00370| 00 00 01 | ... | flags: 1 0x376-0x379 (3)
| | | data: "" 0x379-0x379 (0)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/hevc.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ $ fq -d mp4 dv hevc.mp4
| | | boxes[0:1]: 0xa06-0xa12 (12)
| | | [0]{}: box 0xa06-0xa12 (12)
0x0a00| 00 00 00 0c | .... | size: 12 0xa06-0xa0a (4)
0x0a00| 75 72 6c 20 | url | type: "url " 0xa0a-0xa0e (4)
0x0a00| 75 72 6c 20 | url | type: "url" 0xa0a-0xa0e (4)
0x0a00| 00 | . | version: 0 0xa0e-0xa0f (1)
0x0a00| 00| .| flags: 1 0xa0f-0xa12 (3)
0x0a10|00 01 |.. |
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/in24.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ $ fq dv in24.mp4
| | | boxes[0:1]: 0x2d9-0x2e5 (12)
| | | [0]{}: box 0x2d9-0x2e5 (12)
0x2d0| 00 00 00 0c | .... | size: 12 0x2d9-0x2dd (4)
0x2d0| 75 72 6c| url| type: "url " 0x2dd-0x2e1 (4)
0x2d0| 75 72 6c| url| type: "url" 0x2dd-0x2e1 (4)
0x2e0|20 | |
0x2e0| 00 | . | version: 0 0x2e1-0x2e2 (1)
0x2e0| 00 00 01 | ... | flags: 1 0x2e2-0x2e5 (3)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/lpcm.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ $ fq dv lpcm.mp4
| | | boxes[0:1]: 0x411-0x41d (12)
| | | [0]{}: box 0x411-0x41d (12)
0x410| 00 00 00 0c | .... | size: 12 0x411-0x415 (4)
0x410| 75 72 6c 20 | url | type: "url " 0x415-0x419 (4)
0x410| 75 72 6c 20 | url | type: "url" 0x415-0x419 (4)
0x410| 00 | . | version: 0 0x419-0x41a (1)
0x410| 00 00 01 | ... | flags: 1 0x41a-0x41d (3)
| | | data: "" 0x41d-0x41d (0)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/mp3.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ $ fq -d mp4 dv mp3.mp4
| | | [0]{}: box 0x41f-0x42b (12)
0x410| 00| .| size: 12 0x41f-0x423 (4)
0x420|00 00 0c |... |
0x420| 75 72 6c 20 | url | type: "url " 0x423-0x427 (4)
0x420| 75 72 6c 20 | url | type: "url" 0x423-0x427 (4)
0x420| 00 | . | version: 0 0x427-0x428 (1)
0x420| 00 00 01 | ... | flags: 1 0x428-0x42b (3)
| | | data: "" 0x42b-0x42b (0)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/mpeg2.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ $ fq -d mp4 dv mpeg2.mp4
| | | boxes[0:1]: 0x212b-0x2137 (12)
| | | [0]{}: box 0x212b-0x2137 (12)
0x2120| 00 00 00 0c | .... | size: 12 0x212b-0x212f (4)
0x2120| 75| u| type: "url " 0x212f-0x2133 (4)
0x2120| 75| u| type: "url" 0x212f-0x2133 (4)
0x2130|72 6c 20 |rl |
0x2130| 00 | . | version: 0 0x2133-0x2134 (1)
0x2130| 00 00 01 | ... | flags: 1 0x2134-0x2137 (3)
Expand Down
2 changes: 1 addition & 1 deletion format/mp4/testdata/opus.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ $ fq -d mp4 dv opus.mp4
| | | boxes[0:1]: 0x318-0x324 (12)
| | | [0]{}: box 0x318-0x324 (12)
0x310| 00 00 00 0c | .... | size: 12 0x318-0x31c (4)
0x310| 75 72 6c 20| url | type: "url " 0x31c-0x320 (4)
0x310| 75 72 6c 20| url | type: "url" 0x31c-0x320 (4)
0x320|00 |. | version: 0 0x320-0x321 (1)
0x320| 00 00 01 | ... | flags: 1 0x321-0x324 (3)
| | | data: "" 0x324-0x324 (0)
Expand Down
Loading

0 comments on commit 1784c43

Please sign in to comment.