標籤:follow 視頻編碼 abs surf UI order 螢幕 hold https
本篇項目地址,求start
https://github.com/979451341/Audio-and-video-learning-materials/tree/master/%E5%B0%8F%E8%A7%86%E9%A2%91%E5%BD%95%E5%88%B6
這個項目我覺得厲害,因為之前錄屏用了很多代碼,而這個真正實現錄屏功能的代碼一百行都不到
還有就是關於整個介面UI也做得不錯,但是關於介面如何?的我就不多說了,直接說如何?錄屏的代碼
首先Camera如何給資料SurfaceView,從而在螢幕顯示Camera拍到的東西,這個之前說多了,不在提了
1.錄屏
這一次將視頻資料如何將資料給MediaRecorder,兩行就可以了
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
設定音視頻兩個資料來源的格式
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
設定解析度,顯示螢幕的大小
//設定視頻的解析度
mMediaRecorder.setVideoSize(mProfile.videoFrameWidth, mProfile.videoFrameHeight);
設定編碼的速率
mMediaRecorder.setAudioEncodingBitRate(44100);
if (mProfile.videoBitRate > 2 1024 1024) {
mMediaRecorder.setVideoEncodingBitRate(2 1024 1024);
} else {
mMediaRecorder.setVideoEncodingBitRate(mProfile.videoBitRate);
}
設定視頻播放的幀率
mMediaRecorder.setVideoFrameRate(mProfile.videoFrameRate);
這是音視頻編碼的格式
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
設定輸出檔案的路徑
mMediaRecorder.setOutputFile(mRecordFile.getAbsolutePath());
這項目要說缺陷就是無法在錄屏的時候加特效,但是代碼短,適合一些專門的用途
Android 音視頻深入 八 小視頻錄製(附源碼下載)