本文整理汇总了Java中android.media.MediaFormat.setInteger方法的典型用法代码示例。如果您正苦于以下问题:Java MediaFormat.setInteger方法的具体用法?Java MediaFormat.setInteger怎么用?Java MediaFormat.setInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaFormat
的用法示例。
在下文中一共展示了MediaFormat.setInteger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: VideoEncoderCore
import android.media.MediaFormat; //导入方法依赖的package包/类
/**
* Configures encoder and muxer state, and prepares the input Surface.
*/
public VideoEncoderCore(int width, int height, int bitRate, MMediaMuxer MMediaMuxer)
throws IOException {
super(MMediaMuxer);
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height);
// Set some properties. Failing to specify some of these can cause the MediaCodec
// configure() call to throw an unhelpful exception.
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, calcBitRate(width,height));
format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
if (VERBOSE) Log.d(TAG, "format: " + format);
// Create a MediaCodec encoder, and configure it with our format. Get a Surface
// we can use for input and wrap it with a class that handles the EGL work.
mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mInputSurface = mEncoder.createInputSurface();
mEncoder.start();
}
示例2: getVideoMediaCodec
import android.media.MediaFormat; //导入方法依赖的package包/类
@TargetApi(21)
public static MediaCodec getVideoMediaCodec() {
int videoWidth = getVideoSize(Options.getInstance().video.width);
int videoHeight = getVideoSize(Options.getInstance().video.height);
MediaFormat format = MediaFormat.createVideoFormat(Options.getInstance().video.mime, videoWidth, videoHeight);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, Options.getInstance().video.maxBps* 1024);
int fps = Options.getInstance().video.fps;
//设置摄像头预览帧率
// if(BlackListHelper.deviceInFpsBlacklisted()) {
// SopCastLog.d(SopCastConstant.TAG, "Device in fps setting black list, so set mediacodec fps 15");
// fps = 15;
// }
format.setInteger(MediaFormat.KEY_FRAME_RATE, fps);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, Options.getInstance().video.ifi);
format.setInteger(MediaFormat.KEY_BITRATE_MODE, MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_VBR);
format.setInteger(MediaFormat.KEY_COMPLEXITY, MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_CBR);
MediaCodec mediaCodec = null;
try {
mediaCodec = MediaCodec.createEncoderByType(Options.getInstance().video.mime);
mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
}catch (Exception e) {
e.printStackTrace();
if (mediaCodec != null) {
mediaCodec.stop();
mediaCodec.release();
mediaCodec = null;
}
}
return mediaCodec;
}
示例3: configureDecoder
import android.media.MediaFormat; //导入方法依赖的package包/类
private static MediaCodec configureDecoder(ImageInfo info, int maxInputSize, Surface surface) {
if (mDecoderSupportedSize.getWidth() < info.size.getWidth() || mDecoderSupportedSize.getHeight() < info.size.getHeight()) {
Log.w(TAG, "HEVC image may exceed decoder capability");
}
try {
MediaCodec decoder = MediaCodec.createByCodecName(mDecoderName);
MediaFormat inputFormat = MediaFormat.createVideoFormat(
MediaFormat.MIMETYPE_VIDEO_HEVC, info.size.getWidth(), info.size.getHeight());
inputFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
inputFormat.setByteBuffer("csd-0", info.paramset);
Log.d(TAG, "HEVC input-format=" + inputFormat);
decoder.configure(inputFormat, surface, null, 0);
return decoder;
} catch (IOException ex) {
throw new RuntimeException("no HEVC decoding support");
}
}
示例4: createMediaCodecFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
private MediaFormat createMediaCodecFormat(int colorFmt, int width, int height, Integer profile, Integer level){
String mime = mEncodeFormat.getValue(); // "video/avc"
MediaFormat mediaFormat = MediaFormat.createVideoFormat(mime, width, height);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFmt);
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
mediaFormat.setFloat(MediaFormat.KEY_FRAME_RATE, (float) mFrameRate*1.0f);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, mIFrameInterval);
if(null != profile)
{
//mediaFormat.setInteger(MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileHigh);
mediaFormat.setInteger(MediaFormat.KEY_PROFILE, profile.intValue());
}
if(null != level)
{
//mediaFormat.setInteger(MediaFormat.KEY_LEVEL, MediaCodecInfo.CodecProfileLevel.AVCLevel4);
//mediaFormat.setInteger(MediaFormat.KEY_LEVEL, level.intValue());
}
return mediaFormat;
}
示例5: createMediaFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static MediaFormat createMediaFormat(Type type, int sampleRate) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
MediaFormat format = new MediaFormat();
// TODO: this causes a crash in MediaCodec.configure
//format.setString(MediaFormat.KEY_FRAME_RATE, null);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, sampleRate);
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
if (type == Type.AAC) {
format.setString(MediaFormat.KEY_MIME, "audio/mp4a-latm");
format.setInteger(MediaFormat.KEY_AAC_PROFILE, 2); // TODO: or 39?
format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
} else if (type == Type.FLAC) {
//format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_AUDIO_FLAC); // API=21
format.setString(MediaFormat.KEY_MIME, "audio/flac");
format.setInteger(MediaFormat.KEY_BIT_RATE, 64000);
//TODO: use another bit rate, does not seem to have effect always
//format.setInteger(MediaFormat.KEY_BIT_RATE, 128000);
} else {
format.setString(MediaFormat.KEY_MIME, "audio/amr-wb");
format.setInteger(MediaFormat.KEY_BIT_RATE, 23050);
}
return format;
}
return null;
}
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:27,代码来源:MediaFormatFactory.java
示例6: to
import android.media.MediaFormat; //导入方法依赖的package包/类
/** Create a {@link MpegEncoder} from this {@link Builder}. */
@NonNull
public final MpegEncoder to(@NonNull String path, int width, int height) {
final MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE,
calcBitRate(width * height, mFPS, mMotion));
format.setInteger(MediaFormat.KEY_FRAME_RATE, mFPS);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, mIFrame);
try {
return new MpegEncoder(this, format, path);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
示例7: convertVideoConfigToFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
protected MediaFormat convertVideoConfigToFormat(MediaConfig.Video config){
MediaFormat format=MediaFormat.createVideoFormat(config.mime,config.width,config.height);
format.setInteger(MediaFormat.KEY_BIT_RATE,config.bitrate);
format.setInteger(MediaFormat.KEY_FRAME_RATE,config.frameRate);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL,config.iframe);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
return format;
}
示例8: prepareEncoder
import android.media.MediaFormat; //导入方法依赖的package包/类
private void prepareEncoder() throws IOException {
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
RecordScreenLogUtil.i(TAG, "created video format: " + format);
mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mSurface = mEncoder.createInputSurface();
mEncoder.start();
}
示例9: getAudioMediaCodec
import android.media.MediaFormat; //导入方法依赖的package包/类
@TargetApi(18)
public static MediaCodec getAudioMediaCodec(){
MediaFormat format = MediaFormat.createAudioFormat(
Options.getInstance().audio.mime,
Options.getInstance().audio.frequency,
Options.getInstance().audio.channelCount);
if(Options.getInstance().audio.mime.equals(Options.DEFAULT_MIME)) {
format.setInteger(MediaFormat.KEY_AAC_PROFILE, Options.getInstance().audio.aacProfile);
}
format.setInteger(MediaFormat.KEY_BIT_RATE, Options.getInstance().audio.maxBps * 1024);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, Options.getInstance().audio.frequency);
int maxInputSize = getRecordBufferSize();
format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, Options.getInstance().audio.channelCount);
MediaCodec mediaCodec = null;
try {
mediaCodec = MediaCodec.createEncoderByType(Options.getInstance().audio.mime);
mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
} catch (Exception e) {
e.printStackTrace();
if (mediaCodec != null) {
mediaCodec.stop();
mediaCodec.release();
mediaCodec = null;
}
}
return mediaCodec;
}
示例10: clickStart
import android.media.MediaFormat; //导入方法依赖的package包/类
/**
* onClick handler for "start" button.
*
* We create as many codecs as we can and return without releasing them. The codecs
* will remain in use until the next GC.
*/
public void clickStart(@SuppressWarnings("unused") View unused) {
final String MIME_TYPE = "video/avc";
final int WIDTH = 320;
final int HEIGHT = 240;
final int BIT_RATE = 1000000;
final int FRAME_RATE = 15;
final int IFRAME_INTERVAL = 1;
final boolean START_CODEC = true;
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, WIDTH, HEIGHT);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
Log.d(TAG, "format: " + format);
MediaCodec[] codecs = new MediaCodec[MAX_OPEN];
int i;
for (i = 0; i < MAX_OPEN; i++) {
try {
codecs[i] = MediaCodec.createEncoderByType(MIME_TYPE);
codecs[i].configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
if (START_CODEC) {
codecs[i].createInputSurface();
codecs[i].start();
}
} catch (Exception ex) {
Log.i(TAG, "Failed on creation of codec #" + i, ex);
break;
}
}
showCountDialog(i);
}
示例11: createAudioOutputFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
@Override
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
if (mAudioBitrate == AUDIO_BITRATE_AS_IS || mAudioChannels == AUDIO_CHANNELS_AS_IS) return null;
// Use original sample rate, as resampling is not supported yet.
final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC,
inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), mAudioChannels);
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitrate);
return format;
}
示例12: prepareEncoder
import android.media.MediaFormat; //导入方法依赖的package包/类
/**
* Prepares the video encoder, muxer, and an input surface.
*/
private void prepareEncoder(File outputFile) throws IOException {
mBufferInfo = new MediaCodec.BufferInfo();
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, WIDTH, HEIGHT);
// Set some properties. Failing to specify some of these can cause the MediaCodec
// configure() call to throw an unhelpful exception.
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAMES_PER_SECOND);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
if (VERBOSE) Log.d(TAG, "format: " + format);
// Create a MediaCodec encoder, and configure it with our format. Get a Surface
// we can use for input and wrap it with a class that handles the EGL work.
mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mInputSurface = mEncoder.createInputSurface();
mEncoder.start();
// Create a MediaMuxer. We can't add the video track and start() the muxer here,
// because our MediaFormat doesn't have the Magic Goodies. These can only be
// obtained from the encoder after it has started processing data.
//
// We're not actually interested in multiplexing audio. We just want to convert
// the raw H.264 elementary stream we get from MediaCodec into a .mp4 file.
if (VERBOSE) Log.d(TAG, "output will go to " + outputFile);
mMuxer = new MediaMuxer(outputFile.toString(),
MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mTrackIndex = -1;
mMuxerStarted = false;
}
示例13: createVideoMediaFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
public MediaFormat createVideoMediaFormat() {
MediaFormat format = MediaFormat.createVideoFormat(videoMIMEType, width, height);
// Set some properties. Failing to specify some of these can cause the MediaCodec
// configure() call to throw an unhelpful exception.
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, videoBitRate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, iframeInterval);
return format;
}
示例14: VideoEncoderCore
import android.media.MediaFormat; //导入方法依赖的package包/类
/**
* Configures encoder and muxer state, and prepares the input Surface.
*/
public VideoEncoderCore(int width, int height, int bitRate, File outputFile)
throws IOException {
mBufferInfo = new MediaCodec.BufferInfo();
MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, width, height);
// Set some properties. Failing to specify some of these can cause the MediaCodec
// configure() call to throw an unhelpful exception.
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
if (VERBOSE) Log.d(TAG, "format: " + format);
// Create a MediaCodec encoder, and configure it with our format. Get a Surface
// we can use for input and wrap it with a class that handles the EGL work.
mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mInputSurface = mEncoder.createInputSurface();
mEncoder.start();
// Create a MediaMuxer. We can't add the video track and start() the muxer here,
// because our MediaFormat doesn't have the Magic Goodies. These can only be
// obtained from the encoder after it has started processing data.
//
// We're not actually interested in multiplexing audio. We just want to convert
// the raw H.264 elementary stream we get from MediaCodec into a .mp4 file.
mMuxer = new MediaMuxer(outputFile.toString(),
MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
mTrackIndex = -1;
mMuxerStarted = false;
}
示例15: processOutputFormat
import android.media.MediaFormat; //导入方法依赖的package包/类
/**
* Processes a new output format.
*/
private void processOutputFormat() throws ExoPlaybackException {
MediaFormat format = codec.getOutputFormat();
if (codecNeedsAdaptationWorkaround
&& format.getInteger(MediaFormat.KEY_WIDTH) == ADAPTATION_WORKAROUND_SLICE_WIDTH_HEIGHT
&& format.getInteger(MediaFormat.KEY_HEIGHT) == ADAPTATION_WORKAROUND_SLICE_WIDTH_HEIGHT) {
// We assume this format changed event was caused by the adaptation workaround.
shouldSkipAdaptationWorkaroundOutputBuffer = true;
return;
}
if (codecNeedsMonoChannelCountWorkaround) {
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
}
onOutputFormatChanged(codec, format);
}