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:
How to encode audio with MediaCodec. Do I need to encode audio and video in separate threads?
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:
No, you don't necessarily need a separate thread for audio, just use two separate MediaCodec instances.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With