Video Capture Device (v4l2) plugin

leonhard

Developer
Since information about this plugin is spread all over the place (forum threads / mantis bugtracker) this thread aims to gather all information relevant to the v4l2 capture plugin.

Known Issues
  • The framesize/framerate options are currently hardcoded for some devices.
  • There seem to be problems with devices that need the v4l2compat library.
  • Interleaved formats are handled incorrectly
  • Colorspace/Range is currently handled incorrectly (not at all)

"My device does not work!"
If you encounter any problems with the capture plugin please make sure your device works with other programs, most notably the "Qt V4L2 Test Utility" that is available in most Distributions with the v4l2 userspace utils package.
In case your device works fine with the test utility but not with the obs plugin please leave a comment in this thread and include a log file and the output of the following command:
Code:
v4l2-ctl --list-formats


Frequently Asked Questions
Q:
What are "Emulated" Video Formats?
A: A v4l2 device may output the video data in different image formats. Obs on the other hand accepts different image formats to use them as a texture. If a format is supported by both the device and obs, the captured data is simply copied.
The v4l2 userspace utilities additionally provide the option of transcoding some formats devices may offer but obs is not able to use directly. The formats listed as "Emulated" are transcoded from a different input format.
On webcams the emulated formats are MJPEG internally most of the time, which is a compressed format. Using those formats can help reduce the needed bandwidth for USB devices and might allow for higher resolutions/framerate.

2015-04-21 b4a0e79
  • Added rgb formats supported on newer kernels
2015-02-25 57f32e3
  • Implemented "dv timing" selection
2015-02-24 aa68111
  • Implemented "video standard" selection
2014-10-29 10a9133
  • Improve handling of connecting/disconnecting devices in the properties window.
  • Some smaller improvements/fixes.
2014-10-15 291b88e
  • Added (optional) support for udev to detect device removals/additions
2014-09-22 34e2b77
  • Fixed device capability problems with devices that have more than one device node
  • Added the 'Leave Unchanged' option for all settings and made that the default
  • Some internal refactoring of the plugin code
2014-08-14 69b9e72
  • Added support for selecting inputs
  • Fixed a Crash and endless Loop
2014-07-29 eecc9ab
  • The plugin now requires libv4l2, this enables more pixelformats transcoded on the fly
  • Numerous smaller bugfixes and changes
2014-07-25 94e2bad
  • Added 720x576 (DV-PAL) to list of fixed resolutions
2014-07-19 eeb6fc6
  • Added more logging statements to the plugin
  • Added fixed fallback frame sizes/rates for devices not supporting discrete enumeration
  • Numerous smaller bugfixes and changes
2014-07-12 1cf19d0
  • Fixed a bug where obs would hang if a v4l2 source was added without any device attached
 
Last edited:

apemax

New Member
I have a Hauppauge bt848 TV/video capture card and OBS doesn't seem to detect all the video inputs. (composite port, etc.) Log file attached.

Output of:

Code:
v4l2-ctl --list-formats

Code:
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'GREY'
    Name        : 8 bpp, gray

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'HI24'
    Name        : 8 bpp, dithered color

    Index       : 2
    Type        : Video Capture
    Pixel Format: 'RGBO'
    Name        : 15 bpp RGB, le

    Index       : 3
    Type        : Video Capture
    Pixel Format: 'RGBQ'
    Name        : 15 bpp RGB, be

    Index       : 4
    Type        : Video Capture
    Pixel Format: 'RGBP'
    Name        : 16 bpp RGB, le

    Index       : 5
    Type        : Video Capture
    Pixel Format: 'RGBR'
    Name        : 16 bpp RGB, be

    Index       : 6
    Type        : Video Capture
    Pixel Format: 'BGR3'
    Name        : 24 bpp RGB, le

    Index       : 7
    Type        : Video Capture
    Pixel Format: 'BGR4'
    Name        : 32 bpp RGB, le

    Index       : 8
    Type        : Video Capture
    Pixel Format: 'RGB4'
    Name        : 32 bpp RGB, be

    Index       : 9
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : 4:2:2, packed, YUYV

    Index       : 10
    Type        : Video Capture
    Pixel Format: 'UYVY'
    Name        : 4:2:2, packed, UYVY

    Index       : 11
    Type        : Video Capture
    Pixel Format: '422P'
    Name        : 4:2:2, planar, Y-Cb-Cr

    Index       : 12
    Type        : Video Capture
    Pixel Format: 'YU12'
    Name        : 4:2:0, planar, Y-Cb-Cr

    Index       : 13
    Type        : Video Capture
    Pixel Format: 'YV12'
    Name        : 4:2:0, planar, Y-Cr-Cb

    Index       : 14
    Type        : Video Capture
    Pixel Format: '411P'
    Name        : 4:1:1, planar, Y-Cb-Cr

    Index       : 15
    Type        : Video Capture
    Pixel Format: 'YUV9'
    Name        : 4:1:0, planar, Y-Cb-Cr

    Index       : 16
    Type        : Video Capture
    Pixel Format: 'YVU9'
    Name        : 4:1:0, planar, Y-Cr-Cb
 

