How to record video and audio with MediaCodec and MediaMuxer

自古美人都是妖i 提交于 2019-12-08 22:03:36

问题


I am able to record(encode) video with the help of MediaCodec and MediaMuxer. Next, I need to work on audio part and mux audio with video with help of MediaCodec and MediaMuxer.

I am facing two problems:

  1. How to encode audio with MediaCodec. Do I need to encode audio and video in separate threads?

  2. How can I pass audio and video data to MediaMuxer (as writeSampleData() method takes only one type of data at a time)?

I referred to MediaMuxerTest but it is using MediaExtractor. I need to use MediaCodec as video encoding is done with MediaCodec. Please correct me if I am wrong.

Any suggestion or advice will be very helpful as there is no proper documentation available for these new APIs.

Note:

  1. My app is targeting to API 18+ (Android 4.3+).
  2. I have referred Grafika for video encoding.

回答1:


  1. No, you don't necessarily need a separate thread for audio, just use two separate MediaCodec instances.

  2. The first parameter of writeSampleData is trackIndex, which allows you to specify which track each packet corresponds to. (By running addTrack twice, once for each track, you get two separate track IDs.)



来源:https://stackoverflow.com/questions/26628677/how-to-record-video-and-audio-with-mediacodec-and-mediamuxer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!