Streaming videos using a webcam

Hey guys, I’m just wondering if it is the same steps posted in the Docs we should follow for Streaming videos when using a webcam instead of a camera module.

TL;DR: no, they’re different.

The meaty stuff is the same, though. You need to feed gstreamer a video stream and then sink it. Take a look at these posts: list of supported cameras (may be slightly outdated); Raspberry Pi Foundation docs on webcams (biased towards their product. But they have a point as using Raspberry Pi Camera will have video acceleration support right out of the box) and this answer how to actually stream video.

Well, My project consists on working with a webcam but i decided first to stream videos using a camera module by following the instruction given in Navio Docs I had no error but i couldn’t view the output.
i have some questions to ask:
First is there any command to know whether the camera(camera module) is detected or not!
and second is it a must to attach Navio (Navio +) when streaming videos?!!
and last question, the videos will be streamed on one of the control ground station, right!!
Thanks in advance

I.

raspivid -o vid.h264

That should create a 5 second video clip. If any error occur check your ribbon cable orienation.
You could also attach a TV via HDMI and check live feed.

First make sure that works, than try streaming as described in the Docs.

II

You dont need Navio to stream a video. Raspberry with camera module as transmitter and any Linux, Mac or Windows OS as receiver will do.

III

Streaming to Qgroundcontrol via port 5600 works out of the box.
If you just want the video use the commnands in the Docs for your OS, that will just open a box with your video stream.

I recommend Logitech c920 as webcam.

Hey, i sshed into my RPi and tried to stream the 5 seconds video and it worked, i was expecting the video to be shown on my LapTop screen but it was shown on RPi screen that is confusing me because we are using a headless OS. so if i want to stream the video on my LapTop i should run APM planner, Right!!? and when i tried to do what it is described in the Docs, I got no error but i couldn’t view the image. Here follows you can find the output:
On my RPi:

pi@navio:~ $ raspivid -n -w 1280 -h 720 -b 1000000 -fps 15 -t 0 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=10 pt=96 ! udpsink host=192.168.1.104 port=9000
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:src: caps = "video/x-h264\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ framerate\=\(fraction\)0/1\,\ parsed\=\(boolean\)true\,\ stream-format\=\(string\)avc\,\ alignment\=\(string\)au\,\ level\=\(string\)4\,\ profile\=\(string\)high\,\ codec_data\=\(buffer\)01640028ffe1000e27640028ac2b402802dd00f1226a01000528ee025cb0"
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0.GstPad:src: caps = "application/x-rtp\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)H264\,\ sprop-parameter-sets\=\(string\)\"J2QAKKwrQCgC3QDxImo\\\=\\\,KO4CXLA\\\=\"\,\ payload\=\(int\)96\,\ ssrc\=\(uint\)3076291006\,\ timestamp-offset\=\(uint\)2512908245\,\ seqnum-offset\=\(uint\)6553"
/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink: caps = "application/x-rtp\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)H264\,\ sprop-parameter-sets\=\(string\)\"J2QAKKwrQCgC3QDxImo\\\=\\\,KO4CXLA\\\=\"\,\ payload\=\(int\)96\,\ ssrc\=\(uint\)3076291006\,\ timestamp-offset\=\(uint\)2512908245\,\ seqnum-offset\=\(uint\)6553"
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0.GstPad:sink: caps = "video/x-h264\,\ width\=\(int\)1280\,\ height\=\(int\)720\,\ framerate\=\(fraction\)0/1\,\ parsed\=\(boolean\)true\,\ stream-format\=\(string\)avc\,\ alignment\=\(string\)au\,\ level\=\(string\)4\,\ profile\=\(string\)high\,\ codec_data\=\(buffer\)01640028ffe1000e27640028ac2b402802dd00f1226a01000528ee025cb0"
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0: timestamp = 2512908245
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0: seqnum = 6553
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock

the output of my LapTop:

rayane@rayane-Lenovo-G580:~$ gst-launch-1.0 -v udpsrc port=9000 caps=‘application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264’ ! rtph264depay ! avdec_h264 ! videoconvert ! ximagesink sync=f
Setting pipeline to PAUSED …
Pipeline is live and does not need PREROLL …
/GstPipeline:pipeline0/GstUDPSrc:udpsrc0.GstPad:src: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264
/GstPipeline:pipeline0/GstRtpH264Depay:rtph264depay0.GstPad:sink: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264
Setting pipeline to PLAYING …
New clock: GstSystemClock

@jakob.ruisinger can you tell me what i did wrong!!

well i changed raspivid -n to raspivid -t -1 i got the video streamed on my RPi that means the camera is working but when i tried to do what is written in Emlid Docs i couldn’t view the video on my Laptop nor on My RPi. Has anyone tried that before !! Please Help
and for my webcam (USB2.0 8.0 MEGAPIXEL PC CAMERA) i searched and i dont think it is supported

Ok, first try to ping your Laptop with

sudo ping 192.168.1.104

I assume that is your ip of your Laptop, as you are streaming to that ip.

If you get a response, enter

gst-launch-1.0 -v udpsrc port=9000 caps=“application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264” ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=f