Attachments

  • 2014-08-05 16-57-18.txt
    62 KB · Views: 688

leonhard

Developer
Thank you for the report, as you already noticed there is currently no option for choosing the input. I'll try to implement support for that in the future.
 

leonhard

Developer
Support for selecting an Input was merged to master with some bug fixes. Setting framesize/rate through the videostandard API is next on the list. If you find some time to test your devices again and report back if something changed for you, that would be highly appreciated.
 

a264164

New Member
Hi,

I have found some problem on v4l2 , too ...on Easycap DC60+
when I try to Add a Video Capture Device (V4L2) on sources tab
...
Then I select "Video Capture Device (V4L2)" on "Create New" tab

....
Then a new windows comes up but I can't make any changes (eg: changed S-Video to Composite Video) at all (except close the windows)

The screen cap is the following: (included in this message)
d9rteLCl.jpg


And at the same time... the log shows:

01:35:37 HKT: v4l2-input: Found device 'EM2860/SAA711X Reference Design' at /dev/vbi0
01:35:37 HKT: v4l2-input: Found device 'EM2860/SAA711X Reference Design' at /dev/video0
01:35:37 HKT: v4l2-input: Start capture from /dev/vbi0
01:35:38 HKT: v4l2-input: Unable to set format
01:35:38 HKT: v4l2-input: Initialization failed
01:35:38 HKT: source 'Video Capture Device (V4L2)' (v4l2_input) created
01:35:38 HKT: v4l2-input: Found device 'EM2860/SAA711X Reference Design' at /dev/vbi0
01:35:38 HKT: v4l2-input: Found device 'EM2860/SAA711X Reference Design' at /dev/video0
01:35:38 HKT: v4l2-input: Found input 'S-Video'
01:35:38 HKT: v4l2-input: Found input 'Composite1'
01:35:38 HKT: v4l2-input: Stepwise and Continuous framesizes are currently hardcoded
01:35:38 HKT: v4l2-input: Stepwise and Continuous framerates are currently hardcoded
01:35:38 HKT: v4l2-input: Stepwise and Continuous framesizes are currently hardcoded
01:35:38 HKT: v4l2-input: Stepwise and Continuous framerates are currently hardcoded
01:35:38 HKT: v4l2-input: Stepwise and Continuous framesizes are currently hardcoded
01:35:38 HKT: v4l2-input: Stepwise and Continuous framerates are currently hardcoded
(...endless)

Kindly check this and waiting an better version coming
 

leonhard

Developer
If you installed from the repository and not from source don't bother unless you are curious and have some free time. The changes should be in the next release, so you'll get them automatically with the next update. Might take a little while though.
 

leonhard

Developer
I updated the op with the changes that just got merged to master, so they should soon be available from the ppa.
The problem with the capture device should be fixed now. Additionally there is a new option ("Leave Unchanged") for all settings, which will cause the plugin to leave that setting when starting the capture.
 

leonhard

Developer
@codythedragomdude could you check if the following steps work for you ?
  • start obs and add the v4l2 source, set everything to "leave unchanged" and close obs
  • capture the video in vlc/qv4l2 or any other capture application and close that application
  • start obs again and check if you have video, if not try changing the image-format first
As far as i can tell from your video it starts the capture fine except when you set a framerate, but there are for some unknown reasons simply no frames retrieved from the device. If you could post a log-file regardless of whether it works or not, that would be highly appreciated.
 
i don't know what happened but the adding of video capture devices is GONE from the latest master branch. I just compiled it from git and the option is missing.
Here's my output for the above command however.
Code:
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUV 4:2:2 (YUYV)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : MJPEG
It's a Logitech C260 webcam. and here's the lsusb -v output
http://paste.ubuntu.com/8530642/
 

Lain

Forum Admin
Lain
Forum Moderator
Developer
I'm going to implement a workaround for linux V4L capture at some point. For unbuffered frame playback I mean.
 

bazukas

Developer
i don't know what happened but the adding of video capture devices is GONE from the latest master branch. I just compiled it from git and the option is missing.
Here's my output for the above command however.
Code:
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUV 4:2:2 (YUYV)

    Index       : 1
    Type        : Video Capture
    Pixel Format: 'MJPG' (compressed)
    Name        : MJPEG
