【问题标题】:MediaProjection for screen capture - How to change resolution?用于屏幕捕获的 MediaProjection - 如何更改分辨率?
【发布时间】: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()

这一切都很好,只要 screenWidthscreenHeight 与显示器的匹配。

如果我更改 recordWidthrecordHeight(通过 setVideoSize(Int, Int) 传递给 MediaRecorder),那么一切都会出错。 录制的视频往往只包含整个屏幕的左上角。

所以我的主要问题:

  1. 是否需要做一些特殊的事情来降低分辨率? 录屏?即使我保持纵横比与 屏幕,它似乎不起作用。
  2. 某些宽度/高度值会导致 crash - 是否有 API 来检索支持的屏幕录制 尺寸?我知道Camera 提供了一个,但这并不是真正使用 相机 API。

【问题讨论】:

    标签: android mediarecorder screen-capture mediaprojection


    【解决方案1】:

    我想你可以参考这个 this.mMediaProjection = mMediaProjectionManager.getMediaProjection(resultCode, resultData);

        Log.d(TAG, "startRecording...");
    
        this.mVideoBufferInfo = new MediaCodec.BufferInfo();
        MediaFormat mediaFormat = MediaFormat.createVideoFormat(format, width, height);
    
        mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitrate);
        mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, FPS);
        mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 0);
        mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
    

    【讨论】:

    • 这会有什么帮助?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多