use of android.media.MediaFormat in project Pix-Art-Messenger by kriztan.
the class AndroidStandardFormatStrategy method createAudioOutputFormat.
@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;
}
use of android.media.MediaFormat in project Pix-Art-Messenger by kriztan.
the class AndroidStandardFormatStrategy method createVideoOutputFormat.
@Override
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);
int height = inputFormat.getInteger(MediaFormat.KEY_HEIGHT);
ASPECT_RATIO = (float) width / height;
Log.d(TAG, "Input video (" + width + "x" + height + " ratio: " + ASPECT_RATIO);
int shorter, outWidth, outHeight;
if (width >= height) {
shorter = height;
outWidth = Math.round(mVideoresolution * ASPECT_RATIO);
outHeight = mVideoresolution;
} else {
shorter = width;
outWidth = mVideoresolution;
outHeight = Math.round(mVideoresolution * ASPECT_RATIO);
}
if (shorter < mVideoresolution) {
Log.d(TAG, "This video is less to " + mVideoresolution + "p, pass-through. (" + width + "x" + height + ")");
return null;
}
Log.d(TAG, "Converting video (" + outWidth + "x" + outHeight + " ratio: " + ASPECT_RATIO + ")");
MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight);
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;
}
use of android.media.MediaFormat in project Pix-Art-Messenger by kriztan.
the class MediaFormatPresets method getExportPreset960x540.
// preset similar to iOS SDK's AVAssetExportPreset960x540
@Deprecated
public static MediaFormat getExportPreset960x540() {
MediaFormat format = MediaFormat.createVideoFormat("video/avc", 960, 540);
format.setInteger(MediaFormat.KEY_BIT_RATE, 5500 * 1000);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
return format;
}
use of android.media.MediaFormat in project Pix-Art-Messenger by kriztan.
the class MediaFormatPresets method getExportPreset960x540.
/**
* Preset similar to iOS SDK's AVAssetExportPreset960x540.
* Note that encoding resolutions of this preset are not supported in all devices e.g. Nexus 4.
* On unsupported device encoded video stream will be broken without any exception.
* @param originalWidth Input video width.
* @param originalHeight Input video height.
* @return MediaFormat instance, or null if pass through.
*/
public static MediaFormat getExportPreset960x540(int originalWidth, int originalHeight) {
int longerLength = Math.max(originalWidth, originalHeight);
int shorterLength = Math.min(originalWidth, originalHeight);
// don't upscale
if (longerLength <= LONGER_LENGTH_960x540)
return null;
int residue = LONGER_LENGTH_960x540 * shorterLength % longerLength;
if (residue != 0) {
double ambiguousShorter = (double) LONGER_LENGTH_960x540 * shorterLength / longerLength;
throw new OutputFormatUnavailableException(String.format("Could not fit to integer, original: (%d, %d), scaled: (%d, %f)", longerLength, shorterLength, LONGER_LENGTH_960x540, ambiguousShorter));
}
int scaledShorter = LONGER_LENGTH_960x540 * shorterLength / longerLength;
int width, height;
if (originalWidth >= originalHeight) {
width = LONGER_LENGTH_960x540;
height = scaledShorter;
} else {
width = scaledShorter;
height = LONGER_LENGTH_960x540;
}
MediaFormat format = MediaFormat.createVideoFormat("video/avc", width, height);
format.setInteger(MediaFormat.KEY_BIT_RATE, 5500 * 1000);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
return format;
}
use of android.media.MediaFormat in project EasyPlayer-RTMP-Android by EasyDSS.
the class EasyPlayerClient method startRecord1.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public synchronized void startRecord1(String path) {
if (mMediaInfo == null || mWidth == 0 || mHeight == 0 || mCSD0 == null || mCSD1 == null)
return;
mRecordingPath = path;
mObject = new EasyAACMuxer(path, mMediaInfo.sample != 0, Integer.MAX_VALUE);
MediaFormat format = new MediaFormat();
format.setInteger(MediaFormat.KEY_WIDTH, mWidth);
format.setInteger(MediaFormat.KEY_HEIGHT, mHeight);
mCSD0.clear();
format.setByteBuffer("csd-0", mCSD0);
mCSD1.clear();
format.setByteBuffer("csd-1", mCSD1);
format.setString(MediaFormat.KEY_MIME, "video/avc");
format.setInteger(MediaFormat.KEY_FRAME_RATE, 0);
// format.setInteger(MediaFormat.KEY_BIT_RATE, mWidth*mHeight*0.7*2);
mObject.addTrack(format, true);
format = new MediaFormat();
int audioObjectType = 2;
int sampleRateIndex = getSampleIndex(mMediaInfo.sample);
if (sampleRateIndex > 0) {
int channelConfig = mMediaInfo.channel;
byte[] audioSpecificConfig = CodecSpecificDataUtil.buildAacAudioSpecificConfig(audioObjectType, sampleRateIndex, channelConfig);
Pair<Integer, Integer> audioParams = CodecSpecificDataUtil.parseAacAudioSpecificConfig(audioSpecificConfig);
// format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0);
format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_AUDIO_AAC);
format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, audioParams.second);
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, audioParams.first);
List<byte[]> bytes = Collections.singletonList(audioSpecificConfig);
for (int j = 0; j < bytes.size(); j++) {
format.setByteBuffer("csd-" + j, ByteBuffer.wrap(bytes.get(j)));
}
mObject.addTrack(format, false);
}
ResultReceiver rr = mRR;
if (rr != null) {
rr.send(RESULT_RECORD_BEGIN, null);
}
}
Aggregations