diff --git a/Parser.go b/Parser.go index e10196d..d7616b9 100644 --- a/Parser.go +++ b/Parser.go @@ -26,6 +26,7 @@ import ( type Parser struct { reader io.Reader childBoxDefinitions map[string]map[string]BoxDefinition + IgnoreUnknownBoxes bool Content []any } @@ -119,7 +120,9 @@ func parseNextBox(parser *Parser, reader io.Reader, currentBoxType string, fileP box, err = boxTypeDefinition.Parser(parser, filePosition, boxHeaderSize, boxContentBytes) } else { logger.Println("unknown box type", boxType, "at", filePosition, "in", currentBoxType) - return nil, filePosition, false, errors.New("unknown box type " + boxType + " in " + currentBoxType) + if !parser.IgnoreUnknownBoxes { + return nil, filePosition, false, errors.New("unknown box type " + boxType + " in " + currentBoxType) + } } // check for box errors diff --git a/Parser_test.go b/Parser_test.go index 79a3d3b..6e91767 100644 --- a/Parser_test.go +++ b/Parser_test.go @@ -29,7 +29,7 @@ func TestMain(m *testing.M) { } func TestParser(t *testing.T) { - parser, err := testFile(t, "test/fmp4.mp4") + parser, err := testFile(t, "test/fmp4.mp4", false) if err != nil { t.Error(err) } @@ -46,7 +46,7 @@ func TestParser(t *testing.T) { } func TestParserFragmentedMP4Init(t *testing.T) { - _, err := testFile(t, "test/fmp4_init.mp4") + _, err := testFile(t, "test/fmp4_init.mp4", true) if err != nil { t.Error(err) } @@ -70,12 +70,12 @@ func validateFileType(t *testing.T, parser *Parser) { } func TestParserInvalidSampleCount(t *testing.T) { - if _, err := testFile(t, "test/fmp4-incorrect-sample-count.mp4"); err == nil { + if _, err := testFile(t, "test/fmp4-incorrect-sample-count.mp4", false); err == nil { t.Error("missing error of invalid sample count of track fragment run box") } } -func testFile(t *testing.T, filePath string) (*Parser, error) { +func testFile(t *testing.T, filePath string, allowIgnore bool) (*Parser, error) { // open test file file, err := os.Open(filePath) if err != nil { @@ -85,6 +85,7 @@ func testFile(t *testing.T, filePath string) (*Parser, error) { // create new parser parser := NewParser(file) + parser.IgnoreUnknownBoxes = allowIgnore err = parser.Parse() return parser, err }