How to simulate a webcam device [closed]

允我心安 提交于 2019-12-05 13:39:15

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/

Thesane

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!