我想导出由VP9解码的屏幕录制视频,现在可以导出由VP8编码的视频。
//get mediaProjection
mediaProjectionManager = (MediaProjectionManager) activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data);
mediaRecorder = new MediaRecorder();
DisplayMetrics displayMetrics = getScreenConfig();
int width = DEFAULT_WIDTH;
int height = DEFAULT_HEIGHT;
if (mediaRecorder != null) {
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.WEBM);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.VP8);
mediaRecorder.setOutputFile(saveFile.getAbsolutePath());
mediaRecorder.setVideoSize(width, height);
mediaRecorder.setVideoEncodingBitRate((width * height * 2));
mediaRecorder.setVideoFrameRate(VIDEO_FRAME_RATE);
try {
mediaRecorder.prepare();
virtualDisplay =
mediaProjection.createVirtualDisplay("MainScreen", width,
height, displayMetrics.densityDpi,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mediaRecorder.getSurface(),
null, null);
}catch(Exception e){
...
}
...
//start record
mediaRecorder.start();
使用此代码我可以得到视频是.webm文件并由VP8编码。但是该文件很大并且需要压缩。我发现它可以由VP9编码并减小尺寸。
但是MediaRecorder
不支持VP9,因此如何导出VP9视频。