Search code examples
gstreamer

Gstreamer - how to capture a single frame from udp source


When I stream over udp and autovideosink on the client side (in this example both sender and receiver are on same host), all works fine, but when I try to filesink it and capture a single frame, all my attempts fail. The file been created, but it's empty.

Here is the source:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,framerate=30/1 ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.0 port=5000 -e -v

One of the non working clients:

$ gst-launch-1.0 udpsrc port=5000 num-buffers=1 ! application/x-rtp,encoding-name=JPEG! rtpjpegdepay ! jpegdec ! jpegenc ! filesink location=test.jpeg -e
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Got EOS from element "pipeline0".
Execution ended after 0:00:00.112594509
Setting pipeline to NULL ...
Freeing pipeline ...

How do I capture it?


Solution

  • You use snapshot parameters of jpegenc et remove num-buffers=1 from udpsrc https://gstreamer.freedesktop.org/documentation/jpeg/jpegenc.html?gi-language=c

    Is something like that work for you ?

    gst-launch-1.0 udpsrc port=5000 ! application/x-rtp,encoding-name=JPEG ! rtpjpegdepay ! jpegdec ! jpegenc snapshot=TRUE ! filesink location=test.jpeg