問題描述
我正在使用帶有 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 abyte[]
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 aSurfaceView
; using thelockCanvas()
andunlockCanvasAndPost()
methods available from theSurfaceHolder
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模板網!