Android OpenGLES screenrecord 录屏 直接显示

duansilence 2017-06-19 10:31:13
大家好,我在做Android录屏功能的时候参考官方系统源码提供的frameworks/av/cmds/screenrecord这个示例。
执行
#screenrecord --time-limit 10 --output-format frames /sdcard/video.mp4
直接录制屏幕数据保存到文件
分析代码后其主要是将屏幕内容渲染到Virtualdisplay上,然后通过glReadPixels读取并保存下来。

我现在想将录制的屏幕内容直接在一个surface上显示出来。

程序在EglWindow.cpp中有createWindow这个函数,应该是作者用来测试直接显示录制的内容的,但是我怎么调都没有图像显示,不知道有没有做这块的可以请教或者讨论下,谢谢!



status_t EglWindow::createWindow(const sp<IGraphicBufferProducer>& surface) {
if (mEglSurface != EGL_NO_SURFACE) {
ALOGE("surface already created");
return UNKNOWN_ERROR;
}
status_t err = eglSetupContext(false);
if (err != NO_ERROR) {
return err;
}

// Cache the current dimensions. We're not expecting these to change.
surface->query(NATIVE_WINDOW_WIDTH, &mWidth);
surface->query(NATIVE_WINDOW_HEIGHT, &mHeight);

ANativeWindow_Buffer outBuffer;
// Output side (EGL surface to draw on).
sp<ANativeWindow> anw = new Surface(surface);
//surface->lock(&outBuffer, NULL);
//ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
//android_memset16((uint16_t*)outBuffer.bits, 0xF800, bpr*outBuffer.height);
//surface->unlockAndPost();
mEglSurface = eglCreateWindowSurface(mEglDisplay, mEglConfig, anw.get(),NULL);
if (mEglSurface == EGL_NO_SURFACE) {
ALOGE("eglCreateWindowSurface error: %#x", eglGetError());
eglRelease();
return UNKNOWN_ERROR;
}
return NO_ERROR;
}


...全文
357 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,492

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