编辑 android VideoView 帧 [英] Editing android VideoView frames

查看:44
本文介绍了编辑 android VideoView 帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 库中尝试找到一种访问原始帧的方法,但找不到字节缓冲区或任何代表帧的内容.

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 并覆盖其 draw(Canvas canvas) 方法.

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

  • 将位图设置为通过 draw 接收的画布.
  • 调用 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);
        ...
    }
}

我不知道这是否可行.避免在 draw 中进行繁重的计算,在那里启动一个线程.

I don't know whether this will work. Avoid doing heavy calculation in draw, start a thread there.

这篇关于编辑 android VideoView 帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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