I want to use the webcam on my laptop as video device on my pc to use it for video conferencing etc.
So I not just want to stream the video. I actually want to "stream" the entire device over network.
So, two computers, one streams its webcam, the other picks it up as video device.
Both computes run normal Ubuntu 18.04 however I will soon upgrade to 20.04
Asuming both machines are connected in a network and the PC can reach the laptop's IP. Please follow these steps:
On the laptop
Install
v4l-utils
andffmpeg
by running:Install
matroska
media container like so:Run the following command to open a
netcat
listener for the camera stream:On the PC
Install
v4l-utils
andffmpeg
by running:Install
v4l2loopback
and load the virtual camera:Test it:
Laptop_IP
to the IP of the laptop ):If you can see your face, then it's working.
Microphone?
To send over the microphone output as well from the laptop to the PC, please follow these steps:
On the laptop:
On the pc:
The output will be something like this:
we will use device 1 ( this is usually the virtual microphone ) on card 1 like this
hw:1,1
Laptop_IP
to the IP of the laptop ):Test the microphone and be advised there will be sound latency because no compression is used.
Notice:
If the test fails, then it is probably because you have other camera devices virtual or otherwise present in your PC's
/dev
directory.To fix this, run
ls /dev/video*
and note how many are there. Then use the one with the greater number after it in the two commands in the test. This is done like so:Run
sudo modprobe -r v4l2loopback
Then run
ls /dev/video*
and note the existing cameras like/dev/video0 /dev/video1 /dev/video2 ... etc
Then run:
Then run again
ls /dev/video*
a new camera/dev/video3
will be added like so/dev/video0 /dev/video1 /dev/video2 /dev/video3
Use the new camera in the last two commands instead of
/dev/video0
like so:and
Troubleshooting:
To test if the stream is going through if you are having issues with
v4l2loopback
, you can run on the PC:or
or
To use it with Google Hangouts:
Thanks to @janjaromirhorak as indicated in this comment quoted below.
So you want to borrow the camera for another machine. May be late but this question seems to have solution.
The usual issue I see, most conference/chat apps does only support local camera devices (no network or local file streaming).
Your are missing only one piece:
v4l2loopback
gst-launch-1.0
), ffmpeg, vlc, ... to stream video from cam device to networkgst-launch-1.0
), ffmpeg, vlc, ... to receive and pipe video to theloopback deviceThen set conference/chat apps in Desktop(PC2) use the V4L2 loopback device created in step (1) as camera.
References:
vlc
Using vlc is one way to achieve this goal.
Step 1 - setup
To install VLC on Debian, Ubuntu or Linux Mint:
To install VLC on Fedora, first enable RPM Fusion's free repository, then run:
To install VLC on CentOS or RHEL 6, first set up EPEL repository, and then use the following commands:
Step 2 - Verify Webcam in VLC
Make sure your webcam is detected by your Linux system and VLC.
You’ll need to know the webcam’s name for that. In the example below, the webcam is named
/dev/video0
.Then you have to test video from your webcam. Here is the command you need to use, do not forget to replace "video0" with the name of your device.
If your webcam is successfully detected by VLC, you should be able to see your video stream.
Step 3 - Configure Webcam Streaming on VLC
You have successfully detected your webcam in VLC, next is configuring webcam streaming.
In this example webcam is streamed over HTTP in WMV format. To configure VLC for webcam streaming, first launch VLC.
In VLC menu choose "Streaming".
On the screen select your webcam’s or audio device’s name, e.g., /dev/video0 for webcam, and hw:0,0 for audio. Tick "Show more options" checkbox and make a note of value strings in "MRL" and "Edit Options" fields. These strings will be used later in the tutorial. Click "Stream" button.
Verify the video source, e.g., v4l2:///dev/video, and click "Next" to continue.
Choose the destination, i.e., streaming method/target, of webcam streaming. In our example we choose HTTP from the drop down list, and click "Add".
Next, specify port number and path of a streaming service. For port number, type 8080; we assume the port number is not occupied, for path - "/stream.wmv". For transcoding choose "Video - WMV + WMA (ASF)" profile from the drop down list. Click "Next".
The next screen displays automatically generated stream output string. Make a note of it and click "Stream" button.
At this point, VLC should start streaming video from your webcam over HTTP. Streaming traffic is sent directly to localhost at TCP port number 8080, so you won’t be able to see anything in the VLC window.
To verify that VLC is running correctly at TCP port 8080, run the following command, and look for VLC.
Step 4 - Watch Streaming Video from Webcam
Once a streaming server starts running, the webcam live feed is available at
http://:8080/stream.wmv
You can use VLC player or MPlayer to access the webcam feed as follows.
If you are testing the feed from the same host, use loopback address 127.0.0.1 instead.
If I understand correctly, you mean to have a video device on one computer getting the input from a physical device on another. Even if I do not have here the resources to test it, I guess it is possible. I remember some time ago doing something similar but not with video. According to this (also this; both old posts), video can also be done.
In summary
Solutions and comments in those posts use
dd
,ffmpeg
or netcat (nc
) to dump/stream video, andmplayer
orvlc
to see the tunneled video, and even piping withtee
.If you first try any of the solutions available in posts above, and report feedback, it would be a good starting point for moving ahead.
Creating a local device, to access it exactly as if the webcam were connected locally, was not tested. This (old post) suggests that using SSHFS might do the trick. YMMV, depending on what use you intend for the tunneled video.
References
Piping video device over SSH or tcptunnel?
Can I pipe /dev/video over ssh
Watching remote webcam over piping and SSH?
SSHFS
You could try to use DroidCam. I do not have PC with laptop in the one place, so I've just tested it on Android phone and Ubuntu 19.10. There's Wifi Server option present you could try in your case.
Installation for Ubuntu:
You could run it from terminal:
droidcam &
Allowing it in firewall:
For 20.04 this droidcam installation guide could not work. But I've found a different way described here.
My suggestion would be a little different, since all options are already given.
Install TeamViewer and use it to connect to the laptop, the problem with this idea is that the laptop camera has to be pointed at you, even when you use the Desktop PC. This will work even if both computers are not on the same network. TeamViewer has a free(non-commercial) use and paid(commercial) use.
Use the remote connection You can use the remote connection on your Dekstop computer with Ubuntu.