使用MediaCodec录制720p视频,但编码视频的fps太低 [英] Use MediaCodec to record 720p video but fps of encoding video is too low

查看:225
本文介绍了使用MediaCodec录制720p视频,但编码视频的fps太低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法编写了一个录像演示,我的实现与Grafika的ContinuousCaptureActivity相同. 在ContinuousCaptureActivity.java中,作者在SurfaceCreated中创建egl对象,该对象在UI线程中运行,并在UI线程中也调用drawFrame.他在drawFrame中做了两件事,将帧绘制到屏幕上并将数据推送到编码器.

I managed to write a video recording demo, my implementation is the same as ContinuousCaptureActivity of Grafika. In ContinuousCaptureActivity.java, The author create egl object in SurfaceCreated which run in UI thread and call drawFrame also in UI thread. He did 2 things in drawFrame, draw frame to screen and push data to encoder.

在此处查看代码: ContinuousCaptureActivity

由于我将编码视频的尺寸设置为1280 * 720,因此较大,因此相机预览不流畅,目标视频的fps较低. 我计划创建一个新线程来执行编码工作,但是我不知道如何使用opengl es的多线程处理.谁可以提供建议?

Because I set the encoding video size to 1280*720 which is large, the camera preview is not smooth and fps of target video is low. I plan to create a new thread to do the encoding work but I do not know how to handle with multithread of opengl es. Who can give some advice?

添加:我发现Texture2dProgram的drawFrame使用GLES20.glDrawArrays,GLES20.glDrawElements是否可以获得更好的性能?

Add: I found that drawFrame of Texture2dProgram use GLES20.glDrawArrays, Will GLES20.glDrawElements get a better performance?

推荐答案

首先,对于主流设备来说1280x720应该不是问题.某些超级便宜的低端设备可能会遇到困难,但如果硬件根本无法处理1280x720x30fps,则您实际上无能为力.

First, 1280x720 shouldn't be an issue for mainstream devices. Some super-cheap low-end devices might struggle, but there isn't really anything you can do if the hardware simply can't handle 1280x720x30fps.

我看到的720p FPS较低的最常见原因是无法为相机配置合理的fps值(使用setPreviewFpsRange()getSupportedPreviewFpsRange()的值),以及无法调用setRecordingHint(true)(或相当于Camera2).后者可以将您从15​​fps提升到30fps,但可能会影响预览的宽高比.

The most common reasons I've seen for low FPS at 720p are failure to configure the Camera with a reasonable fps value (using setPreviewFpsRange() with a value from getSupportedPreviewFpsRange()), and failing to call setRecordingHint(true) (or the Camera2 equivalent). The latter can take you from 15fps to 30fps, but may affect the aspect ratio of the preview.

视频编码是在称为Mediaserver的单独过程中执行的,该过程管理与视频编码器硬件的所有交互.已经在运行多个线程,因此添加另一个线程将无济于事.

The video encoding is performed in a separate process, called mediaserver, which manages all interaction with the video encoder hardware. There are already multiple threads in play, so adding another won't help.

GLES代码正在绘制两个带纹理的三角形.使用其他API不会改变两者之间的差异.

The GLES code is drawing two textured triangles. Using a different API won't change the difference.

如果您认为存在性能瓶颈,则需要使用 systrace之类的工具缩小范围.

If you think there is a performance bottleneck, you need to use tools like systrace to narrow it down.

这篇关于使用MediaCodec录制720p视频,但编码视频的fps太低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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