forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.go
87 lines (69 loc) · 1.52 KB
/
video.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
This example will connect to the Bebop and stream its video to a webpage
via ffserver. This requires you to have both ffmpeg and ffserver installed
on your computer.
In order to run this example you will first need to start ffserver with:
$ ffserver -f ff.conf
then in a separate terminal run this program:
$ go run video.go
You will then be able to view the video feed by navigatin to
http://localhost:8090/bebop.mjpeg in a web browser. *NOTE* firefox works
best for viewing the video feed.
*/
package main
import (
"fmt"
"io/ioutil"
"os/exec"
"time"
"gobot.io/x/gobot/platforms/parrot/bebop/client"
)
func main() {
bebop := client.New()
if err := bebop.Connect(); err != nil {
fmt.Println(err)
return
}
if err := bebop.VideoEnable(true); err != nil {
fmt.Println(err)
return
}
if err := bebop.VideoStreamMode(0); err != nil {
fmt.Println(err)
return
}
ffmpeg := exec.Command("ffmpeg", "-i", "pipe:0", "http://localhost:8090/bebop.ffm")
ffmpegErr, err := ffmpeg.StderrPipe()
if err != nil {
fmt.Println(err)
return
}
ffmpegIn, err := ffmpeg.StdinPipe()
if err != nil {
fmt.Println(err)
return
}
if err := ffmpeg.Start(); err != nil {
fmt.Println(err)
return
}
go func() {
for {
buf, err := ioutil.ReadAll(ffmpegErr)
if err != nil {
fmt.Println(err)
}
if len(buf) > 0 {
fmt.Println(string(buf))
}
}
}()
go func() {
for {
if _, err := ffmpegIn.Write(<-bebop.Video()); err != nil {
fmt.Println(err)
}
}
}()
time.Sleep(99 * time.Second)
}