我是Android开发的新手。我正在尝试为在phonebean版本上运行的Android手机编写视频压缩器应用程序。我正在使用MediaCodec API。
以下是我启动解码器的初始设置&编码器。我做了编码&根据文档解码。但是我得到的输出只是双击它就无法播放。任何人都可以建议我检查输出是否有效。?
// Prepare and start Decoder.
MediaCodec mediaDecoder = MediaCodec.createDecoderByType(inputFileMIME /* got from input file using MediaMetadataRetriever */);
mediaDecoder.configure(mediaFormatForDecoder /* got from input file using MediaMetadataRetriever */, null, null, 0);
mediaDecoder.start();
ByteBuffer[] decoderInputBuffers = mediaDecoder.getInputBuffers();
ByteBuffer[] decoderOutputBuffers = mediaDecoder.getOutputBuffers();
int width = 320, height = 240;
int bitRate = 125000, frameRate = 15;
int colorFormat = MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar;
int iFrameInterval = 75;
// Create video format for encoder.
MediaFormat mediaFormatForEncoder = MediaFormat.createVideoFormat("video/avc",width,height);
mediaFormatForEncoder.setInteger(MediaFormat.KEY_BIT_RATE, bitRate) ;
mediaFormatForEncoder.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);
mediaFormatForEncoder.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
mediaFormatForEncoder.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, iFrameInterval);
// Prepare and start Encoder.
MediaCodec mediaEncoder = MediaCodec.createEncoderByType("video/avc");
mediaEncoder.configure(mediaFormatForEncoder, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
mediaEncoder.start();
ByteBuffer[] encoderInputBuffers = mediaEncoder.getInputBuffers();
ByteBuffer[] encoderOutputBuffers = mediaEncoder.getOutputBuffers();
我真的被困在这里了。请帮帮我。
提前致谢:)
答案 0 :(得分:0)
@Ganesh's comment is the correct hint.
Check http://developer.android.com/reference/android/media/MediaMuxer.html to mux your stream(s) to a proper container format, for example MP4.