use of android.media.MediaMuxer in project grafika by google.
the class SoftInputSurfaceActivity method prepareEncoder.
/**
* 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();
// 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;
}
use of android.media.MediaMuxer in project grafika by google.
the class GeneratedMovie method prepareEncoder.
/**
* Prepares the video encoder, muxer, and an EGL input surface.
*/
protected void prepareEncoder(String mimeType, int width, int height, int bitRate, int framesPerSecond, File outputFile) throws IOException {
mBufferInfo = new MediaCodec.BufferInfo();
MediaFormat format = MediaFormat.createVideoFormat(mimeType, 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, framesPerSecond);
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(mimeType);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
Log.v(TAG, "encoder is " + mEncoder.getCodecInfo().getName());
Surface surface;
try {
surface = mEncoder.createInputSurface();
} catch (IllegalStateException ise) {
// TODO: failure message should come out of strings.xml for i18n
if (isSoftwareCodec(mEncoder)) {
throw new RuntimeException("Can't use input surface with software codec: " + mEncoder.getCodecInfo().getName(), ise);
} else {
throw new RuntimeException("Failed to create input surface", ise);
}
}
mEglCore = new EglCore(null, EglCore.FLAG_RECORDABLE);
mInputSurface = new WindowSurface(mEglCore, surface, true);
mInputSurface.makeCurrent();
mEncoder.start();
// 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;
}
Aggregations