Take this block of example code:
// 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()
This all works well, as long as screenWidth and screenHeight match that of the display.
If I change recordWidth and recordHeight (which are passed to the MediaRecorder with setVideoSize(Int, Int)), then all goes wrong. The recorded video tends to contain just the upper left section of the overall screen.
So my main questions:
Camera provides one, but this isn't really using the
Camera APIs.I think you can refer this one 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With