MediaFormat浅析

来源:互联网 发布:淘宝大学靠谱吗 编辑:程序博客网 时间:2024/05/23 00:07
类结构
java.lang.Object
↳ android.media.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.
这个格式有点特殊,是string/value键值对
Keys common to all audio/video formats, all keys not marked optional are mandatory:
键一般是音频/视频这样的格式,所有键都是必须的

关键属性和方法说明
/**
* A key describing the bitrate in bits/sec.
* The associated value is an integer
*/
public static finalString KEY_BIT_RATE= "bitrate";

/**
* A key describing the frame rate of a video format in frames/sec.
* The associated value is an integer or a float.
*/
public static finalString KEY_FRAME_RATE= "frame-rate";

/**
* A key describing the color format of the content in a video format.
* Constants are declared in {@linkandroid.media.MediaCodecInfo.CodecCapabilities}.
*/
public static finalString KEY_COLOR_FORMAT= "color-format";

/**
* A key describing the frequency of I frames expressed in secs
* between I frames.
* The associated value is an integer.
*/
public static finalString KEY_I_FRAME_INTERVAL= "i-frame-interval";

/**
* A key describing the number of channels in an audio format.
* The associated value is an integer
*/
public static finalString KEY_CHANNEL_COUNT= "channel-count";

/**
* A key describing the capture rate of a video format in frames/sec.
*<p>
* When capture rate is different than the frame rate, it means that the
* video is acquired at a different rate than the playback, which produces
* slow motion or timelapse effect during playback. Application can use the
* value of this key to tell the relative speed ratio between capture and
* playback rates when the video was recorded.
*</p>
*<p>
* The associated value is an integer or a float.
*</p>
*/
public static finalString KEY_CAPTURE_RATE= "capture-rate";


/**
* Applies only when configuring a video encoder in "surface-input" mode.
* The associated value is a long and gives the time in microseconds
* after which the frame previously submitted to the encoder will be
* repeated (once) if no new frame became available since.
*/
public static finalString KEY_REPEAT_PREVIOUS_FRAME_AFTER
="repeat-previous-frame-after";


使用实例
MediaFormat mediaFormat = MediaFormat.createVideoFormat("video/avc",windowWidth,windowHeight);
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE,1200000);
mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE,25);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL,1);
mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT,1);
mediaFormat.setInteger(MediaFormat.KEY_CAPTURE_RATE,25);
mediaFormat.setInteger(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER,1000000/ 25);














原创粉丝点击