From 6133ca613e567be24e09b5da223cf4a67ad6d592 Mon Sep 17 00:00:00 2001 From: Marco su Acerrimo3 Date: Mon, 21 Jun 2021 02:28:06 +0200 Subject: [PATCH] It reads info from the correct section (it wasn't accurate enough) --- README.md | 10 ++++++++-- vcodec.go | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b1892c9..4d7634c 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,18 @@ ## program written in [GO](https://golang.org) -Scan a RIFF file for the "vids" section, then exit with an error level 1 if the video codec is listed on the command line. The "heavy lift" is made by the image/riff library. +Scan a RIFF file for the codec (vids in the strh and the structure in the following strf section), then exit with an error level 1 if the video codec is listed on the command line. The "heavy lift" is made by the image/riff library. It's partially based on one of the examples in the image/riff section (the read chunk,etc...). i.e.: -vcodec file.avi DIV3 DX50 ... +vcodec file.avi DIV3 DX50 ... (case insensitive) It's quite useful when you want to re-encode with ffmpeg or others a bunch of files only if they use certain codecs + +Reference (Even if I do need to study them a little more) + +- [Microsoft AVI riff file refernce](https://docs.microsoft.com/it-it/windows/win32/directshow/avi-riff-file-reference) +- [Microsoft bitmapinfoheader info](https://docs.microsoft.com/it-it/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader) +- [Alberta's University AVI format description](https://sites.ualberta.ca/dept/chemeng/AIX-43/share/man/info/C/a_doc_lib/ultimdia/ultiprgd/AVI.htm) diff --git a/vcodec.go b/vcodec.go index 9207b2c..15b3cf3 100644 --- a/vcodec.go +++ b/vcodec.go @@ -15,6 +15,7 @@ import ( ) var exitValue = 0 +var codecList []string func main() { flag.Parse() @@ -22,6 +23,9 @@ func main() { fmt.Print("Usage: vcodec riff_file codec1 codec2 ...\ncodec name is case insensitive\n") os.Exit(2) } + //the next step is to allow to load the codecList from a file, as an alternative + codecList = flag.Args()[1:] + //A little trick to handle the "panic", os.Exit doesn't call deferred functions main2() fmt.Printf("Exit Value: %d\n", exitValue) @@ -39,7 +43,7 @@ func main2() { if r := recover(); r != nil { fmt.Printf("Codec: %s\n", r) codec := fmt.Sprintf("%s", r) - for _, v := range flag.Args()[1:] { + for _, v := range codecList { if strings.EqualFold(codec, v) { exitValue = 1 break @@ -82,7 +86,18 @@ func scanriff(r *riff.Reader) error { return err } if string(b[0:4]) == "vids" { - panic(string(b[4:8])) + codec := string(b[4:8]) + chunkID, _, chunkData, err := r.Next() + if err != nil { + panic(codec) + } + if fmt.Sprintf("%s", chunkID) == "strf" { + b, err = ioutil.ReadAll(chunkData) + if err == nil { + codec = string(b[16:20]) // this should be the right codec + } + } + panic(codec) } } }