27

I need to display a video transmitted by an USB Camera connected to my tablet on Android 3.2.

How can I do this?

I can't use the tablet's camera, because my tablet is fixed on board.

Volker Siegel
  • 3,277
  • 2
  • 24
  • 35
neoffreeman
  • 271
  • 1
  • 3
  • 4

3 Answers3

34

(I wrote this in 2012 when there was no support for USB camera. I am not working on Android anymore.. so I cannot explain how to do it with the API of latest Android. If you know any better solution please post it here.)

The discussion holds true only if the sensor inside USB camera is UVC compliant(most of todays' cameras are compliant).

As of the date of this post(March 1 2012), there are no default Android API's available for working on external camera. So if you are serious about the project, the work you do would involve writing a firmware that talks to the kernel drivers and then displaying the data on the Android application layer.

When you insert a USB camera, There are few things that you need to check first.

1) Is your camera getting power from USB port?(For this to happen your USB port should have USB-OTG support- USB port can act both as target and host, Check whether the lights on camera(if any) are glowing or not?)

2) Is node getting created in /dev directory?(Only in case the kernel has v4l2 and UVC support enabled,node will be created). If node is getting created, now you have access to the real hardware that is USB camera and your job is going to be easy from here on. to check do ls -l /dev/v* inside the android file system and check whether video0 or video1 is being created.

4) If node is created, you need to write a firmware(UVC) and acquire a frame from the real hardware. It(UVC) supports different ioctl calls that talk to the v4l2 layer in the kernel and will fetch you the frames.

These frames would be mostly of format YUYV422 or YUYV420 format.

Once you receive the frames, convert into RGB or Jpeg (Android has support to convert ) and display on the canvas or imageview whichever you like.

For recording you might have to use ffmpeg for encoding. This will convert the images into video.

Sandeep
  • 18,356
  • 16
  • 68
  • 108
  • Thanks for your answer, I'm very interested !!! 1) I tried 2 webcam, the first hasn't light and the second's light doesn't glow. 2) In the Android directoy, the file system "video0" has been created. 3) for this point, I need help XD – neoffreeman Jan 25 '12 at 20:21
  • I also want to capture photo and video from USB webcam. And get it to Android device. I came across your description here and want to start the development for this. Please suggest from where to start off?? I found that Video4Linux(V4L) library does that for linux, so hoping that this should work for Android also without any rooting, because there is an application at the play store which does the same without rooting...[here](https://play.google.com/store/apps/details?id=infinitegra.trial.usbcamera&hl=en) – AndroidDev Oct 16 '13 at 08:17
  • The Reasons why rooting was required are 1. The device node didnt had permissions for user. 2. I have copied the FFmpeg libraries to /system/lib. To do this adb root and adb remount needed to be done. I think now a days FFMpeg can be integrated with the App itseld but i am not sure if the device node being created (/dev/video1) would have permissions for users to read it. If yes then you can do it without any problem. – Sandeep Oct 16 '13 at 09:35
  • @Manty: I appreciate your quick reply. After using that google play store trial application I am sure this feature can be achieved without root. My question is how to start working on this issue? And whether OpenCV is capable to achieve this? – AndroidDev Oct 16 '13 at 11:32
  • I have not used openCV. But i heard of people doing it. Sorry. But the whole idea should be to build an executable for arm first that would be able to capture the image fro usb camera. For this you can use wither uvc or opencv(i am not sure though). – Sandeep Oct 17 '13 at 01:46
  • @Manty: I have two devices HTC One-X and Samsung Galaxy 7 inch tablet. While connecting WebCam to HTC One-X video0 folder is created under /dev folder. But the same folder is not creating inside Samsung Galaxy 7 inch. But that application(described) above work for both the devices. How to get video0 folder if it is not created? – AndroidDev Oct 30 '13 at 11:56
  • @neoffreeman did you get any success regarding the same ? – B.shruti Jul 03 '20 at 06:18
1

One thing worth checking before you get started is whether your USB cable works with a mouse, keyboard, and USB Drive (you will need to StickMount app on some devices to get the USB drive working).

I am also looking to get a USB webcam working on Android and am trying to reproduce what was done at http://brain.cc.kogakuin.ac.jp/research/usb-e.html. Lastly I heard that Bluetooth webcams work out of the box.

bbodenmiller
  • 3,101
  • 5
  • 34
  • 50
  • It's worth noting that this user is using the CM9 mod as well. I was unable to get the hack to work without CM9 nor have I been able to try it with CM9. – bbodenmiller Mar 20 '12 at 05:13
-2

Now (2017) there are android apps supporting USB video input:

https://play.google.com/store/apps/details?id=labsp.android.viewer&hl=it

Probably a "Y-shaped" OTG cable is required ("Y-shaped" OTG cables allow powering the external device)

jumpjack
  • 841
  • 1
  • 11
  • 17
  • do you really think it is a answer of this question. – Aditay Kaushal Jul 19 '17 at 14:04
  • 4
    sure it is: the question was about how to connect an USB camera to an Android tablet. Maybe it is not possible for owners of "ancient" tablets like the one of the OP, but all people coming here looking for an answer for their tablet will find my answer very useful. My answer is also an update to the most-voted answer below, which is now outdated as current smartphones do have drivers for external USB cameras and there are plenty of apps on Google Play Store (look for "easycap" or "usb video capture". – jumpjack Jul 21 '17 at 07:28
  • 1
    question is how to do it using problematically.you did not give a solution. You just gave a APP url. you should give a idea about question – Aditay Kaushal Jul 21 '17 at 14:12
  • 1
    I agree my answer is outdated. I request you to update your answer by briefing it a little more. it should Ideally have some sample code and reference to API's that explain how to write a simple application to use a USB camera in Android. – Sandeep May 18 '18 at 02:31