Reputation: 2289
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:
Upvotes: 7
Views: 3211
Reputation: 13317
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.)
Upvotes: 5