音视频处理涉及到的类api
MediaFormat
官方描述:Encapsulates the information describing the format of media data, be it audio or video. The format of the media data is specified as string/value pairs。added in API level 16。 public final class MediaFormat extends Object。
译文:封装描述媒体数据格式的信息,无论是音频还是视频。 媒体数据的格式被指定为字符串/值对。
MediaMuxer
官方描述:MediaMuxer facilitates muxing elementary streams. Currently MediaMuxer supports MP4, Webm and 3GP file as the output. It also supports muxing B-frames in MP4 since Android Nougat. added in API level 18。public final class MediaMuxer extends Object。
译文:MediaMuxer有助于混合基本流。 目前MediaMuxer支持MP4,Webm和3GP文件作为输出。 自从Android Nougat以来,它还支持MP4中的M帧B帧。
其一般的用法如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25MediaMuxer muxer = new MediaMuxer("temp.mp4", OutputFormat.MUXER_OUTPUT_MPEG_4);
// More often, the MediaFormat will be retrieved from MediaCodec.getOutputFormat()
// or MediaExtractor.getTrackFormat().
MediaFormat audioFormat = new MediaFormat(...);
MediaFormat videoFormat = new MediaFormat(...);
int audioTrackIndex = muxer.addTrack(audioFormat);
int videoTrackIndex = muxer.addTrack(videoFormat);
ByteBuffer inputBuffer = ByteBuffer.allocate(bufferSize);
boolean finished = false;
BufferInfo bufferInfo = new BufferInfo();
muxer.start();
while(!finished) {
// getInputBuffer() will fill the inputBuffer with one frame of encoded
// sample from either MediaCodec or MediaExtractor, set isAudioSample to
// true when the sample is audio data, set up all the fields of bufferInfo,
// and return true if there are no more samples.
finished = getInputBuffer(inputBuffer, isAudioSample, bufferInfo);
if (!finished) {
int currentTrackIndex = isAudioSample ? audioTrackIndex : videoTrackIndex;
muxer.writeSampleData(currentTrackIndex, inputBuffer, bufferInfo);
}
};
muxer.stop();
muxer.release();
Surface
public class Surface extends Object implements Parcelable:Handle onto a raw buffer that is being managed by the screen compositor.A Surface is generally created by or from a consumer of image buffers (such as a SurfaceTexture, MediaRecorder, or Allocation), and is handed to some kind of producer (such as OpenGL, MediaPlayer, or CameraDevice) to draw into.
Note: A Surface acts like a weak reference to the consumer it is associated with. By itself it will not keep its parent consumer from being reclaimed.
(处理由屏幕合成器管理的原始缓冲区。surface通常由图像缓冲区(例如SurfaceTexture,MediaRecorder或Allocation)的使用者创建或从图像缓冲区的消费者创建,并被传递给某种生产者(例如OpenGL,MediaPlayer或CameraDevice)以进行绘制。
注意:Surface表示对与其关联的使用者的弱引用。 它本身不会让其父母消费者不被收回。)