【发布时间】:2018-12-20 02:05:47
【问题描述】:
以这段示例代码为例:
// from window manager
val recordWidth = screenWidth
val recordHeight = screenHeight
val projection: MediaProjection = // retrieved from API
val mediaRecorder = MediaRecorder().apply {
setVideoSource(SURFACE)
setOutputFormat(MPEG_4)
setVideoFrameRate(frameRate) // e.g. 30
setVideoEncoder(H264)
setVideoSize(recordWidth, recordHeight)
setVideoEncodingBitRate(videoBitRate)
setOutputFile(outputFile)
prepare()
}
val virtualDisplay: VirtualDisplay = projection?.createVirtualDisplay(
"Example",
screenWidth,
screenHeight,
screenDensity,
VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mediaRecorder.surface,
null,
null
)
mediaRecorder.start()
这一切都很好,只要 screenWidth 和 screenHeight 与显示器的匹配。
如果我更改 recordWidth 和 recordHeight(通过 setVideoSize(Int, Int) 传递给 MediaRecorder),那么一切都会出错。 录制的视频往往只包含整个屏幕的左上角。
所以我的主要问题:
- 是否需要做一些特殊的事情来降低分辨率? 录屏?即使我保持纵横比与 屏幕,它似乎不起作用。
- 某些宽度/高度值会导致
crash - 是否有 API 来检索支持的屏幕录制
尺寸?我知道
Camera提供了一个,但这并不是真正使用 相机 API。
【问题讨论】:
标签: android mediarecorder screen-capture mediaprojection