媒体编解码器vs媒体播放器和媒体记录器 [英] mediacodec vs mediaplayer and mediarecorder

查看:105
本文介绍了媒体编解码器vs媒体播放器和媒体记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何在Android中播放和录制视频/音频有些困惑.我不太了解在什么情况下应该使用这些类:

I'm a bit confused about how to play and record video/audio in Android. I don't really understand in what situations one should use these classes:

-播放:MediaPlayer vs MediaExtractor + MediaCodec

-To play: MediaPlayer vs MediaExtractor + MediaCodec

-要记录:MediaRecorder vs MediaCodec + MediaMuxer

-To record: MediaRecorder vs MediaCodec + MediaMuxer

我什么时候必须使用其中一个? 抱歉,如果这是一个重复的问题,我认为这应该是一个常见的问题,但我还没有找到任何问题.

When do I have to use one or the others? Sorry if it's a repeated question, I think it should be a common one but I haven't found any.

推荐答案

如果高级界面(MediaPlayer,MediaRecorder)可以执行您想要的操作(将视频从系统支持的格式播放到显示器,或录制视频(从摄像机复制到文件中),您可能应该只使用它们,它会简单得多.

If the high level interfaces (MediaPlayer, MediaRecorder) can do what you want (play back video from a format that the system supports to the display, or record video from the camera into a file), you should probably just use them, it will be much much simpler.

如果您想进行更多自定义操作,则当您发现要修改的链的一部分隐藏在高级类中时,您将继续进行下级操作.例如.对于MediaExtractor;如果您只想从文件中提取数据包,而不是立即解码并显示/播放它们,则需要使用MediaExtractor.如果要从系统本身不支持的其他来源接收数据包,则需要使用没有MediaExtractor的MediaCodec.同样,如果您想录制摄像机以外的内容,或者将输出内容写入MediaRecorder支持的文件之外的其他位置,则需要直接使用MediaCodec而不是MediaRecorder.

If you want to do something more custom, when you notice that the part of the chain that you want to modify is hidden inside the high level classes, you'll want to move on to the lower level ones. E.g. for MediaExtractor; if you only want to extract packets of data from a file but not decode and display/play them back them immediately, you'll want to use MediaExtractor. If you want to receive packets from some other source that the system itself doesn't support, you'll want to use MediaCodec without MediaExtractor. Likewise, if you want to record something else than the camera, or write the output somewhere else than to a file that MediaRecorder supports, you'll want to use MediaCodec directly instead of MediaRecorder.

还请注意,较高级别的类还可以通过使用较新的API版本来改善并变得更加灵活,从而允许您执行以前需要手动使用较低级别的类的操作.例如.在Android 5.0中,MediaRecorder可以从自定义的Surface进行录制,从而使您可以录制自己渲染的视频,而不仅仅是摄像机.从4.3开始,通过使用较低级别的类就可以做到这一点.

Also note that the high level classes also improve and get more flexible with newer API versions, allowing you to do things that previously required you to manually use the lower level classes. E.g. in Android 5.0, MediaRecorder got the ability to record from a custom Surface, allowing you to record a video of something you render yourself, not just the camera. This was previously possible since 4.3 by using the lower level classes.

这篇关于媒体编解码器vs媒体播放器和媒体记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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