It's a Logitech C260 webcam. and here's the lsusb -v output
http://paste.ubuntu.com/8530642/

Do you have libv4l2 development packages installed? I believe it is libv4l-dev on Ubuntu.
 
Do you have libv4l2 development packages installed? I believe it is libv4l-dev on Ubuntu.
apparently i was missing that package before I compiled obs-studio, maybe you should add that to the INSTALL file as a dependency or optional dependency IF a person has a V4L capture device.

It's not working however, or it's very weird. I've tried to leave everything unchanged, close obs, open guvcview, close guvcview, then open obs-studio again and only IF I choose the exact correct settings it will work. Here's the terminal output trying to get it working if this is useful to you. all thew while it's just a grey screen BUT i see the light on the front of my webcam going on and off.

http://pastebin.com/zCsRucFC

WORK AROUND: to anyone else experiencing this in linux, just open guvcview and use a window capture as a source and choose guvcview video as the window and problem solved.
 
well i did try that work around i posted the results in the other forum post didint work out so well heres the results

dragondude@main-desktop:~$ gst-launch-0.10 decklinksrc mode=18 connection=1 ! videoscale ! video/x-raw-yuv,width=1280,height=720 ! v4l2sink device=/dev/video1 sync=false
Setting pipeline to PAUSED ...
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0: Cannot identify device '/dev/video1'.
Additional debug info:
v4l2_calls.c(497): gst_v4l2_open (): /GstPipeline:pipeline0/GstV4l2Sink:v4l2sink0:
system error: No such file or directory
Setting pipeline to NULL ...
Freeing pipeline ...
dragondude@main-desktop:~$
i don't want to muddy up this forum post so we should really take this to the other forum BUT did you try to run
Code:
sudo modprobe v4l2loopback
and then check each of the video device nodes? then ensure that you choose the correct mode? Answer in the other forum
 

leonhard

Developer
Ok here are some steps i did come up with:
  1. Install the v4l2loopback kernel module (this obviously is specific to your distribution)
  2. create a v4l2 loopback device either as root or with sudo:
    Code:
    modprobe v4l2loopback video_nr=9
    I used "video_nr=9" here so it will create /dev/video9, but you might choose whatever suits you ...
  3. try the gstreamer video test source:
    Code:
    gst-launch-1.0 videotestsrc ! video/x-raw,format=YUY2 ! v4l2sink device=/dev/video9
    again, use your video loopback device, and whatever your gst-launch command is

I don't have a black magic pro so i could not try that, but you might check if that works with gstreamer at all by trying
Code:
gst-launch-1.0 decklinksrc mode=18 connection=1 ! video/x-raw,format=YUY2,width=1280,height=720 ! autovideosink

Some observations i made:
  • Specify a "Video Format" in the source properties, otherwise the video will be very choppy and a lot of error messages will be posted.
  • trying to open the device in the qv4l2 test utility seems to screw that up, so i need to remove and readd the kernel module
  • Getting the gstreamer pipeline to work correctly is kind of hard, so make sure to test with the "autovideosink" device if in doubt

Just for the fun of it:
Code:
gst-launch-1.0 filesrc location=~/Movies/Aliens.mp4 ! decodebin name=demux \
    demux. ! queue ! videoconvert ! video/x-raw,format=\(string\)YUY2 ! v4l2sink device=/dev/video9 \
    demux. ! queue ! audioconvert ! autoaudiosink
again, the video is quite choppy ... but it kind of works

Update:
In the source properties set the "Video Format" to something specific like "[YUYV]", that will make the video go smooth
 
Last edited:
i finally figured out how to get my Logitech C260 webcam to work using the V4L plugin. I had to set the following
Input = Camera 1
VideoFormat = YV12 (Emulated)
Resolution = 320x240
FPS = 15
Unbuffered video playback

Code:
./obs 
Attempted path: ../../data/obs-studio/locale/en-US.ini
Attempted path: ../../data/obs-studio/locale.ini
Attempted path: ../../data/obs-studio/license/gplv2.txt
QObject::connect: invalid null parameter
info: OBS 0.6.2-12-gee96d5e-modified (linux)
info: Processor: 4 logical cores
info: Processor: Intel(R) Core(TM) i5-4670K CPU @ 3.40GHz
info: Physical Memory: 7929MB Total
info: Kernel Version: Linux 3.13.0-38-generic
info: Distribution: "Ubuntu" "14.04"
info: audio settings reset:
    samples per sec: 44100
    speakers:        2
    buffering (ms):  100

info: X and Y: 911 484
Backbuffers: 2
Color Format: 3
ZStencil Format: 0
Adapter: 0

info: OpenGL version: 3.2.0 NVIDIA 343.22

info: Created new platform data
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: convert_sampler_info: 1 <= max_anisotropy <= 16 violated, selected: 0, set: 1
info: video settings reset:
    base resolution:   1920x1080
    output resolution: 1280x720
    fps:               60/1
info: output 'default_file_output' (flv_output) created
info: output 'default_stream' (rtmp_output) created
info: encoder 'default_h264' (obs_x264) created
info: encoder 'default_aac' (libfdk_aac) created
info: service 'default_service' (rtmp_custom) created
[image2 @ 0x2094500] Could find no file with with path '/media/500gb1/Dropbox/ubu project new/UBU Stream Overlay [Newest].png' and index in the range 0-4
warning: Failed to open file '/media/500gb1/Dropbox/ubu project new/UBU Stream Overlay [Newest].png': No such file or directory
warning: [image_source: 'overlay'] failed to load texture '/media/500gb1/Dropbox/ubu project new/UBU Stream Overlay [Newest].png'
info: source 'overlay' (image_source) created
info: source 'be right back' (scene) created
error: xcompcap: XCompositeRedirectWindow failed: BadWindow (invalid Window parameter)
info: source 'webcam' (xcomposite_input) created
info: source 'livestreaming' (scene) created
error: xcompcap: XCompositeRedirectWindow failed: BadWindow (invalid Window parameter)
info: source 'borderlands' (xcomposite_input) created
info: source 'testing' (scene) created
info: xshm-input: Geometry 1920x1080 @ 1680,0
info: source 'Screen Capture (XSHM)' (xshm_input) created
info: source 'be_right_back' (image_source) created
info: source 'sine wave test' (scene) created
info: source 'Sinewave Sound Source (Test)' (test_sinewave) created
info: pulse-input: Server name: 'pulseaudio 4.0'
info: pulse-input: Audio format: s16le, 44100 Hz, 2 channels
info: pulse-input: Started recording from 'alsa_output.pci-0000_00_1b.0.analog-stereo.monitor'
info: source 'Audio Output Capture (PulseAudio)' (pulse_output_capture) created
info: pulse-input: Server name: 'pulseaudio 4.0'
info: pulse-input: Audio format: s16le, 48000 Hz, 1 channels
info: pulse-input: Started recording from 'alsa_input.usb-046d_081a_13339CA0-02-U0x46d0x81a.analog-mono'
info: source 'Audio Input Capture (PulseAudio)' (pulse_input_capture) created
info: v4l2-input: Start capture from /dev/video0
info: v4l2-input: Input: 0
info: v4l2-input: Resolution: 432x240
info: v4l2-input: Pixelformat: 842094169
info: v4l2-input: Linesize: 432 Bytes
info: v4l2-input: Framerate: 30.00 fps
info: source 'Video Capture Device (V4L2)' (v4l2_input) created
info: Update check: latest version is: 0.4.0
info: v4l2-input: Found device 'UVC Camera (046d:081a)' at /dev/video0
info: v4l2-input: /dev/video1 seems to not support video capture
info: v4l2-input: Found input 'Camera 1' (Index 0)
info: v4l2-input: Pixelformat: YUV 4:2:2 (YUYV) (available)
info: v4l2-input: Pixelformat: MJPEG (unavailable)
info: v4l2-input: Pixelformat: RGB3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: BGR3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: YU12 (Emulated) (available)
info: v4l2-input: Pixelformat: YV12 (Emulated) (available)
info: v4l2-input: Stepwise and Continuous framerates are currently hardcoded
info: v4l2-input: Pixelformat: YUV 4:2:2 (YUYV) (available)
info: v4l2-input: Pixelformat: MJPEG (unavailable)
info: v4l2-input: Pixelformat: RGB3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: BGR3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: YU12 (Emulated) (available)
info: v4l2-input: Pixelformat: YV12 (Emulated) (available)
info: v4l2-input: Stepwise and Continuous framerates are currently hardcoded
info: v4l2-input: Stepwise and Continuous framerates are currently hardcoded
info: v4l2-input: Stepwise and Continuous framerates are currently hardcoded
info: v4l2-input: Stopped capture after 0 frames
info: v4l2-input: Start capture from /dev/video0
info: v4l2-input: Input: 0
info: v4l2-input: Resolution: 320x240
info: v4l2-input: Pixelformat: 842094169
info: v4l2-input: Linesize: 320 Bytes
info: v4l2-input: Framerate: 30.00 fps
info: v4l2-input: Stopped capture after 0 frames
info: v4l2-input: Start capture from /dev/video0
info: v4l2-input: Input: 0
info: v4l2-input: Resolution: 320x240
info: v4l2-input: Pixelformat: 842094169
info: v4l2-input: Linesize: 320 Bytes
info: v4l2-input: Framerate: 15.00 fps
info: [x264 encoder: 'default_h264'] preset: medium
info: [x264 encoder: 'default_h264'] settings:
    bitrate:     2000
    buffer size: 2000
    fps_num:     60
    fps_den:     1
    width:       1280
    height:      720
    keyint:      60
    cbr:         on
