Skip to content

Commit 6133ca6

Browse files
committed
It reads info from the correct section (it wasn't accurate enough)
1 parent dca212b commit 6133ca6

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44

55
## program written in [GO](https://golang.org)
66

7-
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.
7+
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.
88

99
It's partially based on one of the examples in the image/riff section (the read chunk,etc...).
1010

1111
i.e.:
1212

13-
vcodec file.avi DIV3 DX50 ...
13+
vcodec file.avi DIV3 DX50 ... (case insensitive)
1414

1515
It's quite useful when you want to re-encode with ffmpeg or others a bunch of files only if they use certain codecs
16+
17+
Reference (Even if I do need to study them a little more)
18+
19+
- [Microsoft AVI riff file refernce](https://docs.microsoft.com/it-it/windows/win32/directshow/avi-riff-file-reference)
20+
- [Microsoft bitmapinfoheader info](https://docs.microsoft.com/it-it/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader)
21+
- [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)

vcodec.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import (
1515
)
1616

1717
var exitValue = 0
18+
var codecList []string
1819

1920
func main() {
2021
flag.Parse()
2122
if len(flag.Args()) < 2 {
2223
fmt.Print("Usage: vcodec riff_file codec1 codec2 ...\ncodec name is case insensitive\n")
2324
os.Exit(2)
2425
}
26+
//the next step is to allow to load the codecList from a file, as an alternative
27+
codecList = flag.Args()[1:]
28+
2529
//A little trick to handle the "panic", os.Exit doesn't call deferred functions
2630
main2()
2731
fmt.Printf("Exit Value: %d\n", exitValue)
@@ -39,7 +43,7 @@ func main2() {
3943
if r := recover(); r != nil {
4044
fmt.Printf("Codec: %s\n", r)
4145
codec := fmt.Sprintf("%s", r)
42-
for _, v := range flag.Args()[1:] {
46+
for _, v := range codecList {
4347
if strings.EqualFold(codec, v) {
4448
exitValue = 1
4549
break
@@ -82,7 +86,18 @@ func scanriff(r *riff.Reader) error {
8286
return err
8387
}
8488
if string(b[0:4]) == "vids" {
85-
panic(string(b[4:8]))
89+
codec := string(b[4:8])
90+
chunkID, _, chunkData, err := r.Next()
91+
if err != nil {
92+
panic(codec)
93+
}
94+
if fmt.Sprintf("%s", chunkID) == "strf" {
95+
b, err = ioutil.ReadAll(chunkData)
96+
if err == nil {
97+
codec = string(b[16:20]) // this should be the right codec
98+
}
99+
}
100+
panic(codec)
86101
}
87102
}
88103
}

0 commit comments

Comments
 (0)