joy4 icon indicating copy to clipboard operation
joy4 copied to clipboard

Get the one frame from the stream

Open sttyru opened this issue 6 years ago • 3 comments

Hello!

Thank you for awesome library!

I have a trivial question, maybe. I want to write very easy monitoring tool for IP-cameras (above 50 devices). The main criteria of avalability of devices is an ability of getting an image. I mean that I need more than simple check by ICMP or TCP/UDP. In this case I want to fetch (programmly) of the frame and checking that this image is non-empty, e.g. Can I do that using of your library? I found sources of RTSP-client software but I don't know how fetch the frame.

sttyru avatar Apr 26 '18 13:04 sttyru

@sttyru I do something like this:

  • Create a video decoder with the video stream decoder, err := ffmpeg.NewVideoDecoder(vstream)
  • Run the decoder setup decoder.Setup()
  • Read a packet with pkt, err := demuxer.ReadPacket()
  • Decode the packet to a frame frame, err := decoder.Decode(pkt.Data)
  • Free the memory after the function ends
if err != nil {
    return err
}
defer frame.Free()
  • Now you can access the image with frame.Image
func encodeImg(img image.Image) bytes.Buffer {
	var b bytes.Buffer
	jpeg.Encode(&b, img, nil)
        return b
}

jpegImg := encodeImg(frame.Image)

thenrich avatar Apr 30 '18 20:04 thenrich

@thenrich, very thank you!

sttyru avatar May 07 '18 07:05 sttyru

As this issue is still open, I have one question: Does a packet only contain a single frame? If not, why does the video decoder only return one frame for a whole packet instead of, e.g., a channel or array of frames?

niklaskorz avatar Aug 08 '19 11:08 niklaskorz