You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"image/jpeg""os""github.com/pion/mediadevices""github.com/pion/mediadevices/pkg/prop"// This is required to register camera adapter
_ "github.com/pion/mediadevices/pkg/driver/camera"// Note: If you don't have a camera or your adapters are not supported,// you can always swap your adapters with our dummy adapters below.// _ "github.com/pion/mediadevices/pkg/driver/videotest"
)
funcmain() {
stream, _:=mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
Video: func(constraint*mediadevices.MediaTrackConstraints) {
// Query for ideal resolutionsconstraint.Width=prop.Int(600)
constraint.Height=prop.Int(400)
},
})
// Since track can represent audio as well, we need to cast it to // *mediadevices.VideoTrack to get video specific functionalitiestrack:=stream.GetVideoTracks()[0]
videoTrack:=track.(*mediadevices.VideoTrack)
defervideoTrack.Close()
// Create a new video reader to get the decoded frames. Release is used // to return the buffer to hold frame back to the source so that the buffer // can be reused for the next frames.videoReader:=videoTrack.NewReader(false)
frame, release, _:=videoReader.Read()
deferrelease()
// Since frame is the standard image.Image, it's compatible with Go standard // library. For example, capturing the first frame and store it as a jpeg image.output, _:=os.Create("frame.jpg")
jpeg.Encode(output, frame, nil)
}
Alright, I was able to figure it out. I am using the most recent Raspberry Pi OS so I had to enable the legacy camera (I probably should have noticed that by how old the benchmark is/using mmal). Not sure if most users would know that but might be nice to have that here. If most people would i guess this could be closed.
Your environment.
What did you do?
Tried running the example on the homepage:
than
What did you expect?
To capture a frame and save it.
What happened?
I tried a couple of other things but couldn't figure anything out on the raspberry pi
The text was updated successfully, but these errors were encountered: