Linux v4l2 настройка камеры

Webcam

This article will provide information on setting up and using a webcam on Gentoo using v4l-utils.

Installation

Kernel

The following kernel options need to be activated:

Device Drivers ---> Multimedia support ---> [*] Filter media drivers Media core support ---> [*] Video4Linux core [*] Media Controller API Media device types ---> [*] Cameras and video grabbers Video4Linux options ---> V4L2 flash API for LED flash class devices Media drivers ---> [*] Media USB Adapters ---> USB Video Class (UVC) [*] UVC input events device support

The matching CONFIG_* for the above options are:

  • CONFIG_MEDIA_CONTROLLER
  • CONFIG_MEDIA_SUPPORT
  • CONFIG_MEDIA_SUPPORT_FILTER
  • CONFIG_MEDIA_CAMERA_SUPPORT
  • CONFIG_VIDEO_V4L2_SUBDEV_API
  • CONFIG_VIDEO_DEV
  • CONFIG_V4L2_FLASH_LED_CLASS
  • CONFIG_MEDIA_USB_SUPPORT
  • CONFIG_USB_VIDEO_CLASS
  • CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV

Note
To enable sound on webcams equipped with a microphone, separate options, such as «USB Audio/MIDI driver» (CONFIG_SND_USB_AUDIO), may need to be configured.

USE flags

Recommended USE flags for v4l include: opengl , qt5 , and udev — at least qt5 will be needed to follow on with this article.

USE flags for media-tv/v4l-utils Separate utilities ebuild from upstream v4l-utils package

bpf Enables support for IR BPF decoders.
dvb Add support for DVB (Digital Video Broadcasting)
opengl Add support for OpenGL (3D graphics)
qt5 Add support for the Qt 5 application and UI framework
udev Enable virtual/udev integration (device discovery, power and storage device support, etc)

Источник

Setting Up a DSLR Camera Webcam on Linux

If you ever wanted to set up a DSLR camera as a webcam on Linux, it’s not easy. This post will walk you through some of the steps and tips.

Читайте также:  Linux current user name

I finally set up my DSLR camera as a webcam, and it’s pretty cool. I wanted to share this post because I couldn’t find good, complete resources about it and I thought it might be useful for folks out there (and because future me will probably want it). Here’s everything I learned.

Here’s what I’m working with. Your setup may be different:

Prerequisites

Before we get started, this may be a non-issue for a lot of folks as it’s common for camera manufacturers to create software for this. Canon, for example, make their EOS Webcam Utility that makes it easy for Windows or OSX users. But I use Linux (cue sad trombone).

If you’re like me and a handy webcam utility is not an option, let’s continue.

Setup

Firstly, make sure your camera is supported by checking this list: gphoto.org/proj/libgphoto2/support.php.

Install required software:

sudo apt install gphoto2 v4l2loopback-utils v4l2loopback-dkms ffmpeg

Next, run this random command. I’m still not 100% sure what it does, but I think it creates a “dummy” video capture device for you to use. This will make more sense later.

sudo modprobe v4l2loopback

Now, you can connect your camera and turn it on. After connecting your camera, you may see this icon:

This icon means your camera is connected as a drive. You don’t want this as it will interfere with the webcam utility.

Easiest way to deal with this is to kill all the gphoto processes by running this command:

If you just want to see the processes, you can use this command:

Using The DSLR As A Webcam

Now, with the camera ready, we need to see where the “dummy” video device is mounted by running this command:

You may see a number of different drives like the image below. The key thing to pay attention to is the “Dummy video device (0x0000)” drive. You’ll need to reference that in the next step.

Читайте также:  Минимальная установка linux mint

Now we can use gphoto to control the camera with the following command. Note the reference to the dummy video. Yours may be different. It’s also possible to change on your same computer at a later point in time.

gphoto2 --stdout autofocusdrive=1 --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video4

With that command running, your camera should have started capturing video and you should see some live text processing the video in the terminal. To test it, feel free to check it on any website like webcamtests.com.

Improve Your Setup

Unfortunately, the steps above are tedious, so the first thing you’re going to want to do is automate them. I prefer using Bash aliases to make it easy.

First, we’ll open our .bashrc file:

I like to make one called “prepcam” to setup v4l2loopback and kill gphoto. Then I make another one called “dslrcam” to start the webcam. To do the same, add these lines to the bottom of your .bashrc file.

alias prepcam="sudo modprobe v4l2loopback && pkill gphoto" alias dslrcam="gphoto2 --stdout autofocusdrive=1 --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video4" 

With those changes in place, we can save and close the file. If you used nano like me, use ctrl+x , then when it prompts you to save, press y , and finally hit enter to keep the file with the same name.

We also need to load the changes in our Bash profile.

You’ll probably also want to pick up a dummy battery. These are things that look like camera batteries, and as far as the camera is concerned work like camera batteries, but they have a cable that plugs into the wall. These are handy to provide a consistent power source without the need to recharge.

Читайте также:  Автозагрузка пользователя astra linux

For my camera, the model I was looking for was called “LP-E6 Style Dummy Battery”.

Picking up a USB hub was the next thing I would recommend. I like it because I use my camera in conjunction with a microphone on a boom arm and I like having a single cable to connect for my “recording mode”.

Closing Thoughts

This was a fun project for me to work on, and I’m happy with the results. With that said, it was only worth it because I already had a DSLR camera I don’t use that often.

If I were to start from scratch today, I would make my life much easier by either picking up a camera that makes this all simpler.

If you want to pick up a nice camera that doubles as a webcam, the Sony ZV-E10 Mirrorless Camera. It seems like it doesn’t need any encoding hardware, so you should be able to connect it via USB and be ready to go. That’s a big win.

If all you want is a webcam, the best reviews I’ve found are for the Lgitech C922 Pro and compared to a full on camera, it’s MUCH cheaper at around $75. It won’t serve as a camera as well, but hey, smartphones are pretty darn good these days.

References:

Thank you so much for reading. If you liked this article, and want to support me, the best ways to do so are to share it, sign up for my newsletter, and follow me on Twitter.

Originally published on austingil.com.

Источник

Оцените статью
Adblock
detector