diff options
author | ztenghui <ztenghui@google.com> | 2013-05-31 10:50:04 -0700 |
---|---|---|
committer | ztenghui <ztenghui@google.com> | 2013-05-31 10:50:08 -0700 |
commit | 34a5b011cd3fe3b231770a3bae984175d2c983e2 (patch) | |
tree | 6237ebdb23de3f37bf5d651154bf7c0cfdd9282c /media | |
parent | c1d47c50d61063dc41214beb93aeea32f77f2550 (diff) | |
download | frameworks_base-34a5b011cd3fe3b231770a3bae984175d2c983e2.zip frameworks_base-34a5b011cd3fe3b231770a3bae984175d2c983e2.tar.gz frameworks_base-34a5b011cd3fe3b231770a3bae984175d2c983e2.tar.bz2 |
MediaMuxer sample code update, no functional change
bug:9213533
Change-Id: I0d42ec58576d9fd797dba9c9c9f5ebed1170a818
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/MediaMuxer.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/media/java/android/media/MediaMuxer.java b/media/java/android/media/MediaMuxer.java index e49a00e..774964e 100644 --- a/media/java/android/media/MediaMuxer.java +++ b/media/java/android/media/MediaMuxer.java @@ -35,20 +35,29 @@ import java.util.Map; * It is generally used like this: * * <pre> - * MediaMuxer muxer = new MediaMuxer(...); + * MediaMuxer muxer = new MediaMuxer("temp.mp4", OutputFormat.MUXER_OUTPUT_MPEG_4); + * // More often, the MediaFormat will be retrieved from MediaCodec.getOutputFormat() + * // or MediaExtractor.getTrackFormat(). * MediaFormat audioFormat = new MediaFormat(...); * MediaFormat videoFormat = new MediaFormat(...); * int audioTrackIndex = muxer.addTrack(audioFormat); * int videoTrackIndex = muxer.addTrack(videoFormat); - * ByteBuffer inputBuffer = ByteBuffer.allocate(...); + * ByteBuffer inputBuffer = ByteBuffer.allocate(bufferSize); + * boolean finished = false; + * BufferInfo bufferInfo = new BufferInfo(); + * * muxer.start(); - * while(inputBuffer has new data) { - * if (new data is audio sample) { - * muxer.writeSampleData(audioTrackIndex, inputBuffer, ...); - * } else if (new data is video sample) { - * muxer.writeSampleData(videoTrackIndex, inputBuffer, ...); + * while(!finished) { + * // getInputBuffer() will fill the inputBuffer with one frame of encoded + * // sample from either MediaCodec or MediaExtractor, set isAudioSample to + * // true when the sample is audio data, set up all the fields of bufferInfo, + * // and return true if there are no more samples. + * finished = getInputBuffer(inputBuffer, isAudioSample, bufferInfo); + * if (!finished) { + * int currentTrackIndex = isAudioSample ? audioTrackIndex : videoTrackIndex; + * muxer.writeSampleData(currentTrackIndex, inputBuffer, bufferInfo); * } - * } + * }; * muxer.stop(); * muxer.release(); * </pre> |