[英]How to record video and audio with MediaCodec and MediaMuxer
I am able to record(encode) video with the help of MediaCodec and MediaMuxer. 我可以在MediaCodec和MediaMuxer的帮助下录制(编码)视频。 Next, I need to work on audio part and mux audio with video with help of MediaCodec and MediaMuxer.
接下来,我需要借助MediaCodec和MediaMuxer在视频上处理音频部分和多路复用音频。
I am facing two problems: 我面临两个问题:
How to encode audio with MediaCodec. 如何使用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)? 如何将音频和视频数据传递给MediaMuxer(因为writeSampleData()方法一次只接收一种类型的数据)?
I referred to MediaMuxerTest but it is using MediaExtractor. 我提到了MediaMuxerTest,但它使用的是MediaExtractor。 I need to use MediaCodec as video encoding is done with MediaCodec.
我需要使用MediaCodec,因为视频编码是使用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. 任何建议或建议都将非常有用,因为没有适用于这些新API的文档。
Note: 注意:
No, you don't necessarily need a separate thread for audio, just use two separate MediaCodec instances. 不,您不一定需要单独的音频线程,只需使用两个单独的MediaCodec实例。
The first parameter of writeSampleData
is trackIndex
, which allows you to specify which track each packet corresponds to. writeSampleData
的第一个参数是trackIndex
,它允许您指定每个数据包对应的轨道。 (By running addTrack
twice, once for each track, you get two separate track IDs.) (通过运行
addTrack
两次,每个轨道一次,您将获得两个单独的轨道ID。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.