Any USB camera connected to a machine running Ubuntu or Windows (from now on the SOURCE machine) can be used as a network camera that streams the video:
- over a wireless connection to a different computing unit that runs Dragonfly (from now on the CLIENT machine).
or - within the same machine that runs Dragonfly (this is helpful for example when it is needed to access a USB camera from Ubuntu installed on WSL).
PLEASE READ
- If you are interested in how to configure a USB camera directly connected to the Dragonfly machine please go to this page.
- If the 2 machines do not belong to the same local network then you will have to setup a port forwarding on the SOURCE machine! Otherwise the camera won’t be accessible!
On Ubuntu
1.1 – Install Gstreamer
We use Gstreamer to stream the video from the SOURCE machine. To install it, enter the following commands on your SOURCE machine:
sudo apt-get -y install libgstreamer1.0-dev
sudo apt-get -y install libgstreamer-plugins-base1.0-dev
sudo apt-get -y install gstreamer1.0-libav
sudo apt-get -y install gstreamer1.0-plugins-bad
sudo apt-get -y install gstreamer1.0-tools
sudo apt-get -y install gstreamer1.0-plugins-good
sudo apt-get -y install gstreamer1.0-plugins-ugly
sudo apt-get -y install gstreamer1.0-nice
1.2 – Activate the streaming
On the SOURCE machine:
- Connect the USB camera.
- Launch the following command to list all video devices picked up by Ubuntu in order to find the ID of the USB camera:
sudo apt-get install v4l-utils
v4l2-ctl --list-devicesWhy do you see 2 IDs for each camera?
There is a common bug on Ubuntu 18.04 where 2 indexes are displayed for each USB camera. When configuring the Camera source field inside the Configuration tab of the Dragonfly Web user interface, please use the first index of the two. - Launch one of the following commands to activate the video stream (ip_SOURCE is the local IP address of the SOURCE machine and port_SOURCE is the port number that you would like to assign to gstreamer on the SOURCE machine):
- MJPEG streaming – use this solution if the hardware does not allow live H264 encoding, or if H264 is not satisfying:
gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=30/1' ! decodebin name=dec ! queue ! videoconvert ! jpegenc ! queue ! multipartmux ! tcpserversink host=ip_SOURCE port=port_SOURCE
- H264 streaming – much lower bandwidth requirements than MJPEG, but requires live encoding and some CPUs might not be powerful enough.
gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=30/1' ! videoconvert ! x264enc tune=zerolatency byte-stream=true ! rtph264pay ! gdppay ! tcpserversink host=ip_SOURCE port=port_SOURCE sync=false
- H264 (accelerated) streaming – same as H264 streaming, but does not require a powerful CPU encoding. However, all platforms are not compatible. Raspberry Pi and Jetson Nano should work fine.
gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=30/1' ! videoconvert ! omxh264enc ! rtph264pay ! gdppay ! tcpserversink host=ip_SOURCE port=port_SOURCE sync=false
- MJPEG streaming – use this solution if the hardware does not allow live H264 encoding, or if H264 is not satisfying:
1.3 – Make the video stream available to Dragonfly
- Launch Dragonfly on the CLIENT machine.
- Click on the Configuration tab:
- Set the Camera source parameter to one of the following strings, depending on the type of streaming activated on the SOURCE machine (ip_SOURCE is the local IP of the SOURCE machine and port_SOURCE is the port number assigned to the gstreamer on the SOURCE machine):
- For MJPEG streaming:
gstreamer:tcpclientsrc host=ip_SOURCE port=port_SOURCE ! multipartdemux ! image/jpeg, framerate=30/1 ! jpegparse ! jpegdec ! videoconvert ! appsink sync=false
- For H264 streaming:
gstreamer:tcpclientsrc host=ip_SOURCE port=port_SOURCE ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! appsink sync=false
- For H264 (accelerated) streaming:
gstreamer:tcpclientsrc host=ip_SOURCE port=port_SOURCE ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! appsink sync=false
- For MJPEG streaming:
- Set the Camera source parameter to one of the following strings, depending on the type of streaming activated on the SOURCE machine (ip_SOURCE is the local IP of the SOURCE machine and port_SOURCE is the port number assigned to the gstreamer on the SOURCE machine):
- Click on Save and Restart.
On Windows
2.1 – Install Gstreamer
We use Gstreamer to stream the video from the SOURCE machine. To install it, enter the following commands on your SOURCE machine:
Download Gstreamer from this link:
Launch the setup, and during the installation process:
- select CUSTOM.
- click on “GStreamer 1.0” and choose “ENTIRE FEATURES WILL BE INSTALLED ON LOCAL DRIVE“.
- take note of the location where Gstreamer will be installed (e.g.
C:\gstreamer\
). You will need it later.
Add Gstreamer to the environment variables. To do so:
- Click on the Windows logo in the top left corner, start typing “Environment Variables” and then click the Edit the system environment variables link shown by Windows.
- Click Environment Variables.
- In the section System Variables:
- if the
Path
environment variable exists, select it, click Edit. - if the
Path
environment variable does not exist, clickNew
.
- if the
- In the Edit System Variable (or New System Variable) window, insert the path to the gstreamer binaries:
C:\gstreamer\1.0\mingw_x86_64\bin
- Click OK. Close all remaining windows by clicking OK.
2.2 – Activate the streaming
On the SOURCE machine:
- Connect the USB camera.
- In Search, start typing “Device Manager” and then click on it.
- Under the CAMERA area please take note of the name associated to the USB camera of interest (this will be your camera_name):
- Example: “HD USB Camera”
- Open the command prompt and type the following command to activate the video stream (ip_CLIENT is the local IP address assigned to the CLIENT machine and port_SOURCE is the port number that you would like to assign to gstreamer on the SOURCE machine):
gst-launch-1.0.exe -v ksvideosrc device-name="camera_name" ! "image/jpeg,width=640,height=480" ! rtpjpegpay ! udpsink host=ip_CLIENT port=port_SOURCE
2.3 – Make the video stream available to Dragonfly
- Launch Dragonfly on the CLIENT machine.
- Click on the Configuration tab:
- Set the Camera source parameter to the following string (port_SOURCE is the port number that is assigned to gstreamer on the SOURCE machine):
gstreamer:udpsrc port=port_SOURCE ! application/x-rtp, encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegparse ! jpegdec ! videoconvert ! appsink
- Set the Camera source parameter to the following string (port_SOURCE is the port number that is assigned to gstreamer on the SOURCE machine):
- Click on Save and Restart.