當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaFormat.setInteger方法代碼示例

本文整理匯總了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();
}
 
開發者ID:zhangyaqiang,項目名稱:Fatigue-Detection,代碼行數:27,代碼來源:VideoEncoderCore.java

示例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;
    }
 
開發者ID:wuyisheng,項目名稱:libRtmp,代碼行數:34,代碼來源:AndroidUntil.java

示例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");
    }
}
 
開發者ID:yohhoy,項目名稱:heifreader,代碼行數:18,代碼來源:HeifReader.java

示例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;
}
 
開發者ID:lzmlsfe,項目名稱:19porn,代碼行數:24,代碼來源:VideoEncoder.java

示例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);
    }
}
 
開發者ID:Nik-Gleb,項目名稱:mpeg-encoder,代碼行數:19,代碼來源:MpegEncoder.java

示例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;
}
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:9,代碼來源:SurfaceEncoder.java

示例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();
}
 
開發者ID:sunshinecoast,項目名稱:ScreenRecordCaptureMaster,代碼行數:13,代碼來源:YixiaScreenEncoder.java

示例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;
}
 
開發者ID:wuyisheng,項目名稱:libRtmp,代碼行數:30,代碼來源:AndroidUntil.java

示例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);
}
 
開發者ID:AndyZhu1991,項目名稱:grafika,代碼行數:43,代碼來源:CodecOpenActivity.java

示例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;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:12,代碼來源:Android720pFormatStrategy.java

示例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;
}
 
開發者ID:AndyZhu1991,項目名稱:grafika,代碼行數:38,代碼來源:SoftInputSurfaceActivity.java

示例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;
}
 
開發者ID:ChillingVan,項目名稱:AndroidInstantVideo,代碼行數:13,代碼來源:StreamPublisher.java

示例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;
}
 
開發者ID:AndyZhu1991,項目名稱:grafika,代碼行數:38,代碼來源:VideoEncoderCore.java

示例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);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:18,代碼來源:MediaCodecRenderer.java


注:本文中的android.media.MediaFormat.setInteger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。