info: [x264 encoder: 'default_h264'] custom settings: keyint=60
info: libfdk_aac encoder created
info: libfdk_aac bitrate: 128, channels: 2
info: [flv output: 'default_file_output'] Writing FLV file '/home/ubu/Videos/obs-studio/2014-10-22 22-57-38.flv'...
info: v4l2-input: Found device 'UVC Camera (046d:081a)' at /dev/video0
info: v4l2-input: /dev/video1 seems to not support video capture
info: v4l2-input: Found input 'Camera 1' (Index 0)
info: v4l2-input: Pixelformat: YUV 4:2:2 (YUYV) (available)
info: v4l2-input: Pixelformat: MJPEG (unavailable)
info: v4l2-input: Pixelformat: RGB3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: BGR3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: YU12 (Emulated) (available)
info: v4l2-input: Pixelformat: YV12 (Emulated) (available)
info: v4l2-input: Pixelformat: YUV 4:2:2 (YUYV) (available)
info: v4l2-input: Pixelformat: MJPEG (unavailable)
info: v4l2-input: Pixelformat: RGB3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: BGR3 (Emulated) (unavailable)
info: v4l2-input: Pixelformat: YU12 (Emulated) (available)
info: v4l2-input: Pixelformat: YV12 (Emulated) (available)
info: [flv output: 'default_file_output'] FLV file output complete
info: Output 'default_file_output': stopping
info: Output 'default_file_output': Total frames: 4920
info: Output 'default_file_output': Number of skipped frames: 0 (0%)
Attempted path: ../../data/obs-studio/locale.ini
info: Freeing OBS context data
info:     13 user source(s) were remaining
info: source 'be right back' destroyed
info: source 'be_right_back' destroyed
info: source 'livestreaming' destroyed
info: source 'overlay' destroyed
info: source 'borderlands' destroyed
info: source 'webcam' destroyed
info: source 'testing' destroyed
info: source 'Screen Capture (XSHM)' destroyed
info: source 'Audio Output Capture (PulseAudio)' destroyed
info: pulse-input: Stopped recording from 'alsa_output.pci-0000_00_1b.0.analog-stereo.monitor'
info: pulse-input: Got 324405 packets with 12459487 frames
info: source 'Audio Input Capture (PulseAudio)' destroyed
info: pulse-input: Stopped recording from 'alsa_input.usb-046d_081a_13339CA0-02-U0x46d0x81a.analog-mono'
info: pulse-input: Got 170737 packets with 13555533 frames
info: source 'Video Capture Device (V4L2)' destroyed
info: v4l2-input: Stopped capture after 3926 frames
info: source 'sine wave test' destroyed
info: source 'Sinewave Sound Source (Test)' destroyed
info: output 'default_stream' destroyed
info: output 'default_file_output' destroyed
info:     2 output(s) were remaining
info: encoder 'default_aac' destroyed
info: libfdk_aac encoder destroyed
info: encoder 'default_h264' destroyed
info:     2 encoder(s) were remaining
info: service 'default_service' destroyed
info:     1 service(s) were remaining
Segmentation fault (core dumped)

NOTE: if you can't get your v4l device to work properly than I suggest installing guvcview, running it and than just using Window Capture (XComposite) in OBS as your source and this way you can even crop it if you want
 

ZeroLabs

Member
Continuing from this thread...
https://obsproject.com/forum/thread...-video-unspecified-error-xubuntu-14-04.21227/
I'm running into problems streaming with OBS in Xubuntu Linux 14.04 using multiple USB web cams to do pic in pic. The error returned when I try to add one too many Video Capture Devices to an OBS Scene is
Code:
libv4l2: error turning on stream: No space left on device
I have found a wealth of information on this topic at these two web sites...
http://superuser.com/questions/431759/using-multiple-usb-webcams-in-linux
http://stackoverflow.com/questions/11394712/libv4l2-error-turning-on-stream-no-space-left-on-device

Which brings me to the question how can I get my Logitec C270 to use MJPEG instead of YUYV?
 
Top