5

I want to stream raw video from a Logitech C920 webcam and while both displaying and saving the video to file using GStreamer 1.0.

This works if I stream h264 encoded video from the camera (the camera provides hardware encoded h264), but it fails if I stream raw video from the camera. However, if I only display, or only save to file, streaming raw video works.

Why does it work with a h264 video stream but not with a raw video stream?

h264 encoded video stream from camera to BOTH display and file (WORKS):

gst-launch-1.0 -v v4l2src device=/dev/video0 \
    ! video/x-h264,width=640,height=480,framerate=15/1 ! tee name=t \
    t. ! queue ! h264parse ! avdec_h264 ! xvimagesink sync=false \
    t. ! queue ! h264parse ! matroskamux \
    ! filesink location='h264_dual.mkv' sync=false

raw video stream from camera to ONLY display (WORKS):

gst-launch-1.0 -v v4l2src device=/dev/video0 \
    ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \
    ! xvimagesink sync=false

raw video stream from camera to ONLY file (WORKS):

gst-launch-1.0 -v v4l2src device=/dev/video0 \
    ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \
    ! videoconvert ! x264enc ! matroskamux \
    ! filesink location='raw_single.mkv' sync=false

raw video stream from camera to BOTH display and file (FAILS):

gst-launch-1.0 -v v4l2src device=/dev/video0 \
    ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \
    ! tee name=t \
    t. ! queue ! xvimagesink sync=false \
    t. ! queue ! videoconvert ! x264enc ! h264parse ! matroskamux \
    ! filesink location='raw_dual.mkv' sync=false

The last command (raw video to both display and file) fails without any warnings or errors. The gst-launch terminal output is exactly the same as when only writing to file. The xvimage window appears and displays an image from the camera, but the image does not change (i.e. it is frozen). A zero bytes file appears too.

I have tried multiple versions of the above commands, but I think those are the minimal commands that can reproduce the problem.

Does anyone understand what I am doing wrong?

Jan Spurny
  • 5,219
  • 1
  • 33
  • 47
kalleknast
  • 301
  • 2
  • 3
  • 10
  • What happens when you set `GST_DEBUG=1` ? (or 2, or 3 if nothing relevant happens) – Jan Spurny Mar 25 '15 at 17:43
  • Nearly nothing. I originally tried these pipelines using the Python 3 bindings. Most of the time, with the debug threshold set to 3 or 4, the failing pipeline gave exactly the same output as the one working, where the video was only saved to file. But, once or twice, randomly I saw this message: `pausing after gst_pad_push() = unknown`. Only that. – kalleknast Mar 25 '15 at 20:32
  • `Redistribute latency...0:00:00.415216281 17527 0x7fa920 INFO GST_EVENT gstevent.c:1244:gst_event_new_latency: creating latency event 0:00:00.000000000 0:00:00.415251642 17527 0x7fa920 INFO bin gstbin.c:2502:gst_bin_do_latency_func: configured latency of 0:00:00.000000000 0:00:00.469577927 17527 0xa0a0a0 INFO v4l2src gstv4l2src.c:737:gst_v4l2src_create: sync to 0:00:00.133333332 out ts 0:00:00.294658824` – kalleknast Mar 25 '15 at 21:14
  • I tried again, and I cannot see the `gst_pad_push() = unknown` message anymore. Only with `GST_DEBUG=4` do I see anything at all. If I run the "only to file" command I see data about the timestamped buffers on the terminal as they are captured. If I run the "both display and file" command everything seems the same, apart from that only data from one buffer is printed and then it stops. No error or warning. The above comment shows the last three lines of output from the failing command. – kalleknast Mar 25 '15 at 21:26
  • you can try removing or replacing (with identity, or theoraenc, oggmux instead of h264..) elements from `filesink` branch and see if it starts "working" (i.e. no freezing). That way you can get some idea where it goes wrong. – Jan Spurny Mar 26 '15 at 10:58
  • Thanks Jan. It works nicely with both `theoraenc` and vp8enc (replacing `x264enc` and removing `h264parse`). – kalleknast Mar 26 '15 at 13:30
  • It works also with `x264enc tune=zerolatency`. – kalleknast Mar 26 '15 at 14:50
  • ok. Could you please make this into an answer (just "answer" your own question and accept it - since you found the solution yourself) - that way, anyone having the same problem will find it easier to see the solution. – Jan Spurny Mar 26 '15 at 15:27

1 Answers1

6

Streaming raw video from a webcam (not specific to C920) to both display and h.264 encoded file can be done. The x264enc property tune needs to be set to zerolatency.

h.264 example:

gst-launch-1.0 -v v4l2src device=/dev/video0 \ ! video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 \ ! tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! x264enc tune=zerolatency ! h264parse ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

Alternatively, one can skip h.264 altogether and encode to theora or vp8 instead.

theora example:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! \ video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 ! \ tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! theoraenc ! theoraparse ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

vp8 example:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! \ video/x-raw,format=YUY2,width=640,height=480,framerate=15/1 ! \ tee name=t t. ! queue ! xvimagesink sync=false t. ! queue ! \ videoconvert ! vp8enc ! \ matroskamux ! filesink location='raw_dual.mkv' sync=false

Thanks a lot to Jan Spurny and Tim.

kalleknast
  • 301
  • 2
  • 3
  • 10