3

I'm using OpenCV and v4l2loopback library to emulate video devices:

modprobe v4l2loopback devices=2

Then I check what devices I have:

root@blah:~$ v4l2-ctl --list-devices
Dummy video device (0x0000) (platform:v4l2loopback-000):
        /dev/video1

Dummy video device (0x0001) (platform:v4l2loopback-001):
        /dev/video2

XI100DUSB-SDI (usb-0000:00:14.0-9):
        /dev/video0

video0 is my actual camera where I grab frames from, then I plan to process them via OpenCV and write it to video2 (which is a sink I believe).

Here is how I attempt to do so:

  int width = 320;
  int height = 240;
  Mat frame(height, width, CVX_8UC3, Scalar(0, 0, 255));
  cvtColor(frame, frame, CVX_BGR2YUV);

  int fourcc = CVX_FOURCC('Y', 'U', 'Y', '2');
  cout << "Trying to open video for write: " << FLAGS_out_video << endl;
  VideoWriter outputVideo = VideoWriter(
      FLAGS_out_video, fourcc, 30, frame.size());
  if (!outputVideo.isOpened()) {
    cerr << "Could not open the output video for write: " << FLAGS_out_video
         << endl;
  }

As far as I know video output format should be YUYV (which is equal to YUY2 in OpenCV). Please correct me if I'm wrong. In my code I'm not writing into outputVideo anything yet, just trying to open it for write, but I keep getting outputVideo.isOpened()==false for some reason, no additional errors/info in the output:

root@blah:~$ main --uid='' --in_video='0' --out_video='/dev/video2'
Trying to open video for write: /dev/video2
Could not open the output video for write: /dev/video2

I'd appreciate any advice or help on how to debug/resolve this issue. Thank you in advance!

Pavel Podlipensky
  • 8,201
  • 5
  • 42
  • 53
  • Just some guesses: 1) use a filename with extension, e.g. `/dev/video2.mpeg` 2) you don't have necessary codec installed, try another one to see if this is the case, 3) you don't have the permission to write in that folder – Miki Oct 04 '16 at 07:41
  • @Pavel Podlipensky: as far as i know it is not possible with the VideoWriter class. but you can write to the device directly. take a look at: http://stackoverflow.com/questions/34416189/opencv-output-on-v4l2 – Stefan Krüger s-light Feb 22 '17 at 13:04

0 Answers0