Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate a webcam device [closed]

I am working on a project which I need to synthesize a video from existing frames and then format it exactly like a webcam device and make it available to external computers. In other words, this USB output should look exactly as if it was generated by a webcam. Can someone provide some hints about any existing library or any methodology to do this? The target system to create "webcam" output via USB is UBUNTU.

Thanks

like image 220
saman01 Avatar asked Feb 18 '16 11:02

saman01


2 Answers

Web cams are usually accessed through a library or the operating system rather than as low level USB devices. In python, one option to read webcam frame is https://github.com/gebart/python-v4l2capture or use my cross platform fork (including windows): https://github.com/TimSC/libvideolive

If you want to create a video stream that is accessible to other computers, you either need to emulate a webcam or an IP camera. A webcam can be emulated on windows by creating a custom media source. https://msdn.microsoft.com/en-us/library/windows/desktop/ms700134%28v=vs.85%29.aspx On linux, you need to stream data to v4l2loopback https://github.com/umlaeute/v4l2loopback. To emulate an IP camera, a good starting point is to base it on the tools available at http://live555.com/

like image 170
TimSC Avatar answered Oct 05 '22 08:10

TimSC


OK after updating your requirements I guess the following can help

first you create a program that prepare the frames

Mat frame = imread('<file>');
std::vector<uchar> buff;    
cv::imencode(".jpg", frame, buff);
for (auto i = buff.begin(); i != buff.end(); ++i)
   std::cout << *i ;

then you can use v4l2loopback combined with ffmpeg to emulate the webcam and pipe the output from the above program ./app | ffmpeg -re -i pipe:0 -f v4l2 /dev/video1

now the /dev/video1 is a virtual webcam (video device). Note that is not USB output. But I hope that's what you want.

For further info you can check this and this


UPDATE

you can always create another program that capture the output from /dev/video1 and then uses libusb to write it to another USB port which will achieve what do you want (webcam output to usb port

check this for an example

like image 20
Thesane Avatar answered Oct 05 '22 07:10

Thesane