2024年10月29日 第22讲 录像使用PersistentInputSurface 极客笔记
本讲是Android Camera性能分析专题的第22讲,我们介绍录像使用PersistInputSurface,包括如下内容:
| 资源 | 描述 | 
|---|---|
| 在线课程 | 极客笔记在线课程 | 
| 知识星球 | 星球名称:深入浅出Android Camera  星球ID: 17296815  | 
| 极客笔记圈 | 
可以分为如下步骤:
Surface persistSurface = MediaCodec.createPersistentInputSurface()
MediaRecorder.setInputSurface(persistSurface)
MediaRecorder.prepare()
createCaptureSession with persist input surface
persistSurface.release()
MediaRecorder.setInputSurface设置给MediaRecorder具体见视频讲解,核心函数如下:
public void copyToMediaRecorder(MediaRecorder media_recorder, boolean slow_motion, Surface persistSurface) {
    if( MyDebug.LOG )
        Log.d(TAG, "copyToMediaRecorder: " + media_recorder + toString());
    if( record_audio && !slow_motion) {
        if( MyDebug.LOG )
            Log.d(TAG, "record audio");
        media_recorder.setAudioSource(this.audioSource);
    }
    media_recorder.setVideoSource(this.videoSource);
    // n.b., order may be important - output format should be first, at least
    // also match order of MediaRecorder.setProfile() just to be safe, see https://stackoverflow.com/questions/5524672/is-it-possible-to-use-camcorderprofile-without-audio-source
    media_recorder.setOutputFormat(this.fileFormat);
    if (slow_motion) {
        media_recorder.setVideoFrameRate(30);
    } else {
        media_recorder.setVideoFrameRate(this.videoFrameRate);
    }
    media_recorder.setCaptureRate(this.videoCaptureRate);
    media_recorder.setVideoSize(this.videoFrameWidth, this.videoFrameHeight);
    media_recorder.setVideoEncodingBitRate(this.videoBitRate);
    media_recorder.setVideoEncoder(this.videoCodec);
    if( record_audio && !slow_motion) {
        media_recorder.setAudioEncodingBitRate(this.audioBitRate);
        media_recorder.setAudioChannels(this.audioChannels);
        media_recorder.setAudioSamplingRate(this.audioSampleRate);
        media_recorder.setAudioEncoder(this.audioCodec);
    }
    if( MyDebug.LOG )
        Log.d(TAG, "done: " + media_recorder);
    if (persistSurface != null) {
        media_recorder.setInputSurface(persistSurface);
    }
}
注意,使用Persistent Input Surface后不能再从MediaRecorder去getSurface()了。
从GeekCamera App的进程我们能看到GraphicBufferSource的Trace

本文链接:http://so.lmcjl.com/news/16525/