in your Laptop.
I guess you use a Windows OS.

Then

raspivid -n -w 1280 -h 720 -b 1000000 -fps 15 -t 0 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=10 pt=96 ! udpsink host=192.168.1.104 port=9000

into your raspberry

One step after the other, first try to get the Pi Cam working, then try a webcam.

I did ping command and here it is the output:

rayane@rayane-Lenovo-G580:~$ ping 192.168.42.9
PING 192.168.42.9 (192.168.42.9) 56(84) bytes of data.
64 bytes from 192.168.42.9: icmp_seq=1 ttl=63 time=3.03 ms
64 bytes from 192.168.42.9: icmp_seq=2 ttl=63 time=3.59 ms
64 bytes from 192.168.42.9: icmp_seq=3 ttl=63 time=3.95 ms
64 bytes from 192.168.42.9: icmp_seq=4 ttl=63 time=1.95 ms

but after i did ping to check that my RPi is can communicate with my LapTop i got this:

pi@navio:~ $ sudo ping 192.168.1.104
PING 192.168.1.104 (192.168.1.104) 56(84) bytes of data.

does that mean that my computer can connect to The RPi but my RPi can’t do the same??
and I’m using Ubuntu 14.04 not windows
Any ideas!!

Well I’m no expert in networking, but it looks like you are on 2 different subnets.
Check your ip configuration on raspberry und Laptop and make sure both are on the same subnet.
That would be ip 192.168.1.104 subnet 255.255.255.0 for your Laptop
Raspberry would be 192.168.1.105 subnet 255.255.255.0 for example.

If those two different subnets are intended check your Routing table.

I got them both on the same subnet, I can ping from one to the other but when trying to stream the video i got this:

rayane@rayane-Lenovo-G580:~$ gst-launch-1.0 -v udpsrc port=9000 caps=‘application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264’ ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=f
Setting pipeline to PAUSED …
libva info: VA-API version 0.35.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: va_openDriver() returns -1
libva info: VA-API version 0.35.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: va_openDriver() returns -1
libva info: VA-API version 0.35.0
libva info: va_getDriverName() returns -1
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
Pipeline is live and does not need PREROLL …
/GstPipeline:pipeline0/GstUDPSrc:udpsrc0.GstPad:src: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264
/GstPipeline:pipeline0/GstRtpH264Depay:rtph264depay0.GstPad:sink: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264
Setting pipeline to PLAYING …
New clock: GstSystemClock
/GstPipeline:pipeline0/GstRtpH264Depay:rtph264depay0.GstPad:src: caps = video/x-h264, stream-format=(string)avc, alignment=(string)au, codec_data=(buffer)01640028ffe1000e27640028ac2b402802dd00f1226a01000528ee025cb0
/GstPipeline:pipeline0/avdec_h264:avdec_h264-0.GstPad:sink: caps = video/x-h264, stream-format=(string)avc, alignment=(string)au, codec_data=(buffer)01640028ffe1000e27640028ac2b402802dd00f1226a01000528ee025cb0
/GstPipeline:pipeline0/avdec_h264:avdec_h264-0.GstPad:src: caps = video/x-raw, format=(string)I420, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, framerate=(fraction)25/1
/GstPipeline:pipeline0/GstVideoConvert:videoconvert0.GstPad:src: caps = video/x-raw, format=(string)I420, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, framerate=(fraction)25/1
/GstPipeline:pipeline0/GstAutoVideoSink:autovideosink0.GstGhostPad:sink.GstProxyPad:proxypad0: caps = video/x-raw, format=(string)I420, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, colorimetry=(string)bt709, framerate=(fraction)25/1
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 151 (XVideo)
Minor opcode of failed request: 13 ()
Serial number of failed request: 31
Current serial number in output stream: 34

has anyone an idea whats going on!

Live streaming With Online Platforms:
A streaming platform does all the heavy lifting for you. You don’t have to worry about any coding or technical knowledge. There are plenty of free or paid streaming services that give you user-friendly tools to easily broadcast your webcam without the hassle of installing encoders or hosting it yourself. Go to a reputable search engine and search for “live stream platform.” The results will give you more than enough options to choose from.
Decide what you need from a platform. Do you want a huge audience, HD streaming, mobile compatibility, and an ad-free platform? Look for a paid service. Do you just need a basic stream for a small audience, and you don’t care about ads? Look for a free service.
If you decide you want a free platform, alter your search to “live stream platform for free.” Just remember there are far fewer free platforms than paid platforms.
You can try out different free platforms before you commit. Many paid platforms also have free trials you can take advantage of.
Popular services include: Ustream (paid, free trial), DaCast (paid),Livestream (free option, free trial), and Bambuser (free option).
Check Lenovo G580 Manual for more help.

How to push live feed from raspberry pi to a RTMP protocol to pull the stream somewhere else

Hi @Surya_Tj,

I’m afraid I can’t provide you with step-by-step instructions since we didn’t do such things.

However, I assume you should start by bringing up a web-server with an RTMP module on your Raspberry Pi. Then, you can also install any tool allowing you to convert and stream video from a camera to an RTMP server. For example, FFmpeg, which is available for Raspberry Pi as well.