android 调用 screenrecord 实现录屏
首先要说明的是并未实现,本文讲一下自己的思路。
java.lang.SecurityException: Permission Denial: broadcast asks to run as user -2 but is calling from user 0
需要android.permission.INTERACT_ACROSS_USERS_FULL 或者 android.permission.INTERACT_ACROSS_USERS 权限,而这个权限是system app的权限,第三方app是没有权限申请的。
shell@aries:/sdcard $ screenrecord --verbose --time-limit 10 /sdcard/1.mp4
Main display is 720x1280 @59.00fps (orientation=0)
Configuring recorder for 720x1280 video/avc at 4.00Mbps
Content area is 720x1280 at offset x=0 y=0
Time limit reached
Encoder stopping; recorded 6 frames in 10 seconds
Stopping encoder and muxer
Executing: /system/bin/am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_
FILE -d file:///sdcard/1.mp4
Broadcasting: Intent { act=android.intent.action.MEDIA_SCANNER_SCAN_FILE dat=fil
e:///sdcard/1.mp4 }
Broadcast completed: result=0
既然如此看一下screenrecord源码吧。
frameworks\av\cmds\screenrecord\screenrecord.cpp
*
* Sends a broadcast to the media scanner to tell it about the new video.
*
* This is optional, but nice to have.
*/
static status_t notifyMediaScanner(const char* fileName)
果然有这样一个函数,然后在 main 函数的末尾调用了此函数:
if (err == NO_ERROR) {
// Try to notify the media scanner. Not fatal if this fails.
notifyMediaScanner(fileName);
}
那么,如果注释掉 notifyMediaScanner(fileName); 这一行,重新编译出来的 screenrecord 可执行程序在录屏时就不会发广播了,是不是就不用 root 权限了呢?
经过测试,是可以的。
C:\Users\wy>adb logcat | findstr /I "ScreenRecord"
10-17 10:36:17.435 9839 9839 V ScreenRecord: Creating codec
10-17 10:36:17.531 9839 9839 V ScreenRecord: Creating encoder input surface
10-17 10:36:17.533 9839 9839 V ScreenRecord: Starting codec
10-17 10:36:17.618 9839 9839 V ScreenRecord: Codec prepared
10-17 10:36:17.623 9839 9839 V ScreenRecord: Calling dequeueOutputBuffer
10-17 10:36:17.873 9839 9839 V ScreenRecord: dequeueOutputBuffer returned -11
10-17 10:36:17.873 9839 9839 V ScreenRecord: Got -EAGAIN, looping
10-17 10:36:17.873 9839 9839 V ScreenRecord: Calling dequeueOutputBuffer
10-17 10:36:18.124 9839 9839 V ScreenRecord: dequeueOutputBuffer returned -11
10-17 10:36:18.124 9839 9839 V ScreenRecord: Got -EAGAIN, looping
10-17 10:36:18.124 9839 9839 V ScreenRecord: Calling dequeueOutputBuffer
日志显示,在输出 buffer 的时候一直返回错误,不停的重复尝试,直到结束也没成功录屏一帧。
这就不知道什么原因了,还得去看代码。
先丢这里,望明白的大神指点。
最新文章
- redirect问题
- Linux 防火墙开放特定端口 (iptables)
- reference
- mac os利用xampp实现apache下的cgi
- Autoit 获取运行目录
- Flash与DIV的层叠顺序问题
- EC读书笔记系列之9:条款16、17
- nginx 安装三方包重新编译
- 二叉树——遍历篇(递归/非递归,C++)
- vim中的批量替换
- LeetCode第十八题-四数之和
- java设计模式自我总结---适配器模式
- ionic3 生命周期 之 ionViewWillLeave 坑
- Day08 - Ruby比一比:String的+=与concat串接
- tsung HTTP协议统计报告分析
- HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)
- 【python练习题】程序2
- c++ 异常 warning: 'MEMORY_UNIT_NAME' defined but not used
- 架构之路:nginx与IIS服务器搭建集群实现负载均衡(三)
- IE8不能保存cookie,造成response.redirect死循环的原因
热门文章
- Linux计划任务及压缩归档(week2_day1)--技术流ken
- 如果你也打算学习 Spring Cloud
- Autofac 和 Quartz.Net 自动注入的整合
- The openssl extension is required for SSL/TLS protection but is not available
- ssh远程连接vm 安装的ubuntu
- iPhone手机怎么投影到MacPro上
- Android ViewPager+Fragment 在Activity中获取Fragment的控件
- dotnet core如何编译exe
- 开始食用grpc(之二)
- POJ 3085 - Quick Change