当前位置:网站首页>The framing efficiency of setpreviewcallbackwithbuffer will become lower
The framing efficiency of setpreviewcallbackwithbuffer will become lower
2022-07-28 21:14:00 【android_ cai_ niao】
The following code implements a video capture without preview , And every time 10 Second count the frame rate :
class MainActivity : AppCompatActivity() {
private lateinit var camera: Camera
private val surfaceTexture = SurfaceTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES)
private val width = 1920
private val height = 1080
private var fps = 0
private var start = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
println("width = $width height = $height")
camera = Camera.open()
camera.parameters = camera.parameters.apply {
previewFormat = ImageFormat.NV21
setPreviewSize(width, height)
}
camera.setPreviewTexture(surfaceTexture)
camera.setPreviewCallback {
data, camera ->
fps++
val current = System.currentTimeMillis()
if (start == 0L) {
start = current
}
if (current - start >= 10000) {
println(" Frame rate :${
fps} frame /10 second ")
fps = 0
start = current
}
}
camera.startPreview()
}
override fun onDestroy() {
super.onDestroy()
camera.setPreviewCallback(null)
camera.stopPreview()
camera.release()
}
}
The millet 11 pro The operation effect is as follows :
width = 1920 height = 1080
Frame rate :301 frame /10 second
Frame rate :300 frame /10 second
Frame rate :300 frame /10 second
Frame rate :300 frame /10 second
Frame rate :301 frame /10 second
Frame rate :300 frame /10 second
Frame rate :300 frame /10 second
The average frame rate is 30 frame / second . I heard that using buffers can improve efficiency , So we changed the way of video capture to using buffer , as follows :
class MainActivity : AppCompatActivity() {
private lateinit var camera: Camera
private val surfaceTexture = SurfaceTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES)
private val width = 1920
private val height = 1080
private val callbackBuffer = ByteArray((width * height * 3) shr 1)
private var fps = 0
private var start = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
println("width = $width height = $height")
camera = Camera.open()
camera.parameters = camera.parameters.apply {
previewFormat = ImageFormat.NV21
setPreviewSize(width, height)
}
camera.setPreviewTexture(surfaceTexture)
camera.addCallbackBuffer(callbackBuffer)
camera.setPreviewCallbackWithBuffer {
data, camera ->
fps++
val current = System.currentTimeMillis()
if (start == 0L) {
start = current
}
if (current - start >= 10000) {
println(" Frame rate :${
fps} frame /10 second ")
fps = 0
start = current
}
camera.addCallbackBuffer(callbackBuffer)
}
camera.startPreview()
}
override fun onDestroy() {
super.onDestroy()
camera.setPreviewCallback(null)
camera.stopPreview()
camera.release()
}
}
The millet 11 pro The operation results are as follows :
width = 1920 height = 1080
Frame rate :276 frame /10 second
Frame rate :293 frame /10 second
Frame rate :298 frame /10 second
Frame rate :299 frame /10 second
Frame rate :295 frame /10 second
Frame rate :297 frame /10 second
You can see , After using the buffer , Frame rate decreased , Efficiency has not improved , It can only be said that it saves more memory . The difference in test results is more obvious on the company's mobile phone , Such as the test without buffer :
width = 1920 height = 1080
Frame rate :189 frame /10 second
Frame rate :249 frame /10 second
Frame rate :247 frame /10 second
Frame rate :250 frame /10 second
Frame rate :173 frame /10 second
Frame rate :162 frame /10 second
Frame rate :147 frame /10 second
Frame rate :173 frame /10 second
Test condition after using buffer :
width = 1920 height = 1080
Frame rate :133 frame /10 second
Frame rate :181 frame /10 second
Frame rate :133 frame /10 second
Frame rate :129 frame /10 second
Frame rate :141 frame /10 second
Frame rate :139 frame /10 second
Frame rate :133 frame /10 second
Frame rate :135 frame /10 second
You can see , After using buffer, the frame rate decreases significantly . If you use YV12 Format ,
Based on this test result , I don't use buffers in our company's project development , Because the project we developed is running on a special Android On the device , This Android As soon as the device starts, only one of our applications runs , There are no other applications , So it's OK to consume more memory , Anyway, memory is enough .
There are also particular about the choice of format , For example, on the company's mobile phone , Use NV21 Format , wide 640, high 480, Use buffer , The test results are as follows :
width = 640 height = 480
Frame rate :192 frame /10 second
Frame rate :240 frame /10 second
Frame rate :236 frame /10 second
Frame rate :239 frame /10 second
Frame rate :238 frame /10 second
Frame rate :238 frame /10 second
Frame rate is OK , Then we only change one format , hold NV21 Change to YV12, The test results are as follows :
width = 640 height = 480
Frame rate :181 frame /10 second
Frame rate :182 frame /10 second
Frame rate :179 frame /10 second
Frame rate :177 frame /10 second
You can see , Just change a format , The frame rate drops significantly , Can you think that the camera acquisition of this device is used NV21 Collected , When we use YV12 When the format , The framework needs to be NV21 To YV12 Format conversion , Therefore, the frame rate decreases ? When I use Xiaomi 11 pro There is no such problem during the mobile phone test , Is it because the mobile phone is fast , Fast format conversion , So the frame rate is not delayed ?
边栏推荐
- Is it necessary to disconnect all connections before deleting the PostgreSQL database?
- Interesting pictures and words
- Cobal Strike的学习与使用
- Ctfshow question making web module web11~web14
- SQL server中提示对象名无效
- oracle如何导出数据(oracle如何备份数据库)
- quii cordova-plugin-telerik-imagepicker插件多图上传乱序
- What is low code? Which platforms are suitable for business personnel? Is it reliable to develop the system?
- unity-shader-1
- Color finder actual combat (QT including source code)
猜你喜欢

58岁安徽人,干出瑞士今年最大IPO 投资界

How does lazada store make up orders efficiently? (detailed technical explanation of evaluation self-supporting number)

IJCAI2022教程 | 对话推荐系统

Buuctf questions upload labs record pass-01~pass-10

广和通&高通物联网技术开放日成功举办

A 58 year old native of Anhui Province, he has become the largest IPO investor in Switzerland this year

两款吾爱破解优秀软件,批量查找文本,图像视频画质增强

探讨:想要落地DevOps的话,只考虑好的PaaS容器平台就够了么?

Guo Mingxuan: meta contraction is conducive to the development of VR competitors, and apple XR headshow will change the industry rules

(turn) bubble sorting and optimization details
随机推荐
Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
Unity foundation 3- data persistence
After Europe, it entered Japan and South Korea again, and the globalization of Pico consumer VR accelerated
Jiuxin intelligence officially joined opengauss community
SQL Server 数据库之备份和恢复数据库
source insight 使用快捷键
Ctfshow question making web module web11~web14
mfc wpf winform(工业用mfc还是qt)
Reading and writing basic data types in protobuf
mysql梳理复习内容--附思维导图
(转)冒泡排序及优化详解
Unity - script lifecycle
Source insight uses shortcut keys
Database -- use of explain
A 58 year old native of Anhui Province, he has become the largest IPO investor in Switzerland this year
Maxwell 一款简单易上手的实时抓取Mysql数据的软件
取色器实战(Qt含源码)
MySQL修改端口号(修改mysql的端口号会有问题吗)
什么是低代码?哪些平台适合业务人员?用来开发系统靠不靠谱?
Cause analysis of restart of EMC cx4-120 SPB controller