1
1
mirror of https://github.com/wader/fq.git synced 2024-09-11 12:05:39 +03:00

Merge pull request #920 from wader/mov-avi-trim-space

mp4,avi: Trim spaces for type
This commit is contained in:
Mattias Wadman 2024-04-09 20:38:19 +02:00 committed by GitHub
commit 8d31040fd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 40 additions and 39 deletions

View File

@ -53,7 +53,7 @@ var subTypeNames = scalar.StrMapDescription{
"subp": "Subpicture",
"text": "Text",
"tmcd": "Time Code",
"url ": "URL",
"url": "URL",
"vide": "Video Track",
}
@ -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)",
@ -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",
@ -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...)
}
@ -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")
@ -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))
@ -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{
@ -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")
}
}

View File

@ -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)",
@ -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",

View File

@ -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",
@ -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",
@ -255,12 +255,12 @@ var boxDescriptions = scalar.StrMapDescription{
"UITS": "Unique Identifier Technology Solution",
"ulst": "A list of UUIDs",
"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

View File

@ -19,6 +19,7 @@ import (
"cmp"
"embed"
"fmt"
"strings"
"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
@ -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")
}

View File

@ -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)

View File

@ -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 |. |

View File

@ -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 |.. |

View File

@ -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)

View File

@ -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)

View File

@ -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 |. |
@ -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)

View File

@ -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 |.. |

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -182,7 +182,7 @@ $ fq dv png.mp4
| | | [0]{}: box 0x20e-0x21a (12)
0x200| 00 00| ..| size: 12 0x20e-0x212 (4)
0x210|00 0c |.. |
0x210| 75 72 6c 20 | url | type: "url " 0x212-0x216 (4)
0x210| 75 72 6c 20 | url | type: "url" 0x212-0x216 (4)
0x210| 00 | . | version: 0 0x216-0x217 (1)
0x210| 00 00 01 | ... | flags: 1 0x217-0x21a (3)
| | | data: "" 0x21a-0x21a (0)

View File

@ -144,7 +144,7 @@ $ fq dv png_no_hdlr.mp4
| | | boxes[0:1]: 0x17c-0x188 (12)
| | | [0]{}: box 0x17c-0x188 (12)
0x170| 00 00 00 0c| ....| size: 12 0x17c-0x180 (4)
0x180|75 72 6c 20 |url | type: "url " 0x180-0x184 (4)
0x180|75 72 6c 20 |url | type: "url" 0x180-0x184 (4)
0x180| 00 | . | version: 0 0x184-0x185 (1)
0x180| 00 00 01 | ... | flags: 1 0x185-0x188 (3)
| | | data: "" 0x188-0x188 (0)

View File

@ -174,7 +174,7 @@ $ fq -d mp4 'dv' stz2.mp4
| | | boxes[0:1]: 0x1aa-0x1b6 (12)
| | | [0]{}: box 0x1aa-0x1b6 (12)
0x1a0| 00 00 00 0c | .... | size: 12 0x1aa-0x1ae (4)
0x1a0| 75 72| ur| type: "url " 0x1ae-0x1b2 (4)
0x1a0| 75 72| ur| type: "url" 0x1ae-0x1b2 (4)
0x1b0|6c 20 |l |
0x1b0| 00 | . | version: 0 0x1b2-0x1b3 (1)
0x1b0| 00 00 01 | ... | flags: 1 0x1b3-0x1b6 (3)

View File

@ -180,7 +180,7 @@ $ fq -d mp4 dv vorbis.mp4
| | | [0]{}: box 0x35e-0x36a (12)
0x0350| 00 00| ..| size: 12 0x35e-0x362 (4)
0x0360|00 0c |.. |
0x0360| 75 72 6c 20 | url | type: "url " 0x362-0x366 (4)
0x0360| 75 72 6c 20 | url | type: "url" 0x362-0x366 (4)
0x0360| 00 | . | version: 0 0x366-0x367 (1)
0x0360| 00 00 01 | ... | flags: 1 0x367-0x36a (3)
| | | data: "" 0x36a-0x36a (0)

View File

@ -163,7 +163,7 @@ $ fq -d mp4 dv vp9.mp4
| | | boxes[0:1]: 0x16e9-0x16f5 (12)
| | | [0]{}: box 0x16e9-0x16f5 (12)
0x16e0| 00 00 00 0c | .... | size: 12 0x16e9-0x16ed (4)
0x16e0| 75 72 6c| url| type: "url " 0x16ed-0x16f1 (4)
0x16e0| 75 72 6c| url| type: "url" 0x16ed-0x16f1 (4)
0x16f0|20 | |
0x16f0| 00 | . | version: 0 0x16f1-0x16f2 (1)
0x16f0| 00 00 01 | ... | flags: 1 0x16f2-0x16f5 (3)

View File

@ -195,7 +195,7 @@ $ fq -d mp4 dv prores_frame.mov
| | | [0]{}: box 0x6dee-0x6dfa (12)
0x6de0| 00 00| ..| size: 12 0x6dee-0x6df2 (4)
0x6df0|00 0c |.. |
0x6df0| 75 72 6c 20 | url | type: "url " 0x6df2-0x6df6 (4)
0x6df0| 75 72 6c 20 | url | type: "url" 0x6df2-0x6df6 (4)
0x6df0| 00 | . | version: 0 0x6df6-0x6df7 (1)
0x6df0| 00 00 01 | ... | flags: 1 0x6df7-0x6dfa (3)
| | | data: "" 0x6dfa-0x6dfa (0)

View File

@ -59,7 +59,7 @@ var aviListTypeDescriptions = scalar.StrMapDescription{
"hdrl": "AVI main list",
"strl": "Stream list",
"movi": "Stream Data",
"rec ": "Chunk group",
"rec": "Chunk group",
}
const (
@ -245,7 +245,7 @@ func aviDecodeEx(d *decode.D, ai format.AVI_In, extendedChunk bool) {
return true, nil
case "LIST":
typ := d.FieldUTF8("type", 4, aviListTypeDescriptions)
typ := d.FieldUTF8("type", 4, scalar.ActualTrimSpace, aviListTypeDescriptions)
switch typ {
case "strl":
return true, &aviStream{}