在Android应用程序上使用USB Camera

时间:2021-08-09 15:58:47

I need to display a video transmitted by an USB Camera connected to my tablet on Android 3.2. But I haven't any idea on how to do it.

我需要在Android 3.2上显示连接到平板电脑的USB摄像头传输的视频。但我对如何做到这一点一无所知。

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

我无法使用平板电脑的相机,因为我的平板电脑是固定在机上的。

thx.

3 个解决方案

#1


34  

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

只有当USB摄像头内部的传感器符合UVC(当今大多数摄像机都兼容)时,讨论才成立。

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.

截至本文发布之日(2012年3月1日),没有默认的Android API可用于外置摄像头。因此,如果您对项目非常认真,那么您所做的工作将涉及编写与内核驱动程序对话的固件,然后在Android应用程序层上显示数据。

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

插入USB摄像头时,首先需要检查的东西很少。

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?)

1)你的相机是否从USB端口供电?(为此你的USB端口应该有USB-OTG支持 - USB端口可以作为目标和主机,检查相机上的灯(如果有的话)是否发光?)

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.

2)是否在/ dev目录中创建了节点?(仅在内核启用了v4l2和UVC支持的情况下,才会创建节点)。如果创建了节点,现在您可以访问USB摄像头的真实硬件,从此处可以轻松完成工作。检查android文件系统中的ls -l / dev / v *并检查是否正在创建video0或video1。

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.

4)如果创建了节点,则需要编写固件(UVC)并从真实硬件中获取帧。它(UVC)支持与内核中的v4l2层通信的不同ioctl调用,并将获取帧。

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

这些帧主要是格式YUYV422或YUYV420格式。

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.

收到帧后,转换为RGB或Jpeg(Android支持转换)并在画布或imageview上显示您喜欢的。

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

对于录制,您可能必须使用ffmpeg进行编码。这会将图像转换为视频。

PS: 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.

PS:我在2012年写的时候没有支持USB摄像头。我不再在Android上工作..所以我无法解释如何使用最新的Android API。如果您知道更好的解决方案,请在此处发布。

#2


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).

在开始之前,值得检查的一件事是USB线是否可以与鼠标,键盘和USB驱动器配合使用(在某些设备上需要使用StickMount应用程序才能使USB驱动器正常工作)。

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.

我也希望在Android上使用USB网络摄像头,并尝试重现在http://brain.cc.kogakuin.ac.jp/research/usb-e.html上所做的工作。最后我听说蓝牙网络摄像头开箱即用。

#3


-3  

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

现在(2017)有支持USB视频输入的Android应用程序:

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)

可能需要“Y形”OTG电缆(“Y形”OTG电缆允许为外部设备供电)

#1


34  

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

只有当USB摄像头内部的传感器符合UVC(当今大多数摄像机都兼容)时,讨论才成立。

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.

截至本文发布之日(2012年3月1日),没有默认的Android API可用于外置摄像头。因此,如果您对项目非常认真,那么您所做的工作将涉及编写与内核驱动程序对话的固件,然后在Android应用程序层上显示数据。

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

插入USB摄像头时,首先需要检查的东西很少。

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?)

1)你的相机是否从USB端口供电?(为此你的USB端口应该有USB-OTG支持 - USB端口可以作为目标和主机,检查相机上的灯(如果有的话)是否发光?)

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.

2)是否在/ dev目录中创建了节点?(仅在内核启用了v4l2和UVC支持的情况下,才会创建节点)。如果创建了节点,现在您可以访问USB摄像头的真实硬件,从此处可以轻松完成工作。检查android文件系统中的ls -l / dev / v *并检查是否正在创建video0或video1。

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.

4)如果创建了节点,则需要编写固件(UVC)并从真实硬件中获取帧。它(UVC)支持与内核中的v4l2层通信的不同ioctl调用,并将获取帧。

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

这些帧主要是格式YUYV422或YUYV420格式。

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.

收到帧后,转换为RGB或Jpeg(Android支持转换)并在画布或imageview上显示您喜欢的。

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

对于录制,您可能必须使用ffmpeg进行编码。这会将图像转换为视频。

PS: 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.

PS:我在2012年写的时候没有支持USB摄像头。我不再在Android上工作..所以我无法解释如何使用最新的Android API。如果您知道更好的解决方案,请在此处发布。

#2


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).

在开始之前,值得检查的一件事是USB线是否可以与鼠标,键盘和USB驱动器配合使用(在某些设备上需要使用StickMount应用程序才能使USB驱动器正常工作)。

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.

我也希望在Android上使用USB网络摄像头,并尝试重现在http://brain.cc.kogakuin.ac.jp/research/usb-e.html上所做的工作。最后我听说蓝牙网络摄像头开箱即用。

#3


-3  

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

现在(2017)有支持USB视频输入的Android应用程序:

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)

可能需要“Y形”OTG电缆(“Y形”OTG电缆允许为外部设备供电)