-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffmpeg_utils.go
64 lines (56 loc) · 1.18 KB
/
ffmpeg_utils.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"bytes"
"context"
"fmt"
ffmpeg "github.com/u2takey/ffmpeg-go"
"os"
"sort"
)
type ImageProcessor struct {
ExpectedReceives int // how many byte arrays will be sent
Input chan ImageInput
endCtx context.CancelFunc
}
type ImageInput struct {
index int
bytes []byte
}
// processVideo listens for incoming
// image files and converts them into
// an mp4 file using FFMPEG.
func (b *ImageProcessor) processVideo() {
images := make([]ImageInput, b.ExpectedReceives)
received := 0
for {
if received == b.ExpectedReceives {
fmt.Println("got ", b.ExpectedReceives, " byte arrays")
break
}
select {
case input := <-b.Input:
images = append(images, input)
received++
}
}
sort.Slice(images, func(i, j int) bool {
return images[i].index > images[j].index
})
i := bytes.Buffer{}
for _, img := range images {
i.Write(img.bytes)
}
if ffmpeg.Input("pipe:").
Output("juliaSet.mp4", ffmpeg.KwArgs{
"c:v": "libx264",
"pix_fmt": "yuv420p",
}).
OverWriteOutput().
ErrorToStdOut().
WithInput(bytes.NewReader(i.Bytes())).
Run() != nil {
panic("error running FFMPEG")
}
fmt.Println("video generated!")
os.Exit(0)
}