android - 编辑 android VideoView 帧

标签 android android-videoview android-source android-4.2-jelly-bean motion-detection

环境:

Nexus 7 果冻 bean 4.1.2

问题:

我正在尝试使用 VideoView 制作一个与 RTSP 配合使用的运动检测应用程序。

我希望有类似 onNewFrameListener 的东西

videoView.onNewFrame(Frame frame)

我尝试通过 VideoView 访问 RTSP 流的原始帧,但在 Android SDK 中找不到对此的任何支持。

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

所以我深入研究了 media_jni 库,试图找到一种访问原始帧的方法,但找不到字节缓冲区或任何表示帧的东西。

问题:

任何人都知道我在哪里或如何找到这个缓冲区并访问它?

或者在 VideoView 上实现运动检测的任何其他想法?

即使是我需要重新编译 AOSP。

最佳答案

您可以扩展 VideoView 并覆盖其 draw(Canvas canvas) 方法。

  • 将您的位图设置为通过draw 接收的 Canvas 。
  • 调用 super.draw() 将把框架绘制到您的位图上。
  • 从位图中访问帧像素。

    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 中进行繁重的计算,在那里启动一个线程。

关于android - 编辑 android VideoView 帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13498184/

相关文章:

android - 如何将文件系统移植到Android?

android - avc 拒绝在守护进程上进行转换

android - 无法录制音频

android - 水平 RecyclerView 中的 VideoView 在滑动时显示壁纸

android - API 16 之前的 ExoPlayer

android - 即使 fragment 内的方向发生变化,也要保持视频播放?

android - 从 App 到 Android 中的 SystemService 的通信

java - 通过 CountDownTimer 显示长小数的简单方法 - Android

java - Osmdroid - 折线渲染不平滑

android - 更改 ActionBar 标题