38

I have created an armeabi API 21 emulator in the AVD manager in Android Studio, set it to use the webcam as a front camera, and launched it. The problem is that it's not able to open it, as I'm getting this error:

emulator: ERROR: camera_device_start_capturing: VIDIOC_STREAMON on camera '/dev/video0' has failed: Timer expired
emulator: ERROR: _camera_client_query_start: Cannot start camera '/dev/video0' for NV21[640x480]: Inappropriate ioctl for device

How can I solve this?

The webcam works normally using other software. The operative system is Ubuntu 14.04.

Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48
  • 2
    Hi Johnson, what dev tools do you mean? – Alessandro Roaro Jan 10 '15 at 14:03
  • 1
    Same issue here - have you found a solution so far. In my case it was AndroidStudio. – Jon Feb 17 '15 at 12:50
  • 1
    Hi Jon, no I haven't solved this problem yet. What was the issue? – Alessandro Roaro Feb 17 '15 at 13:49
  • 1
    It is weird - when I start the camera from vlc it works perfectly. But when using the Android's emulator - it fails. With the same error message. So, time for a bounty! – Jon Feb 17 '15 at 14:36
  • 1
    I'm using the same OS, so I have added it to the edit – Alessandro Roaro Feb 17 '15 at 15:39
  • Did you see this question, http://stackoverflow.com/questions/14012924/android-how-to-use-webcam-in-emulator – Virmundi Feb 17 '15 at 15:52
  • It's already set like that, thank you anyway – Alessandro Roaro Feb 17 '15 at 15:55
  • does the webcam appear when you access the emulator command line with `-webcam list`? – Uriel Arvizu Feb 17 '15 at 16:21
  • Yes, the cameras are detected. It even realizes it when I switch from my built-in camera to an additional, external camera. – Jon Feb 19 '15 at 09:14
  • It seems that the `Inappropriate ioctl` error can be related to the driver for some webcams. [This page](http://www.raspberrypi.org/forums/viewtopic.php?t=17308&p=178372) discusses the error in a different context. One idea: use Gstreamer to redirect /dev/video0 to a different pipe which the Android emulator uses as a webcam input - see [this stackexchange post](http://unix.stackexchange.com/questions/5452/manipulating-dev-video). – Aaron D Feb 24 '15 at 12:31
  • Is it working with the emulated camera? – Erdal G. Dec 20 '15 at 15:27

5 Answers5

22

In Android Studio, go to AVD Manager, click on edit (pencil) button in Actions. After that, in next appearing window, click on Advance settings, and then scroll down and in Camera options, select webcam for front and back.

BST Kaal
  • 2,993
  • 6
  • 34
  • 52
  • 5
    As I said, I configured the emulator to use the front camera. Thanks anyway – Alessandro Roaro Nov 24 '15 at 08:23
  • I read a warning hat you must not name the same camera twice in AVD Manager. So selecting webcam for front AND back would run afoul that rule. – Quigi Oct 11 '18 at 19:09
12

To enable Camera in your Android Emulator, just add following highlighted code in your AVD’s config.ini file. You can find the config.ini file under your <userdirectory>/.android folder.

File: ~/.android/config.ini

hw.lcd.density=160<br>
skin.name=HVGA<br>
skin.path=platforms\android-9\skins\HVGA<br>
hw.cpu.arch=arm<br>
abi.type=armeabi<br>
vm.heapSize=24<br>
image.sysdir.1=platforms\android-9\images\<br>
hw.camera=yes<br>
sdcard.size=64M<br>

In case you don’t find the config.ini file or want to enable Camera support through Android SDK and AVD Manager do the following:

Open Android SDK and AVD Manager:

  1. Add SD Card in AVD
    In the SD Card setting, set the value for Size. To enable camera, the SD Card must be enabled in Emulator.
  2. Add Camera Support in Hardware under AVD
    Now under Hardware section, click New button to add Camera hardware. It will open following Dialog box. Select Camera support from the Property dropdown and click Ok.
  3. Enable Camera Support in Hardware
    The new hardware: Camera support is visible under Hardware section. Set its value to yes and save changes by pressing Edit AVD.
  4. Save the changes and launch the emulator.
Akhil
  • 1,073
  • 1
  • 9
  • 28
Mayavi
  • 149
  • 6
9

You can try to manually edit your AVD's configuration file under

~/.android/avd/yourAvdName/config.ini

by adding this line:

hw.camera=yes

UPDATE

You can try to specify the real resolution of your webcam:

hw.camera.maxHorizontalPixels=XXX
hw.camera.maxVerticalPixels=XXX

Keep in mind that the default value for maxHorizontalPixels is 640 and for maxVerticalPixels is 480, so chaning this values may help you to solve your issues.

bonnyz
  • 13,458
  • 5
  • 46
  • 70
  • We don't have the issue of activating the camera. The camera is activated, but there seems to be an issue with drivers. There camera works with VLC and cheese. But it does not work within the emulator. However, the camera is detected by the system. – Jon Feb 19 '15 at 09:12
  • 2
    `hw.camera=yes` fixed my problem! Tks! Strangely, if you save your AVD configurations using the AVD manager, it removes the `hw.camera=yes` var. o.O – Alexander Haroldo da Rocha Mar 17 '18 at 12:58
1

I had a similar issue with a slightly different error message under OS X. I turned out that everything was ok but the emulator is crashing when the camera takes too much time to initialize.

I my case I ended up closing other applications and it worked. You may want to test in a more performant computer.

Erdal G.
  • 2,694
  • 2
  • 27
  • 37
0

I had trouble getting the camera to work under the emulator (under linux), even after setting it up in AVD as instructed here. I was helped by noticing that the camera it was trying to use was /dev/video0, but the camera I wanted was /dev/video3. A quick swap...

mv /dev/video0 /dev/video4
mv /dev/video3 /dev/video0

...did the trick

Change /dev/video6 into /dev/video0

poleguy
  • 523
  • 7
  • 11