Android Question How can I use a USB camera ?

laviniut

Active Member
Licensed User
Longtime User
I bought a chinese USB HD webcam which is working fine on windows xp and windows 7 without any driver. I tried to connect to my samsung galaxy s2 but I have not seen my usb camera in any camera application. Maybe is a HID device. So, how can I use a USB camera ?
 

laviniut

Active Member
Licensed User
Longtime User
I tried USBdetails from here http://www.b4x.com/android/forum/threads/usb-host-library.11290/#post-63127 and i get some details:
Manufacturer : Novatek
Product : Digital Camera
Serial : 961230000000100

DeviceName : /dev/bus/usb/002/002
DeviceClass : USB_CLASS_MISC (miscellaneous
DeviceSubClass : 2
Device ID : 7D2h
ProductId : 8124h
VendorId :603h

B4aInterfaceNumber : 0
InterfaceClass : USB_CLASS_VIDEO (video)
InterfaceSubClass : 1
InterfaceProtocol : 0

EndpointNumber : 3
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_INT (interrupt)
EndpointAttribute : 3
EndpointInterval : 8
EndpointMaxPacketSize : 32

B4aInterfaceNumber : 1
InterfaceClass : USB_CLASS_VIDEO (video)
InterfaceSubClass : 2
InterfaceProtocol : 0

B4aInterfaceNumber : 2
InterfaceClass : USB_CLASS_VIDEO (video)
InterfaceSubClass : 2
InterfaceProtocol : 0

EndpointNumber : 1
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_ISOC (isochronous )
EndpointAttribute : 5
EndpointInterval : 1
EndpointMaxPacketSize : 128

B4aInterfaceNumber : 3
InterfaceClass : USB_CLASS_VIDEO (video)
InterfaceSubClass : 2
InterfaceProtocol : 0

EndpointNumber : 1
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_ISOC (isochronous )
EndpointAttribute : 5
EndpointInterval : 1
EndpointMaxPacketSize : 256

B4aInterfaceNumber : 4
InterfaceClass : USB_CLASS_VIDEO (video)
InterfaceSubClass : 2
InterfaceProtocol : 0

EndpointNumber : 1
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_ISOC (isochronous )
EndpointAttribute : 5
EndpointInterval : 1
EndpointMaxPacketSize : 512

B4aInterfaceNumber : 5
InterfaceClass : USB_CLASS_VIDEO (video)
InterfaceSubClass : 2
InterfaceProtocol : 0

EndpointNumber : 1
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_ISOC (isochronous )
EndpointAttribute : 5
EndpointInterval : 1
EndpointMaxPacketSize : 1024

B4aInterfaceNumber : 6
InterfaceClass : USB_CLASS_VIDEO (video)
InterfaceSubClass : 2
InterfaceProtocol : 0

EndpointNumber : 1
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_ISOC (isochronous )
EndpointAttribute : 5
EndpointInterval : 1
EndpointMaxPacketSize : 3072

B4aInterfaceNumber : 7
InterfaceClass : USB_CLASS_VIDEO (video)
InterfaceSubClass : 2
InterfaceProtocol : 0

EndpointNumber : 1
EndpointDirection : In
EndpointType : USB_ENDPOINT_XFER_ISOC (isochronous )
EndpointAttribute : 5
EndpointInterval : 1
EndpointMaxPacketSize : 5120
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
As far as I know, there's no Android API to handle an external camera, which means, you will have to write an app to handle that task, you could use a 3rd party app and use intents, like THIS for example. (I haven't tried that API, but at least is an idea).
 
Upvote 0

laviniut

Active Member
Licensed User
Longtime User
Not a bad idea. But i don't know java. Can you give me an b4a example that uses that api ?
 
Upvote 0

hayderOICO

Member
Licensed User
Longtime User
as I know. Android now supports UVC cameras.

in addition for cameras with ARM linux drivers, you can cross compile them to work with android.


The only issue remaining is how to access them from B4A ? It would be nice if we could access /dev/video0 ... video4 from B4A cameraEx.
 
Upvote 0

hayderOICO

Member
Licensed User
Longtime User
I read this somewhere...

give it a go. it may work.

OK, but I have to say that this mod is not what I would call “professional”. Far from it, as I do not have the skills.only

