Skip to content

Commit

Permalink
It reads info from the correct section (it wasn't accurate enough)
Browse files Browse the repository at this point in the history
  • Loading branch information
squeeze69 committed Jun 21, 2021
1 parent dca212b commit 6133ca6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 17 additions & 2 deletions vcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import (
)

var exitValue = 0
var codecList []string

func main() {
flag.Parse()
if len(flag.Args()) < 2 {
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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 6133ca6

Please sign in to comment.