如何提供音频数据和视频数据以MediaMux [英] How to provide both audio data and video data to MediaMux

查看:712
本文介绍了如何提供音频数据和视频数据以MediaMux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让被preVIEW视频的原始数据,通过AudioRecord获取音频原始数据。然后,我会送他们到媒体codeC(我将设置两个codeC实例)。从那以后,我将视频数据和音频数据发送到 MediaMux 得到一个MP4文件。我有两个问题:

I'm trying to get video raw data by Preview, get audio raw data by AudioRecord. Then I will send them to MediaCodec(I will set two Codec instance). After that I will send the video data and audio data to MediaMux to get a mp4 file. I have two questions:

1)我用MediaMux之前处理的视频数据。对于视频数据,通过帧MediaMux处理它,但视频记录是连续的。该MediaMux怎么能处理的同步视频和音频。

1) I've used MediaMux to process the video data before. For video data, the MediaMux process it by frame, but the video record is continuous. How could the MediaMux handle the video and audio in synchronization.

2)我发现只有变量在函数 writeSampleData 。在计算器上一个好人还提供了一个演示<一个href=\"https://android.googlesource.com/platform/cts/+/kitkat-release/tests/tests/media/src/android/media/cts/MediaMuxerTest.java\"相对=nofollow> MediaMux 。但是,这个演示只有源数据的一个变量。这一个变量怎么能忍受这两个视频数据和音频数据?

2) I found only of variable for inputbuffer in the function writeSampleData. A nice guy on StackOverflow also provided a demo of MediaMux. But this demo only has one variable for source data. How could this one variable stand both video data and audio data?

感谢您!

推荐答案

我已经取得了一些成功,通过同步音频和视频 MediaMuxer 。我计算音频样本应当为每个视频帧播放数目:基于所述音频取样率和视频帧率。然后,我有一个循环,写了一个视频帧,并在每次迭代音频一块。使用presentation时间,以确保他们将播放同步。使用从 addTrack 在通话跟踪指数 writeSampleData 来允许写入的视频和音频两个不同的轨道。

I have had some success passing synced audio and video to MediaMuxer. I calculated the number of audio samples that should play for each frame of video: based on the audio sample rate and the video frame rate. I then had a loop that wrote one video frame and one block of audio in each iteration. Use the presentation time to ensure they will be synced on playback. Use the track index from addTrack in calls to writeSampleData to allow writing video and audio to two separate tracks.

这篇关于如何提供音频数据和视频数据以MediaMux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