问题
I came a across a bug, mostly present on samsung devices. I record a video with media recorder (code shown below). It worked flawlessly, on all devices, but now on some Android Devices the Audio and Video track are separated.
Say I'm capturing 5 sec of Video. The Video will be 5 sec long, playing the video will play the first frame of the video and the 5 secs of Audio. After that, the 5 secs of Video are being played. The default video player shows that the video is over after 5 sec, but in fact its only the audio...
Is there anything newly introduced to 8.0 Oreo, so that I have to adapt my MediaRecorder?
My media recorder setup:
private void SetUpMediaRecorder()
{
MediaRecorder.SetAudioSource(AudioSource.Mic);
MediaRecorder.SetVideoSource(VideoSource.Surface);
MediaRecorder.SetOutputFormat(OutputFormat.Mpeg4);
MediaRecorder.SetVideoEncoder(VideoEncoder.H264);
MediaRecorder.SetAudioEncoder(AudioEncoder.Aac);
MediaRecorder.SetOutputFile(outputURL);
MediaRecorder.SetVideoSize(1280, 720);
MediaRecorder.SetVideoFrameRate(30);
MediaRecorder.SetVideoEncodingBitRate(2000000);
MediaRecorder.SetMaxDuration(VideoManager.MAX_VIDEODURATION_MS);
//Set audio bitrate
int bitDepth = 16;
int sampleRate = 44100;
int bitRate = sampleRate * bitDepth;
MediaRecorder.SetAudioEncodingBitRate(bitRate);
MediaRecorder.SetAudioSamplingRate(sampleRate);
int rotation = (int)ThisActivity.WindowManager.DefaultDisplay.Rotation;
int orientation = orientations[rotation];
MediaRecorder.SetOrientationHint(orientation);
MediaRecorder.Prepare();
}
EDIT: I'm using the Camera2 API
EDIT2: It seems to be an issue for some samsung devices. The deep sleep will cause the presentation timestamp of the first frame to be too long. Setting the timestamp to 1/30th of a second (if your video was captured at 30fps) will fix this issue. Here is a corresponding bug thread: https://github.com/googlesamples/android-Camera2Video/issues/24
来源:https://stackoverflow.com/questions/51079648/android-mediarecorder-video-audio-and-video-track-playing-subsequently