android jni中使用native Window渲染ffmpeg frame中的rgba数据

android jni中使用native Window渲染ffmpeg frame中的rgba数据
初始化:

    jobject surface=NULL;
    ANativeWindow* nativeWindow=NULL;
    ANativeWindow_Buffer outBuffer;

    nativeWindow=ANativeWindow_fromSurface(env, surface);

使用:

                ANativeWindow_setBuffersGeometry(nativeWindow, filt_frame->width, filt_frame->height,
                                                 WINDOW_FORMAT_RGBA_8888);
                ANativeWindow_lock(nativeWindow, &outBuffer, NULL);
                uint8_t *dst = (uint8_t *) outBuffer.bits;
                int destStride = outBuffer.stride * 4;
                uint8_t *src = filt_frame->data[0];
                int srcStride = filt_frame->linesize[0];
                for (int i = 0; i < filt_frame->height; ++i) {
                    memcpy(dst + i * destStride, src + i * srcStride,
                           static_cast<size_t>(srcStride));
                }
                ANativeWindow_unlockAndPost(nativeWindow);

关闭:

        if (nativeWindow!=NULL)
            ANativeWindow_release(nativeWindow);

最重要在cmake中添加库

find_library( # Sets the name of the path variable.
        lnative_window_jni-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        android )
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。