-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_decode_simple_test.go
More file actions
79 lines (69 loc) · 2.07 KB
/
Copy pathexample_decode_simple_test.go
File metadata and controls
79 lines (69 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package goav1_test
import (
"crypto/md5"
"encoding/hex"
"fmt"
"os"
"path/filepath"
av1 "github.com/thesyncim/goav1"
)
// ExampleDecodeIVF shows the simplest possible decode: hand a whole IVF stream
// to the one-shot DecodeIVF helper and get back independent, caller-owned frame
// copies. No scratch binding, no frame pool, no worker pool wiring -- the helper
// drives the same byte-exact public decode path internally.
func ExampleDecodeIVF() {
path := filepath.Join("internal", "av1", "testvector", "testdata",
"profiles", "profile1-444-8bit-64x64.ivf")
ivf, err := os.ReadFile(path)
if err != nil {
fmt.Println("read fixture:", err)
return
}
frames, err := av1.DecodeIVF(ivf)
if err != nil {
fmt.Println("decode:", err)
return
}
for i, f := range frames {
sum := md5.Sum(append(append(append([]byte(nil), f.Y...), f.U...), f.V...))
fmt.Printf("frame %d %dx%d md5=%s\n", i, f.Width, f.Height, hex.EncodeToString(sum[:]))
}
// Output:
// frame 0 64x64 md5=00211cdc8f799c808849c955a318a0f5
// frame 1 64x64 md5=397ff01920ff514bc611ab49d76371c1
// frame 2 64x64 md5=f8fbfb25a42da47a7adb71510de9b178
}
// ExampleDecoder_DecodeNext shows the streaming form: build a Decoder over the
// frame payloads and pull visible frames one payload at a time. The returned
// *Frame values alias a reused arena, so copy out anything that must outlive the
// next DecodeNext call -- here we hash each frame's bytes immediately.
func ExampleDecoder_DecodeNext() {
path := filepath.Join("internal", "av1", "testvector", "testdata",
"profiles", "profile1-444-8bit-64x64.ivf")
ivf, err := os.ReadFile(path)
if err != nil {
fmt.Println("read fixture:", err)
return
}
dec, err := av1.NewDecoderFromIVF(ivf, av1.WithWorkers(1))
if err != nil {
fmt.Println("new decoder:", err)
return
}
defer dec.Close()
var count int
for {
frames, ok, err := dec.DecodeNext()
if err != nil {
fmt.Println("decode next:", err)
return
}
if !ok {
break
}
count += len(frames)
}
fmt.Printf("decoded %d visible frames\n", count)
// Output:
// decoded 3 visible frames
}