当前位置: 首页>>代码示例>>Java>>正文


Java MediaExtractor.getTrackFormat方法代码示例

本文整理汇总了Java中android.media.MediaExtractor.getTrackFormat方法的典型用法代码示例。如果您正苦于以下问题:Java MediaExtractor.getTrackFormat方法的具体用法?Java MediaExtractor.getTrackFormat怎么用?Java MediaExtractor.getTrackFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaExtractor的用法示例。


在下文中一共展示了MediaExtractor.getTrackFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: selectTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
private MediaFormat selectTrack(MediaExtractor extractor) {
    int trackCount = extractor.getTrackCount();
    Log.d(TAG, "trackCount :" + trackCount);

    MediaFormat format;
    for (int i = 0; i < trackCount; i++) {
        extractor.selectTrack(i);
        format = extractor.getTrackFormat(i);
        Log.d(TAG, "Track media format :" + format.toString());

        String mime = format.getString(MediaFormat.KEY_MIME);
        if (mime.startsWith("video/")) {
            return format;
        }
    }

    return null;
}
 
开发者ID:ficklerobot,项目名称:grid-video-viewer,代码行数:19,代码来源:DecodeThread.java

示例2: selectTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
@TargetApi(16)
private int selectTrack(MediaExtractor extractor, boolean audio) {
    int numTracks = extractor.getTrackCount();
    for (int i = 0; i < numTracks; i++) {
        MediaFormat format = extractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (audio) {
            if (mime.startsWith("audio/")) {
                return i;
            }
        } else {
            if (mime.startsWith("video/")) {
                return i;
            }
        }
    }
    return -5;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:19,代码来源:MediaController.java

示例3: getFirstVideoAndAudioTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
public static TrackResult getFirstVideoAndAudioTrack(MediaExtractor extractor) {
    TrackResult trackResult = new TrackResult();
    trackResult.mVideoTrackIndex = -1;
    trackResult.mAudioTrackIndex = -1;
    int trackCount = extractor.getTrackCount();
    for (int i = 0; i < trackCount; i++) {
        MediaFormat format = extractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (trackResult.mVideoTrackIndex < 0 && mime.startsWith("video/")) {
            trackResult.mVideoTrackIndex = i;
            trackResult.mVideoTrackMime = mime;
            trackResult.mVideoTrackFormat = format;
        } else if (trackResult.mAudioTrackIndex < 0 && mime.startsWith("audio/")) {
            trackResult.mAudioTrackIndex = i;
            trackResult.mAudioTrackMime = mime;
            trackResult.mAudioTrackFormat = format;
        }
        if (trackResult.mVideoTrackIndex >= 0 && trackResult.mAudioTrackIndex >= 0) break;
    }
    if (trackResult.mVideoTrackIndex < 0 || trackResult.mAudioTrackIndex < 0) {
        throw new IllegalArgumentException("extractor does not contain video and/or audio tracks.");
    }
    return trackResult;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:25,代码来源:MediaExtractorUtils.java

示例4: selectTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * Selects the video track, if any.
 *
 * @return the track index, or -1 if no video track is found.
 */
private static int selectTrack(MediaExtractor extractor) {
    // Select the first video track we find, ignore the rest.
    int numTracks = extractor.getTrackCount();
    for (int i = 0; i < numTracks; i++) {
        MediaFormat format = extractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (mime.startsWith("video/")) {
            if (VERBOSE) {
                Log.d(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
            }
            return i;
        }
    }

    return -1;
}
 
开发者ID:AndyZhu1991,项目名称:grafika,代码行数:22,代码来源:MoviePlayer.java

示例5: initExtractor

import android.media.MediaExtractor; //导入方法依赖的package包/类
public boolean initExtractor(String filePath) throws IOException {
  decoding = false;
  audioExtractor = new MediaExtractor();
  audioExtractor.setDataSource(filePath);
  for (int i = 0; i < audioExtractor.getTrackCount() && !mime.startsWith("audio/"); i++) {
    audioFormat = audioExtractor.getTrackFormat(i);
    mime = audioFormat.getString(MediaFormat.KEY_MIME);
    if (mime.startsWith("audio/")) {
      audioExtractor.selectTrack(i);
    } else {
      audioFormat = null;
    }
  }
  if (audioFormat != null && mime.equals("audio/mp4a-latm")) {
    isStereo = (audioFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT) == 2);
    sampleRate = audioFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
    return true;
    //audio decoder not supported
  } else {
    mime = "";
    audioFormat = null;
    return false;
  }
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:25,代码来源:AudioDecoder.java

示例6: initExtractor

import android.media.MediaExtractor; //导入方法依赖的package包/类
public boolean initExtractor(String filePath) throws IOException {
  decoding = false;
  videoExtractor = new MediaExtractor();
  videoExtractor.setDataSource(filePath);
  for (int i = 0; i < videoExtractor.getTrackCount() && !mime.startsWith("video/"); i++) {
    videoFormat = videoExtractor.getTrackFormat(i);
    mime = videoFormat.getString(MediaFormat.KEY_MIME);
    if (mime.startsWith("video/")) {
      videoExtractor.selectTrack(i);
    } else {
      videoFormat = null;
    }
  }
  if (videoFormat != null && mime.equals("video/avc")) {
    width = videoFormat.getInteger(MediaFormat.KEY_WIDTH);
    height = videoFormat.getInteger(MediaFormat.KEY_HEIGHT);
    return true;
    //video decoder not supported
  } else {
    mime = "";
    videoFormat = null;
    return false;
  }
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:25,代码来源:VideoDecoder.java

示例7: retrieveFrameRate

import android.media.MediaExtractor; //导入方法依赖的package包/类
public int retrieveFrameRate() {
    MediaExtractor extractor = new MediaExtractor();
    int frameRate = -1;
    try {
        //Adjust data source as per the requirement if file, URI, etc.
        extractor.setDataSource(getPath());
        int numTracks = extractor.getTrackCount();
        for (int i = 0; i < numTracks; i++) {
            MediaFormat format = extractor.getTrackFormat(i);
            if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
                frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        //Release stuff
        extractor.release();
    }
    return frameRate;
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:22,代码来源:Video.java

示例8: getDuration

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * 获取视频信息
 *
 * @param url
 * @return
 */
public static long getDuration(String url) {
	try {
		MediaExtractor mediaExtractor = new MediaExtractor();
		mediaExtractor.setDataSource(url);
		int videoExt = TrackUtils.selectVideoTrack(mediaExtractor);
		if(videoExt == -1){
			videoExt = TrackUtils.selectAudioTrack(mediaExtractor);
			if(videoExt == -1){
				return 0;
			}
		}
		MediaFormat mediaFormat = mediaExtractor.getTrackFormat(videoExt);
		long res = mediaFormat.containsKey(MediaFormat.KEY_DURATION) ? mediaFormat.getLong(MediaFormat.KEY_DURATION) : 0;//时长
		mediaExtractor.release();
		return res;
	} catch (Exception e) {
		return 0;
	}
}
 
开发者ID:yangjie10930,项目名称:EpMedia,代码行数:26,代码来源:VideoUitls.java

示例9: handlePrepare

import android.media.MediaExtractor; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected int handlePrepare(MediaExtractor media_extractor) {
	int track_index = selectTrack(media_extractor, "audio/");
	if (track_index >= 0) {
		final MediaFormat format = media_extractor.getTrackFormat(track_index);
		mAudioChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
		mAudioSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
		final int min_buf_size = AudioTrack.getMinBufferSize(mAudioSampleRate,
				(mAudioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
				AudioFormat.ENCODING_PCM_16BIT);
		final int max_input_size = format.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE);
		mAudioInputBufSize =  min_buf_size > 0 ? min_buf_size * mAudioChannels * 2 : max_input_size;
		if (mAudioInputBufSize > max_input_size) mAudioInputBufSize = max_input_size;
		final int frameSizeInBytes = mAudioChannels * 2;
		mAudioInputBufSize = (mAudioInputBufSize / frameSizeInBytes) * frameSizeInBytes;
		if (DEBUG) Log.v(TAG, String.format("getMinBufferSize=%d,max_input_size=%d,mAudioInputBufSize=%d",min_buf_size, max_input_size, mAudioInputBufSize));
	}
	return track_index;
}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:21,代码来源:MediaAudioDecoder.java

示例10: internal_start_video

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * @param media_extractor
 * @param trackIndex
 * @return
 */
protected MediaCodec internal_start_video(final MediaExtractor media_extractor, final int trackIndex) {
	if (DEBUG) Log.v(TAG, "internal_start_video:");
	MediaCodec codec = null;
	if (trackIndex >= 0) {
        final MediaFormat format = media_extractor.getTrackFormat(trackIndex);
        final String mime = format.getString(MediaFormat.KEY_MIME);
		try {
			codec = MediaCodec.createDecoderByType(mime);
			codec.configure(format, mOutputSurface, null, 0);
	        codec.start();
			if (DEBUG) Log.v(TAG, "internal_start_video:codec started");
		} catch (final IOException e) {
			Log.w(TAG, e);
		}
	}
	return codec;
}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:23,代码来源:MediaMoviePlayer.java

示例11: internal_start_audio

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * @param media_extractor
 * @param trackIndex
 * @return
 */
protected MediaCodec internal_start_audio(final MediaExtractor media_extractor, final int trackIndex) {
	if (DEBUG) Log.v(TAG, "internal_start_audio:");
	MediaCodec codec = null;
	if (trackIndex >= 0) {
        final MediaFormat format = media_extractor.getTrackFormat(trackIndex);
        final String mime = format.getString(MediaFormat.KEY_MIME);
		try {
			codec = MediaCodec.createDecoderByType(mime);
			codec.configure(format, null, null, 0);
	        codec.start();
	    	if (DEBUG) Log.v(TAG, "internal_start_audio:codec started");
	    	//
	        final ByteBuffer[] buffers = codec.getOutputBuffers();
	        int sz = buffers[0].capacity();
	        if (sz <= 0)
	        	sz = mAudioInputBufSize;
	        if (DEBUG) Log.v(TAG, "AudioOutputBufSize:" + sz);
	        mAudioOutTempBuf = new byte[sz];
		} catch (final IOException e) {
			Log.w(TAG, e);
		}
	}
	return codec;
}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:30,代码来源:MediaMoviePlayer.java

示例12: selectTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * search first track index matched specific MIME
 * @param extractor
 * @param mimeType "video/" or "audio/"
 * @return track index, -1 if not found
 */
protected static final int selectTrack(final MediaExtractor extractor, final String mimeType) {
    final int numTracks = extractor.getTrackCount();
    MediaFormat format;
    String mime;
    for (int i = 0; i < numTracks; i++) {
        format = extractor.getTrackFormat(i);
        mime = format.getString(MediaFormat.KEY_MIME);
        if (mime.startsWith(mimeType)) {
            if (DEBUG) {
                Log.d(TAG_STATIC, "Extractor selected track " + i + " (" + mime + "): " + format);
            }
            return i;
        }
    }
    return -1;
}
 
开发者ID:saki4510t,项目名称:libcommon,代码行数:23,代码来源:MediaMoviePlayer.java

示例13: selectTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * Selects the video track, if any.
 *
 * @return the track index, or -1 if no video track is found.
 */
private static int selectTrack(MediaExtractor extractor) {
  // Select the first video track we find, ignore the rest.
  int numTracks = extractor.getTrackCount();
  for (int i = 0; i < numTracks; i++) {
    MediaFormat format = extractor.getTrackFormat(i);
    String mime = format.getString(MediaFormat.KEY_MIME);
    if (mime.startsWith("video/")) {
      if (VERBOSE) {
        Log.d(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
      }
      return i;
    }
  }

  return -1;
}
 
开发者ID:Eric-Gonzalez,项目名称:marclay,代码行数:22,代码来源:MoviePlayer.java

示例14: selectTrack

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * Selects the video track, if any.
 *
 * @return the track index, or -1 if no video track is found.
 */
private int selectTrack(MediaExtractor extractor) {
    // Select the first video track we find, ignore the rest.
    int numTracks = extractor.getTrackCount();
    for (int i = 0; i < numTracks; i++) {
        MediaFormat format = extractor.getTrackFormat(i);
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (mime.startsWith("video/")) {
            if (VERBOSE) {
                Log.d(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
            }
            return i;
        }
    }

    return -1;
}
 
开发者ID:PhilLab,项目名称:Android-MediaCodec-Examples,代码行数:22,代码来源:ExtractMpegFramesTest.java

示例15: concatVideoListFromMediaCodec

import android.media.MediaExtractor; //导入方法依赖的package包/类
private static void concatVideoListFromMediaCodec(List<String> pathList,
                                                  String destinationVideoFilePath, int videoRotation,
                                                  ConcatMediaCallback concatMediaCallback) throws IOException {
  MediaExtractor extractor = new MediaExtractor();
  MediaFormat format = null;
  extractor.setDataSource(pathList.get(0));
  int numTracks = extractor.getTrackCount();
  // find and select the first audio track present in the file.
  for (int i = 0; i < numTracks; i++) {
    format = extractor.getTrackFormat(i);
    if (format.getString(MediaFormat.KEY_MIME).startsWith("audio/")) {
      extractor.selectTrack(i);
      break;
    }
  }
  MediaCodec mediaCodec = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME));
  mediaCodec.configure(format, null, null, 0);
  mediaCodec.start();
}
 
开发者ID:XueyanLiu,项目名称:miku,代码行数:20,代码来源:VideoUtils.java


注:本文中的android.media.MediaExtractor.getTrackFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。