I have a nexus 7 32gb wifi, stock rom JDQ39. Bootloader unlocked and rooted. My webcam is the one you find in the Trust Exis Chat Pack, max resolution 640×480 and uvc compatible.
The webcam can be attached before booting (“BB”) or after (“AB”). Simplewebcam works and lets me access the webcam both ways. Fast Burst Camera works, but I can see both built-in and usb camera only in the BB case, otherwise it’s just built-in. The native camera app is the most problematic, because in the BB case it crashes and in the AB case it works but lets me use the built-in camera only.
I can experience the above behaviour even when I add a line to /etc/nvcamera.conf that reads like “usb=/dev/video0″ (or anything else I could think of, for that matter) which some say works [see Steven Archibald's google+ posting]. So I left that file in its original state.
What I did instead was to edit the /etc/media_profiles.xml, in the following way.

I copied the whole section beginning with the tag and ending with the tag .
Pasted it right underneath.
Changed the tag to .
So I had two CamcorderProfiles, the first for cameraId=”0″ and the second for cameraId=”1″.
Then I examined all the subsections in the second profile, kept the ones I thought were ok for my webcam and deleted the others.

I copied the whole section beginning with the tag -CamcorderProfiles cameraId=”0″- and ending with the tag /CamcorderProfiles.
Pasted it right underneath.

Changed the tag to CamcorderProfiles cameraId=”1″.
So I had two CamcorderProfiles, the first for cameraId=”0″ and the second for cameraId=”1″.
Then I examined all the subsections in the second profile, kept the ones I thought were ok for my webcam and deleted the others.

Now the native camera app (BB case only) lets me see both usb and built-in cam and I can shoot pictures or take videos with both of them.
Problems: the usb camera preview is ok when holding the tablet in portrait position and does not rotate when holding the tablet in landscape position. Some apps just don’t work: AutoGuard Blackbox and Car Blackbox for instance.

PS: the media_profiles.xml I had was NOT the original one, because of the 720p video recording hack: http://forum.xda-developers.com/showthread.php?t=1868962

I truly hope this helps. Cheers!
 
Upvote 0

hayderOICO

Member
Licensed User
Longtime User
I bought a chinese USB HD webcam which is working fine on windows xp and windows 7 without any driver. I tried to connect to my samsung galaxy s2 but I have not seen my usb camera in any camera application. Maybe is a HID device. So, how can I use a USB camera ?

Your device sounds a bit old. did you upgrade with CM10 to get up to jelly bean at least? if you upgrade it to JellyBean, you will be able to use the above.

I can confirm that I made the logitech C920 camera work on my nexus 7 today. will update progress on making it work from B4A.
 
Upvote 0

laviniut

Active Member
Licensed User
Longtime User
I will test soon with another device with android 4.2.2
So, i think it don't work without changes you made.
 
Upvote 0

hayderOICO

Member
Licensed User
Longtime User
yea. you do need to make the changes above. I havent had time to do this last week. but this week I'm working on it.

my setup:

Nexus 7 2013
android 4.4 kitkat
rooted, and added elementalX

Cameras:
Logitech C920 with UVC (this already works for me but using "third party" software).
Another camera module but with a libusb driver (not working yet).

Next tasks:
spoof the android into thinking the /dev/videoX (USB video camera) is one of the "built in" cameras
Build a Basic 4 Android program to preview and take image with that USB camera.
 
Upvote 0

hayderOICO

Member
Licensed User
Longtime User
ok. The above method works fine for devices with only ONE built in camera (Camera0)... then you can add your external camera as camera1.

but for devices which already have 2 built in cameras (camera0 and camera1), you would need to set your USB camera as camera2 in media_profiles.xml on the device.

Then you would have to make some changes to the CameraExClass FindCamera to enable more than 2 cameras and set it to the camera you want to use. ;)
 
Last edited:
Upvote 0

hayderOICO

Member
Licensed User
Longtime User
sadly I have to report back...

for the nexus 7 2013 the above method doesn't work. It simply refuses to acknowledge a third camera :(

for a tablet / phone with only one built in camera it still works since they seem to have "hardcoded" a front/back camera setup (0 for back and 1 for front)... I added cameras 2,3 to no avail even though the underlying ANDROID system does see it (it is assigned /dev/video3 and works fine with a program called dashcam on the same tablet which is accessing it directly via V4L2).


I will continue trying to make this work.
 
Upvote 0
Top