Created
May 23, 2017 04:01
-
-
Save adg/d397269cc5f6618cc11da706de7e81fb to your computer and use it in GitHub Desktop.
decode webcam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"image/jpeg" | |
"io" | |
"log" | |
"mime/multipart" | |
"os/exec" | |
) | |
func main() { | |
cmd := exec.Command("ffmpeg", "-f", "avfoundation", "-pix_fmt", "0rgb", "-r", "30", "-i", "FaceTime", "-f", "mpjpeg", "-") | |
out, err := cmd.StdoutPipe() | |
if err != nil { | |
log.Fatal(err) | |
} | |
if err := cmd.Start(); err != nil { | |
log.Fatal(err) | |
} | |
mr := multipart.NewReader(out, "ffserver") | |
for { | |
p, err := mr.NextPart() | |
if err == io.EOF { | |
return | |
} | |
if err != nil { | |
log.Fatal(err) | |
} | |
m, err := jpeg.Decode(p) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("frame bounds", m.Bounds()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment