Android中的视频处理

Video processing in Android(Android中的视频处理)
本文介绍了Android中的视频处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 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[] 数据,以多种可能的图像格式表示帧.
  • 修改像素数据.由于数据以原始字节的形式返回,因此对数据进行调整相对容易......这里的困难在于为您想要执行的特定图像处理应用算法.没有任何内置效果(4.0 之前)可以简单地应用于图像,因此您必须自己编写.
  • 还可以将数据解码为 Bitmap 对象,以便更轻松地处理像素.在 2.2 中,您可以选择使用 NDK 和 jnigraphics 在本机代码中处理位图的像素,这比 Java 层要快得多.
  • 获取生成的 Bitmap 的内容并显示它.对于快速移动的数据,您可能希望在 SurfaceView 上显示它;使用视图包含的 SurfaceHolder 提供的 lockCanvas()unlockCanvasAndPost() 方法.
  • Capture the preview frames from the camera as bitmapped data. Camera.PreviewCallback will return a byte[] of data representing the frame in a number of possible image formats.
  • Modify the pixel data. Since the data comes back as raw bytes, making adjustments to the data is relatively easy...the difficulty here is applying an algorithm for the particular image processing you want to do. There aren't any built-in effects (pre-4.0) that can be applied simply to images so you will have to write your own.
  • It is also possible to decode the data into a 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.
  • Take the contents of your resultant 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中的视频处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)