编辑机器人VideoView帧机器人、编辑、VideoView

2023-09-07 04:38:13 作者:宇宙×制霸

的Nexus 7果冻豆4.1.2

我试图做一个运动检测应用程序,使用VideoView RTSP工作。

I'm trying to make a Motion Detection application that works with RTSP using VideoView.

我希望有类似的onNewFrameListener

I wish that there was something like an onNewFrameListener

videoView.onNewFrame(Frame frame)

我试图让您能够通过VideoView的RTSP流的原始帧,但无法找到,在Android SDK中的任何支持。

I've tried to get access to the raw frames of an RTSP stream via VideoView but couldn't find any support for that in the Android SDK.

我发现VideoView封装了Android的MediaPlayer的类。

I found out that VideoView encapsulates the Android's MediaPlayer class.

所以,我一头扎进 media_jni lib中,试图找到一种方法来访问原始帧,但找不到字节的缓冲区或什么的再presents一个框架。

So i dived into the media_jni lib to try and find a way to access the raw frames, But couldn't find the byte buffer or whatever that represents a frame.

任何人有一个想法在哪里,我怎么能找到这个缓冲区和访问它?

Anyone has an idea where or how can i find this buffer and get access to it ?

或实施运动检测过VideoView任何其他的想法?

Or any other idea of implementing a Motion Detection over a VideoView ?

即使它是最高审计机关,我需要重新编译AOSP。

推荐答案

您可以扩展 VideoView 并覆盖其画(油画画布)方法。

You can extend the VideoView and override its draw(Canvas canvas) method.

设置您的位图,通过收到的帆布。 呼叫 super.draw()这将让绘制到您的位图的框架。

从位图访问帧的像素。 Set your bitmap to the canvas received through draw. Call super.draw() which will get the frame drawn onto your bitmap.

Access the frame pixels from the bitmap.

class MotionDetectorVideoView extends VideoView {
public Bitmap mFrameBitmap;
...
    @Override
    public void draw(Canvas canvas) {
        // set your own member bitmap to canvas..
        canvas.setBitmap(mFrameBitmap);
        super.draw(canvas);
        // do whatever you want with mFrameBitmap. It now contains the frame.
        ...
        // Allocate `buffer` big enough to hold the whole frame.
        mFrameBitmap.copyPixelsToBuffer(buffer);
        ...
    }
}

我不知道这是否会奏效。不要干过重的计算,启动一个线程在那里。 尝试,让我知道。

I dont know whether this will work. Avoid doing heavy calculation in draw, start a thread there. Try and let me know..