Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add decode motion jpeg #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions examples/http_mjpeg_streamer/webcam.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Example program that uses blakjack/webcam library
// for working with V4L2 devices.
// for working with V4L2 devices and JPEG stream.
package main

import (
Expand All @@ -23,6 +23,7 @@ import (
const (
V4L2_PIX_FMT_PJPG = 0x47504A50
V4L2_PIX_FMT_YUYV = 0x56595559
Motion_JPEG = 1196444237
)

type FrameSizes []webcam.FrameSize
Expand All @@ -46,6 +47,7 @@ func (slice FrameSizes) Swap(i, j int) {
var supportedFormats = map[webcam.PixelFormat]bool{
V4L2_PIX_FMT_PJPG: true,
V4L2_PIX_FMT_YUYV: true,
Motion_JPEG: true,
}

func main() {
Expand All @@ -70,7 +72,6 @@ func main() {
for _, s := range format_desc {
fmt.Fprintln(os.Stderr, s)
}

var format webcam.PixelFormat
FMT:
for f, s := range format_desc {
Expand Down Expand Up @@ -219,9 +220,16 @@ func encodeToImage(wc *webcam.Webcam, back chan struct{}, fi chan []byte, li cha

}
img = yuyv
case Motion_JPEG:
var err error
img, err = jpeg.Decode(bytes.NewBuffer(frame))
if err != nil {
log.Fatal("Error format jpeg: %v", err.Error)
}
default:
log.Fatal("invalid format ?")
}

//convert to jpeg
buf := &bytes.Buffer{}
if err := jpeg.Encode(buf, img, nil); err != nil {
Expand Down