本文整理匯總了Java中android.media.MediaFormat.getInteger方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaFormat.getInteger方法的具體用法?Java MediaFormat.getInteger怎麽用?Java MediaFormat.getInteger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.MediaFormat
的用法示例。
在下文中一共展示了MediaFormat.getInteger方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: retrieveFrameRate
import android.media.MediaFormat; //導入方法依賴的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;
}
示例2: onOutputFormatChanged
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
public void onOutputFormatChanged(final MediaCodec codec, final MediaFormat format) {
if (mMuxerStarted) {
throw new RuntimeException("format changed twice");
}
String name = format.getString(MediaFormat.KEY_MIME);
int width = format.getInteger(MediaFormat.KEY_WIDTH);
int height = format.getInteger(MediaFormat.KEY_HEIGHT);
Logging.d(TAG, "onOutputFormatChanged " + name + " " + width + "x" + height);
mTrackIndex = mMediaMuxer.addTrack(format);
mMediaMuxer.start();
mMuxerStarted = true;
}
示例3: onOutputFormatChanged
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat)
throws ExoPlaybackException {
boolean passthrough = passthroughMediaFormat != null;
String mimeType = passthrough ? passthroughMediaFormat.getString(MediaFormat.KEY_MIME)
: MimeTypes.AUDIO_RAW;
MediaFormat format = passthrough ? passthroughMediaFormat : outputFormat;
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int[] channelMap;
if (codecNeedsDiscardChannelsWorkaround && channelCount == 6 && this.channelCount < 6) {
channelMap = new int[this.channelCount];
for (int i = 0; i < this.channelCount; i++) {
channelMap[i] = i;
}
} else {
channelMap = null;
}
try {
audioTrack.configure(mimeType, channelCount, sampleRate, pcmEncoding, 0, channelMap);
} catch (AudioTrack.ConfigurationException e) {
throw ExoPlaybackException.createForRenderer(e, getIndex());
}
}
示例4: extractMedia
import android.media.MediaFormat; //導入方法依賴的package包/類
private boolean extractMedia(){
if(mPath==null||!new File(mPath).exists()){
//文件不存在
return false;
}
try {
MediaMetadataRetriever mMetRet=new MediaMetadataRetriever();
mMetRet.setDataSource(mPath);
mVideoTotalTime=Long.valueOf(mMetRet.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
mExtractor=new MediaExtractor();
mExtractor.setDataSource(mPath);
int trackCount=mExtractor.getTrackCount();
for (int i=0;i<trackCount;i++){
MediaFormat format=mExtractor.getTrackFormat(i);
String mime=format.getString(MediaFormat.KEY_MIME);
if(mime.startsWith("audio")){
mAudioDecodeTrack=i;
}else if(mime.startsWith("video")){
mVideoDecodeTrack=i;
int videoRotation=0;
String rotation=mMetRet.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
if(rotation!=null){
videoRotation=Integer.valueOf(rotation);
}
if(videoRotation%180!=0){
mVideoSize.y=format.getInteger(MediaFormat.KEY_WIDTH);
mVideoSize.x=format.getInteger(MediaFormat.KEY_HEIGHT);
}else{
mVideoSize.x=format.getInteger(MediaFormat.KEY_WIDTH);
mVideoSize.y=format.getInteger(MediaFormat.KEY_HEIGHT);
}
}
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
示例5: createVideoOutputFormat
import android.media.MediaFormat; //導入方法依賴的package包/類
@SuppressLint("LongLogTag")
@Override
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
// TODO: detect non-baseline profile and throw exception
int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);
int height = inputFormat.getInteger(MediaFormat.KEY_HEIGHT);
MediaFormat outputFormat = MediaFormatPresets.getExportPreset960x540(width, height);
int outWidth = outputFormat.getInteger(MediaFormat.KEY_WIDTH);
int outHeight = outputFormat.getInteger(MediaFormat.KEY_HEIGHT);
Log.d(TAG, String.format("inputFormat: %dx%d => outputFormat: %dx%d", width, height, outWidth, outHeight));
return outputFormat;
}
示例6: createVideoOutputFormat
import android.media.MediaFormat; //導入方法依賴的package包/類
@SuppressLint("LongLogTag")
@Override
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);
int height = inputFormat.getInteger(MediaFormat.KEY_HEIGHT);
int targetLonger = mScale * 16 * 16;
int targetShorter = mScale * 16 * 9;
int longer, shorter, outWidth, outHeight;
if (width >= height) {
longer = width;
shorter = height;
outWidth = targetLonger;
outHeight = targetShorter;
} else {
shorter = width;
longer = height;
outWidth = targetShorter;
outHeight = targetLonger;
}
if (longer * 9 != shorter * 16) {
throw new OutputFormatUnavailableException("This video is not 16:9, and is not able to transcode. (" + width + "x" + height + ")");
}
if (shorter <= targetShorter) {
Log.d(TAG, "This video's height is less or equal to " + targetShorter + ", pass-through. (" + width + "x" + height + ")");
return null;
}
MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight);
// From Nexus 4 Camera in 720p
format.setInteger(MediaFormat.KEY_BIT_RATE, mVideoBitrate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 3);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
return format;
}
示例7: prepare
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
protected void prepare() throws IOException {
if (mState < STATE_PREPARED) {
MediaFormat format;
if (mState == STATE_UNINITIALIZED) {
mTrackIndex = selectTrack();
if (mTrackIndex < 0) {
setState(STATE_NO_TRACK_FOUND);
return;
}
mExtractor.selectTrack(mTrackIndex);
format = mExtractor.getTrackFormat(mTrackIndex);
mSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int audioChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
mAudioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
mSampleRate,
(audioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
AudioFormat.ENCODING_PCM_16BIT,
AudioTrack.getMinBufferSize(
mSampleRate,
(audioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
AudioFormat.ENCODING_PCM_16BIT
),
AudioTrack.MODE_STREAM
);
mState = STATE_INITIALIZED;
} else {
format = mExtractor.getTrackFormat(mTrackIndex);
}
String mime = format.getString(MediaFormat.KEY_MIME);
Log.d(TAG, mime);
mMediaCodec = MediaCodec.createDecoderByType(mime);
// mMediaCodec.setCallback(mCallback);
mMediaCodec.configure(format, null, null, 0);
setState(STATE_PREPARED);
}
super.prepare();
}
示例8: onReady
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
public void onReady(final MediaFormat mediaFormat) {
mVideoWidth = mediaFormat.getInteger(MediaFormat.KEY_WIDTH);
mVideoHeight = mediaFormat.getInteger(MediaFormat.KEY_HEIGHT);
Log.i(TAG, "Video size: %dx%d", mVideoWidth, mVideoHeight);
Log.i(TAG, "VideoFormat decoder " + mediaFormat);
}
示例9: showMetrics
import android.media.MediaFormat; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void showMetrics(MediaFormat format, int numBytesSubmitted, int numBytesDequeued) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Log.i("queued a total of " + numBytesSubmitted + " bytes, " + "dequeued " + numBytesDequeued + " bytes.");
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
int inBitrate = sampleRate * channelCount * 16; // bit/sec
int outBitrate = format.getInteger(MediaFormat.KEY_BIT_RATE);
float desiredRatio = (float) outBitrate / (float) inBitrate;
float actualRatio = (float) numBytesDequeued / (float) numBytesSubmitted;
Log.i("desiredRatio = " + desiredRatio + ", actualRatio = " + actualRatio);
}
}
示例10: 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);
}
示例11: onOutputFormatChanged
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat) {
boolean hasCrop = outputFormat.containsKey(KEY_CROP_RIGHT)
&& outputFormat.containsKey(KEY_CROP_LEFT) && outputFormat.containsKey(KEY_CROP_BOTTOM)
&& outputFormat.containsKey(KEY_CROP_TOP);
currentWidth = hasCrop
? outputFormat.getInteger(KEY_CROP_RIGHT) - outputFormat.getInteger(KEY_CROP_LEFT) + 1
: outputFormat.getInteger(MediaFormat.KEY_WIDTH);
currentHeight = hasCrop
? outputFormat.getInteger(KEY_CROP_BOTTOM) - outputFormat.getInteger(KEY_CROP_TOP) + 1
: outputFormat.getInteger(MediaFormat.KEY_HEIGHT);
currentPixelWidthHeightRatio = pendingPixelWidthHeightRatio;
if (Util.SDK_INT >= 21) {
// On API level 21 and above the decoder applies the rotation when rendering to the surface.
// Hence currentUnappliedRotation should always be 0. For 90 and 270 degree rotations, we need
// to flip the width, height and pixel aspect ratio to reflect the rotation that was applied.
if (pendingRotationDegrees == 90 || pendingRotationDegrees == 270) {
int rotatedHeight = currentWidth;
currentWidth = currentHeight;
currentHeight = rotatedHeight;
currentPixelWidthHeightRatio = 1 / currentPixelWidthHeightRatio;
}
} else {
// On API level 20 and below the decoder does not apply the rotation.
currentUnappliedRotationDegrees = pendingRotationDegrees;
}
// Must be applied each time the output format changes.
setVideoScalingMode(codec, scalingMode);
}
示例12: getProfile
import android.media.MediaFormat; //導入方法依賴的package包/類
public int getProfile(MediaFormat mediaFormat)
{
return mediaFormat.getInteger(MediaFormat.KEY_AAC_PROFILE);
}
示例13: readAndWriteTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
@TargetApi(16)
private long readAndWriteTrack(final MessageObject messageObject, MediaExtractor extractor, MP4Builder mediaMuxer, MediaCodec.BufferInfo info, long start, long end, File file, boolean isAudio) throws Exception {
int trackIndex = selectTrack(extractor, isAudio);
if (trackIndex >= 0) {
extractor.selectTrack(trackIndex);
MediaFormat trackFormat = extractor.getTrackFormat(trackIndex);
int muxerTrackIndex = mediaMuxer.addTrack(trackFormat, isAudio);
int maxBufferSize = trackFormat.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE);
boolean inputDone = false;
if (start > 0) {
extractor.seekTo(start, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
} else {
extractor.seekTo(0, MediaExtractor.SEEK_TO_PREVIOUS_SYNC);
}
ByteBuffer buffer = ByteBuffer.allocateDirect(maxBufferSize);
long startTime = -1;
checkConversionCanceled();
long lastTimestamp = -100;
while (!inputDone) {
checkConversionCanceled();
boolean eof = false;
int index = extractor.getSampleTrackIndex();
if (index == trackIndex) {
info.size = extractor.readSampleData(buffer, 0);
if (info.size >= 0) {
info.presentationTimeUs = extractor.getSampleTime();
} else {
info.size = 0;
eof = true;
}
if (info.size > 0 && !eof) {
if (start > 0 && startTime == -1) {
startTime = info.presentationTimeUs;
}
if (end < 0 || info.presentationTimeUs < end) {
if (info.presentationTimeUs > lastTimestamp) {
info.offset = 0;
info.flags = extractor.getSampleFlags();
if (mediaMuxer.writeSampleData(muxerTrackIndex, buffer, info, isAudio)) {
didWriteData(messageObject, file, false, false);
}
}
lastTimestamp = info.presentationTimeUs;
} else {
eof = true;
}
}
if (!eof) {
extractor.advance();
}
} else if (index == -1) {
eof = true;
} else {
extractor.advance();
}
if (eof) {
inputDone = true;
}
}
extractor.unselectTrack(trackIndex);
return startTime;
}
return -1;
}
示例14: createVideoOutputFormat
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);
int height = inputFormat.getInteger(MediaFormat.KEY_HEIGHT);
int integer = inputFormat.getInteger(MediaFormat.KEY_ROTATION);
int longer, shorter, outWidth, outHeight;
if (width <= height) {
shorter = width;
longer = height;
if(integer ==0 || integer == 180) {
outWidth = LONGER_LENGTH;
outHeight = SHORTER_LENGTH;
}else {
outWidth = SHORTER_LENGTH;
outHeight = LONGER_LENGTH;
}
} else {
longer = width;
shorter = height;
if(integer ==0 || integer == 180) {
outWidth = SHORTER_LENGTH;
outHeight = LONGER_LENGTH;
}else {
outWidth = LONGER_LENGTH;
outHeight = SHORTER_LENGTH;
}
}
// if (longer * 9 != shorter * 16) {
// outWidth = shorter;
// outHeight = longer;
//// throw new OutputFormatUnavailableException("This video is not 16:9, and is not able to transcode. (" + width + "x" + height + ")");
// }
//
// if (shorter < SHORTER_LENGTH) {
// if(integer ==0 || integer == 180) {
// outWidth = shorter;
// outHeight = longer;
// }else {
// outWidth = longer;
// outHeight = shorter;
//
// }
// Log.d(TAG, "This video is less or equal to 720p, pass-through. (" + width + "x" + height + ")");
// return null;
// }
MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight);
// From Nexus 4 Camera in 720p
format.setInteger(MediaFormat.KEY_BIT_RATE, mVideoBitrate);
format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 3);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
return format;
}
示例15: dequeueOutputBuffer
import android.media.MediaFormat; //導入方法依賴的package包/類
private DecodedOutputBuffer dequeueOutputBuffer(int dequeueTimeoutMs) {
checkOnMediaCodecThread();
if (decodeStartTimeMs.isEmpty()) {
return null;
}
// Drain the decoder until receiving a decoded buffer or hitting
// MediaCodec.INFO_TRY_AGAIN_LATER.
final MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
while (true) {
final int result =
mediaCodec.dequeueOutputBuffer(info, TimeUnit.MILLISECONDS.toMicros(dequeueTimeoutMs));
switch (result) {
case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED:
outputBuffers = mediaCodec.getOutputBuffers();
Logging.d(TAG, "Decoder output buffers changed: " + outputBuffers.length);
if (hasDecodedFirstFrame) {
throw new RuntimeException("Unexpected output buffer change event.");
}
break;
case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:
MediaFormat format = mediaCodec.getOutputFormat();
Logging.d(TAG, "Decoder format changed: " + format.toString());
final int newWidth;
final int newHeight;
if (format.containsKey(FORMAT_KEY_CROP_LEFT) && format.containsKey(FORMAT_KEY_CROP_RIGHT)
&& format.containsKey(FORMAT_KEY_CROP_BOTTOM)
&& format.containsKey(FORMAT_KEY_CROP_TOP)) {
newWidth = 1 + format.getInteger(FORMAT_KEY_CROP_RIGHT)
- format.getInteger(FORMAT_KEY_CROP_LEFT);
newHeight = 1 + format.getInteger(FORMAT_KEY_CROP_BOTTOM)
- format.getInteger(FORMAT_KEY_CROP_TOP);
} else {
newWidth = format.getInteger(MediaFormat.KEY_WIDTH);
newHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
}
if (hasDecodedFirstFrame && (newWidth != width || newHeight != height)) {
throw new RuntimeException("Unexpected size change. Configured " + width + "*" + height
+ ". New " + newWidth + "*" + newHeight);
}
width = newWidth;
height = newHeight;
if (!useSurface && format.containsKey(MediaFormat.KEY_COLOR_FORMAT)) {
colorFormat = format.getInteger(MediaFormat.KEY_COLOR_FORMAT);
Logging.d(TAG, "Color: 0x" + Integer.toHexString(colorFormat));
if (!supportedColorList.contains(colorFormat)) {
throw new IllegalStateException("Non supported color format: " + colorFormat);
}
}
if (format.containsKey(FORMAT_KEY_STRIDE)) {
stride = format.getInteger(FORMAT_KEY_STRIDE);
}
if (format.containsKey(FORMAT_KEY_SLICE_HEIGHT)) {
sliceHeight = format.getInteger(FORMAT_KEY_SLICE_HEIGHT);
}
Logging.d(TAG, "Frame stride and slice height: " + stride + " x " + sliceHeight);
stride = Math.max(width, stride);
sliceHeight = Math.max(height, sliceHeight);
break;
case MediaCodec.INFO_TRY_AGAIN_LATER:
return null;
default:
hasDecodedFirstFrame = true;
TimeStamps timeStamps = decodeStartTimeMs.remove();
long decodeTimeMs = SystemClock.elapsedRealtime() - timeStamps.decodeStartTimeMs;
if (decodeTimeMs > MAX_DECODE_TIME_MS) {
Logging.e(TAG, "Very high decode time: " + decodeTimeMs + "ms"
+ ". Q size: " + decodeStartTimeMs.size()
+ ". Might be caused by resuming H264 decoding after a pause.");
decodeTimeMs = MAX_DECODE_TIME_MS;
}
return new DecodedOutputBuffer(result, info.offset, info.size,
TimeUnit.MICROSECONDS.toMillis(info.presentationTimeUs), timeStamps.timeStampMs,
timeStamps.ntpTimeStampMs, decodeTimeMs, SystemClock.elapsedRealtime());
}
}
}