我正在使用带有 Eclipse 的 Android 2.2.
I'm using Android 2.2 with Eclipse.
我想制作一个捕获视频的应用程序,并且对于每一帧,将其作为位图发送到处理它的方法并返回一个新位图并显示处理后的位图.
I would like to make an application that captures video, and for each frame, its send it as a bitmap to a method that processes it and returns a new bitmap and shows the processed bitmap.
我对 Android 不是很熟悉,所以请谁能给我发一份我需要查看的资源来做这样的事情?
I am not very familiar with Android, so please, can anyone send me to the resources I need to look at to do such a thing?
使用Android SDK完成以下步骤很简单:
It is simple enough to accomplish the following steps using the Android SDK:
Camera.PreviewCallback
将返回一个 byte[]
数据,以多种可能的图像格式表示帧.Bitmap
对象,以便更轻松地处理像素.在 2.2 中,您可以选择使用 NDK 和 jnigraphics 在本机代码中处理位图的像素,这比 Java 层要快得多.Bitmap
的内容并显示它.对于快速移动的数据,您可能希望在 SurfaceView
上显示它;使用视图包含的 SurfaceHolder
提供的 lockCanvas()
和 unlockCanvasAndPost()
方法.Camera.PreviewCallback
will return a byte[]
of data representing the frame in a number of possible image formats.Bitmap
object to make working with the pixels easier. In 2.2, you have the option of using the NDK and jnigraphics to work with a Bitmap's pixels in native code, which is significantly faster than at the Java layer.Bitmap
and display it. For fast moving data, you would want to display this on a SurfaceView
; using the lockCanvas()
and unlockCanvasAndPost()
methods available from the SurfaceHolder
that view contains.如果这就是您想做的全部,您可以轻松完成.但是,这与捕获视频不同.Android 目前不提供挂钩让您将帧实时流式传输到编码的视频容器(MPEG4、3GP 等)中.它的视频捕获功能被紧紧地包裹在 MediaRecorder
中,它控制着从帧捕获到编写编码视频的整个过程.您将需要一个第三部分库,例如 FFMPEG(已在 Android 应用程序中多次使用 NDK 层构建和运行)来协助修改帧的编码过程.
If this is all you are wanting to do, you could accomplish this with little difficulty. However, this is not the same as capturing video. Android does not currently provide hooks for you to stream frames out into an encoded video container (MPEG4, 3GP, etc.) in real-time. It's video capture capabilities are wrapped up tightly into the MediaRecorder
which controls the process from frame capture all the way to writing the encoded video. You would need a 3rd part library such as FFMPEG (which has been built and run using the NDK layer a number of times in Android applications) to assist in the encoding process of your modified frames.
我知道您的目标是 2.2,但 Android 4.0 确实在这方面提供了一些缓解,因为他们发布了新版本的 NDK,它允许人们在从流中读取图像数据然后将其交给之前有更多发言权表示层.但是,我没有花足够的时间来了解它是否适合您的情况.
I know you have a 2.2 target, but Android 4.0 does provide some relief here as they have released a new version of the NDK which allows one to have more say in what happens when reading image data from a stream before handing it to the presentation layer. However, I have not spent enough time with it to know whether it could be recommended for your situation.
这篇关于Android中的视频处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!