17

I want to capture a video from a real webcam, apply filters with openCv and write the filtered video on a virtual webcam, to stream it on web.

I don't have problem with the first 2 points, but I don't know how I can write on a virtual webcam.

It's possible?

How can I do it?

I use openCv with C++ on Debian. Thanks

Mehdi
  • 1,494
  • 5
  • 33
  • 53
user1275896
  • 313
  • 1
  • 3
  • 5
  • or if you have another idea to stream the filtered video... – user1275896 May 03 '12 at 12:42
  • How does one "write to" a webcam? What does it mean? – San Jacinto May 03 '12 at 12:43
  • how do you plan on doing the streaming? Instead of making a virtual webcam, just host the streaming service directly from your app. Should be easier. Making a virtual cam involves driver programming which is much more complex than simply hosting a service. Maybe find an open source streaming server and modifi it a little bit with your new features. – Esben Skov Pedersen May 03 '12 at 12:57
  • @sanJacinto: I think that on Linux, a webcam write a file in /dev/something. I want write that file instead of a real webcam – user1275896 May 03 '12 at 12:57

2 Answers2

25

Well, actually this is possible. A quick and dirty way to do this is to use WebcamStudio. That will create a new video device (e.g., /device/video2) that other programs see as a normal video device and can take its input from desktop, so you just set it up to capture a part of the screen that OpenCV's output is shown there.

A better but more technical way is to use the V4L2 loop back module. This way you can simply pipe the output of OpenCV to the module which is seen as a regular video device by the other programs. See the readme at the bottom of this page: https://github.com/umlaeute/v4l2loopback and the wiki page: https://github.com/umlaeute/v4l2loopback/wiki for more information.

Hope that helps.

fireant
  • 14,080
  • 4
  • 39
  • 48
  • thanks. the solution with v4l2 loopback seems very interesting. can you suggest me handbooks or "howto" for it? I looked for them, but they are difficult to find... – user1275896 May 03 '12 at 13:46
  • I edited the answer, see if that's enough to understand how to use it. If you need an OpenCV example, right now I'm busy later tonight or tomorrow I can write an example on ubuntu. – fireant May 03 '12 at 13:55
  • How do I actually do it though? – Shambhav Dec 06 '21 at 11:41
1

You can also use a combination of v4l2loopback, OBS Studio and obs-v4l2sink.

Use OBS Studio to capture video from your device, then obs-v4l2sink is a small plugin that writes output into /dev/video* of your choice.

v4l2sink

https://github.com/umlaeute/v4l2loopback/wiki/OBS-Studio

https://github.com/CatxFish/obs-v4l2sink

Mahmoud
  • 9,729
  • 1
  • 36
  • 47