本文整理了Java中android.media.MediaExtractor.selectTrack()
方法的一些代码示例,展示了MediaExtractor.selectTrack()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaExtractor.selectTrack()
方法的具体详情如下:
包路径:android.media.MediaExtractor
类名称:MediaExtractor
方法名:selectTrack
暂无
代码示例来源:origin: TeamNewPipe/NewPipe
private MediaExtractor getMediaExtractor(FileInputStream source, long offset, long length) throws IOException {
MediaExtractor extractor = new MediaExtractor();
extractor.setDataSource(source.getFD(), offset, length);
extractor.selectTrack(0);
return extractor;
}
}
代码示例来源:origin: guoxiaoxing/phoenix
private void setupTrackTranscoders(MediaFormatStrategy formatStrategy) {
MediaExtractorUtils.TrackResult trackResult = MediaExtractorUtils.getFirstVideoAndAudioTrack(mExtractor);
MediaFormat videoOutputFormat = formatStrategy.createVideoOutputFormat(trackResult.mVideoTrackFormat);
MediaFormat audioOutputFormat = formatStrategy.createAudioOutputFormat(trackResult.mAudioTrackFormat);
if (videoOutputFormat == null && audioOutputFormat == null) {
throw new InvalidOutputFormatException("MediaFormatStrategy returned pass-through for both video and audio. No transcoding is necessary.");
}
QueuedMuxer queuedMuxer = new QueuedMuxer(mMuxer, new QueuedMuxer.Listener() {
@Override
public void onDetermineOutputFormat() {
MediaFormatValidator.validateVideoOutputFormat(mVideoTrackTranscoder.getDeterminedFormat());
MediaFormatValidator.validateAudioOutputFormat(mAudioTrackTranscoder.getDeterminedFormat());
}
});
if (videoOutputFormat == null) {
mVideoTrackTranscoder = new PassThroughTrackTranscoder(mExtractor, trackResult.mVideoTrackIndex, queuedMuxer, QueuedMuxer.SampleType.VIDEO);
} else {
mVideoTrackTranscoder = new VideoTrackTranscoder(mExtractor, trackResult.mVideoTrackIndex, videoOutputFormat, queuedMuxer);
}
mVideoTrackTranscoder.setup();
if (audioOutputFormat == null) {
mAudioTrackTranscoder = new PassThroughTrackTranscoder(mExtractor, trackResult.mAudioTrackIndex, queuedMuxer, QueuedMuxer.SampleType.AUDIO);
} else {
mAudioTrackTranscoder = new AudioTrackTranscoder(mExtractor, trackResult.mAudioTrackIndex, audioOutputFormat, queuedMuxer);
}
mAudioTrackTranscoder.setup();
mExtractor.selectTrack(trackResult.mVideoTrackIndex);
mExtractor.selectTrack(trackResult.mAudioTrackIndex);
}
代码示例来源:origin: guoxiaoxing/phoenix
@Override
public void setup() {
mExtractor.selectTrack(mTrackIndex);
try {
mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mEncoder.configure(mOutputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
mEncoderStarted = true;
mEncoderBuffers = new MediaCodecBufferCompatWrapper(mEncoder);
final MediaFormat inputFormat = mExtractor.getTrackFormat(mTrackIndex);
try {
mDecoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mDecoder.configure(inputFormat, null, null, 0);
mDecoder.start();
mDecoderStarted = true;
mDecoderBuffers = new MediaCodecBufferCompatWrapper(mDecoder);
mAudioChannel = new AudioChannel(mDecoder, mEncoder, mOutputFormat);
}
代码示例来源:origin: guoxiaoxing/phoenix
@Override
public void setup() {
mExtractor.selectTrack(mTrackIndex);
try {
mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
代码示例来源:origin: saki4510t/libcommon
public void restart() {
if (DEBUG) Log.v(TAG, "restart:");
if (mState == STATE_WAIT) {
synchronized (mSync) {
mMediaExtractor.unselectTrack(mTrackIndex);
mMediaExtractor.selectTrack(mTrackIndex);
mState = STATE_PLAYING;
mSync.notifyAll();
}
}
}
代码示例来源:origin: stackoverflow.com
MediaExtractor extractor= new MediaExtractor();
File file = new File(this.fileName);
extractor.setDataSource(this.fileName);
int tracks = extractor.getTrackCount();
extractor.selectTrack(0); ..
代码示例来源:origin: bitmovin/bitcodin-android-demo
@Override
public void enable(int track, long positionUs) {
Assertions.checkState(prepared);
Assertions.checkState(trackStates[track] == TRACK_STATE_DISABLED);
trackStates[track] = TRACK_STATE_ENABLED;
extractor.selectTrack(track);
seekToUsInternal(positionUs, positionUs != 0);
}
代码示例来源:origin: aserbao/AndroidCamera
private int getAndSelectAudioTrackIndex(MediaExtractor extractor) {
for (int index = 0; index < extractor.getTrackCount(); ++index) {
if (VERBOSE) {
Log.d(TAG, "format for track " + index + " is "
+ getMimeTypeFor(extractor.getTrackFormat(index)));
}
if (isAudioFormat(extractor.getTrackFormat(index))) {
extractor.selectTrack(index);
return index;
}
}
return -1;
}
代码示例来源:origin: aserbao/AndroidCamera
private int getAndSelectVideoTrackIndex(MediaExtractor extractor) {
for (int index = 0; index < extractor.getTrackCount(); ++index) {
if (VERBOSE) {
Log.d(TAG, "format for track " + index + " is "
+ getMimeTypeFor(extractor.getTrackFormat(index)));
}
if (isVideoFormat(extractor.getTrackFormat(index))) {
extractor.selectTrack(index);
return index;
}
}
return -1;
}
代码示例来源:origin: yangjie10930/OpenGL4Android
private boolean audioDecodeStep(ByteBuffer buffer) {
boolean isTimeEnd = false;
buffer.clear();
synchronized (Extractor_LOCK) {
mExtractor.selectTrack(mAudioDecoderTrack);
int length = mExtractor.readSampleData(buffer, 0);
if (length != -1) {
int flags = mExtractor.getSampleFlags();
mAudioEncoderBufferInfo.size = length;
mAudioEncoderBufferInfo.flags = flags;
mAudioEncoderBufferInfo.presentationTimeUs = mExtractor.getSampleTime();
mAudioEncoderBufferInfo.offset = 0;
isTimeEnd = mExtractor.getSampleTime() >= mVideoStopTimeStamp;
mMuxer.writeSampleData(mAudioEncoderTrack, buffer, mAudioEncoderBufferInfo);
}
isAudioExtractorEnd = !mExtractor.advance();
}
return isAudioExtractorEnd || isTimeEnd;
}
代码示例来源:origin: lijundacom/AndroidRTSPLib2
public MP4Encorder(Session session){
mediaExtractor = new MediaExtractor();
try {
mediaExtractor.setDataSource(session.getVideoPath());
} catch (IOException e) {
e.printStackTrace();
}
for(int i = 0; i < mediaExtractor.getTrackCount(); i++) {
MediaFormat format = mediaExtractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (!mime.startsWith("video/")) {
continue;
}
framerate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
mediaExtractor.selectTrack(i);
session.getVideoQuality().setmFrameRate(framerate);
}
}
代码示例来源:origin: pedroSG94/rtmp-rtsp-stream-client-java
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) {
width = videoFormat.getInteger(MediaFormat.KEY_WIDTH);
height = videoFormat.getInteger(MediaFormat.KEY_HEIGHT);
duration = videoFormat.getLong(MediaFormat.KEY_DURATION);
return true;
//video decoder not supported
} else {
mime = "";
videoFormat = null;
return false;
}
}
代码示例来源:origin: pedroSG94/rtmp-rtsp-stream-client-java
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) {
isStereo = (audioFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT) == 2);
sampleRate = audioFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
duration = audioFormat.getLong(MediaFormat.KEY_DURATION);
return true;
//audio decoder not supported
} else {
mime = "";
audioFormat = null;
return false;
}
}
代码示例来源:origin: ypresto/android-transcoder
@Override
public void setup() {
mExtractor.selectTrack(mTrackIndex);
try {
mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mEncoder.configure(mOutputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
mEncoderStarted = true;
mEncoderBuffers = new MediaCodecBufferCompatWrapper(mEncoder);
final MediaFormat inputFormat = mExtractor.getTrackFormat(mTrackIndex);
try {
mDecoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mDecoder.configure(inputFormat, null, null, 0);
mDecoder.start();
mDecoderStarted = true;
mDecoderBuffers = new MediaCodecBufferCompatWrapper(mDecoder);
mAudioChannel = new AudioChannel(mDecoder, mEncoder, mOutputFormat);
}
代码示例来源:origin: windrunnerlihuan/DogCamera
@Override
public void setup() {
mExtractor.selectTrack(mTrackIndex);
try {
mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mEncoder.configure(mOutputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
mEncoderStarted = true;
mEncoderBuffers = new MediaCodecBufferCompatWrapper(mEncoder);
final MediaFormat inputFormat = mExtractor.getTrackFormat(mTrackIndex);
try {
mDecoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mDecoder.configure(inputFormat, null, null, 0);
mDecoder.start();
mDecoderStarted = true;
mDecoderBuffers = new MediaCodecBufferCompatWrapper(mDecoder);
mAudioChannel = new AudioChannel(mDecoder, mEncoder, mOutputFormat);
}
代码示例来源:origin: GoBelieveIO/im_android
@Override
public void setup() {
mExtractor.selectTrack(mTrackIndex);
try {
mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mEncoder.configure(mOutputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
mEncoderStarted = true;
mEncoderBuffers = new MediaCodecBufferCompatWrapper(mEncoder);
final MediaFormat inputFormat = mExtractor.getTrackFormat(mTrackIndex);
try {
mDecoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mDecoder.configure(inputFormat, null, null, 0);
mDecoder.start();
mDecoderStarted = true;
mDecoderBuffers = new MediaCodecBufferCompatWrapper(mDecoder);
mAudioChannel = new AudioChannel(mDecoder, mEncoder, mOutputFormat);
}
代码示例来源:origin: MasayukiSuda/Mp4Composer-android
@Override
public void setup() {
extractor.selectTrack(trackIndex);
try {
encoder = MediaCodec.createEncoderByType(outputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
encoder.configure(outputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
encoder.start();
encoderStarted = true;
encoderBuffers = new MediaCodecBufferCompatWrapper(encoder);
final MediaFormat inputFormat = extractor.getTrackFormat(trackIndex);
try {
decoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
decoder.configure(inputFormat, null, null, 0);
decoder.start();
decoderStarted = true;
decoderBuffers = new MediaCodecBufferCompatWrapper(decoder);
audioChannel = new AudioChannel(decoder, encoder, outputFormat);
}
代码示例来源:origin: stackoverflow.com
MediaExtractor extractor = new MediaExtractor();
extractor.setDataSource(...);
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; ++i) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (weAreInterestedInThisTrack) {
extractor.selectTrack(i);
}
}
ByteBuffer inputBuffer = ByteBuffer.allocate(...)
while (extractor.readSampleData(inputBuffer, ...) >= 0) {
int trackIndex = extractor.getSampleTrackIndex();
long presentationTimeUs = extractor.getSampleTime();
...
extractor.advance();
}
extractor.release();
extractor = null;
代码示例来源:origin: kriztan/Pix-Art-Messenger
@Override
public void setup() {
mExtractor.selectTrack(mTrackIndex);
try {
mEncoder = MediaCodec.createEncoderByType(mOutputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mEncoder.configure(mOutputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mEncoder.start();
mEncoderStarted = true;
mEncoderBuffers = new MediaCodecBufferCompatWrapper(mEncoder);
final MediaFormat inputFormat = mExtractor.getTrackFormat(mTrackIndex);
try {
mDecoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
mDecoder.configure(inputFormat, null, null, 0);
mDecoder.start();
mDecoderStarted = true;
mDecoderBuffers = new MediaCodecBufferCompatWrapper(mDecoder);
mAudioChannel = new AudioChannel(mDecoder, mEncoder, mOutputFormat);
}
代码示例来源:origin: MasayukiSuda/GPUVideo-android
@Override
public void setup() {
extractor.selectTrack(trackIndex);
try {
encoder = MediaCodec.createEncoderByType(outputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
encoder.configure(outputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
encoder.start();
encoderStarted = true;
encoderBuffers = new MediaCodecBufferCompatWrapper(encoder);
final MediaFormat inputFormat = extractor.getTrackFormat(trackIndex);
try {
decoder = MediaCodec.createDecoderByType(inputFormat.getString(MediaFormat.KEY_MIME));
} catch (IOException e) {
throw new IllegalStateException(e);
}
decoder.configure(inputFormat, null, null, 0);
decoder.start();
decoderStarted = true;
decoderBuffers = new MediaCodecBufferCompatWrapper(decoder);
audioChannel = new AudioChannel(decoder, encoder, outputFormat);
}
内容来源于网络,如有侵权,请联系作者删除!