Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

video capture - Android Camera2 + MediaCodec + MediaMuxer using persistent surface?

I'm writing a video camera app. When I open my capture activity I would like to configure a camera capture session that starts a preview, and when the user later presses the record button it should start recording video using MediaCodec + MediaMuxer (not MediaRecorder for app-specific reasons) without having to recreate a new CameraCaptureSession. I tried using MediaCodec#createPersistentInputSurface to make this possible.

So far I have got the preview working and the MediaCodec/MediaMuxer bit is producing a 'valid' output video file (as per ffprobe), but the content of the video is flashes of random diagonal colours/scrambled. On another device the same code fails to create the capture session at all. I believe the problem is that I am creating the MediaCodec instance after creating the capture session, meaning that when the camera is configured with the persistent surface it has no idea what output size and colour format it should be using.

My question: What pipeline do I need to follow in order to achieve the behaviour I'm looking for with MediaCodec and a persistent input surface?

My notes:

  • As far as I've tested/understood, you can only use a MediaCodec instance once. For the next recording you have to create a new one. So to have only a single camera capture session that allows multiple video recordings, creating a MediaCodec instance after configuring the capture session is required.

  • The same surface must be used for all created MediaCodecs because it is specified in the camera capture session (can deferred surfaces (second bullet point) change this?), hence why it needs to be persistent.

  • The persistent surface needs to be created before the camera capture session, and the MediaCodec would need to configure the persistent surface before the camera capture session is started...

A bit of a chicken and the egg problem. Is there a way to break this cyclic dependency loop?

question from:https://stackoverflow.com/questions/65842243/android-camera2-mediacodec-mediamuxer-using-persistent-surface

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...