forked from icza/mjpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
43 lines (34 loc) · 778 Bytes
/
example.go
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
/*
This example encodes all jpeg images (*.jpg) into an MJPEG movie file
(flying-gopher.avi). Images are added in alphabetical order, using FPS=2/sec.
*/
package main
import (
"fmt"
"io/ioutil"
"path/filepath"
"sort"
"github.com/icza/mjpeg"
)
func main() {
checkErr := func(err error) {
if err != nil {
panic(err)
}
}
outName := "flying-gopher.avi"
aw, err := mjpeg.New(outName, 144, 108, 2)
checkErr(err)
// Create a movie from images:
matches, err := filepath.Glob("*.jpg")
checkErr(err)
sort.Strings(matches)
fmt.Println("Found images:", matches)
for _, name := range matches {
data, err := ioutil.ReadFile(name)
checkErr(err)
checkErr(aw.AddFrame(data))
}
checkErr(aw.Close())
fmt.Printf("%s was written successfully.\n", outName)
}