How to simulate a webcam device

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


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/


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 ./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

链接地址: http://www.djcxy.com/p/14242.html

上一篇: 将CouchDB作为Rails应用程序的一部分进行分发?

下一篇: 如何模拟摄像头设备