在 Android 应用程序上使用 USB 摄像头 [英] Use USB Camera on Android application

查看:122
本文介绍了在 Android 应用程序上使用 USB 摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Android 3.2 上显示连接到我的平板电脑的 USB 摄像头传输的视频.

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

我该怎么做?

我无法使用平板电脑的摄像头,因为我的平板电脑是固定在船上的.

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

推荐答案

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

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

只有当 USB 摄像头内的传感器符合 UVC 标准(当今的大多数摄像头都符合标准)时,该讨论才成立.

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

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

当您插入 USB 摄像头时,您需要先检查几件事.

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

1) 您的相机是否通过 USB 端口供电?(为此,您的 USB 端口应该支持 USB-OTG - 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?)

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

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) 如果创建了节点,需要编写固件(UVC)并从真实硬件中获取帧. 它(UVC)支持与 v4l2 层对话的不同 ioctl 调用内核并会为您获取帧.

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.

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

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

收到帧后,将其转换为 RGB 或 Jpeg(Android 支持转换)并显示在您喜欢的画布或图像视图上.

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.

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

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

这篇关于在 Android 应用程序上使用 USB 摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