2

I am currently working on video recording using MediaCodec and MediaMuxer because I need the recorder frames to use a t multiple places.

Current Behaviour : Media codec is configured with 720x1280 resolution, and media muxer video track added from the media codec, therefore the video output is also containg the same resolution 720x1280.

Creating media format

MediaFormat mVideoFormat = MediaFormat.createVideoFormat(VIDEO_MIME_TYPE, 720, 1280);
    mVideoFormat.setInteger(MediaFormat.KEY_BIT_RATE, 1024*1024);
    mVideoFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
    mVideoFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 3);
    mVideoFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);

Creating codec from media format

 mMediaCodec = MediaCodec.createByCodecName(videoCodecInfo.getName());
        mMediaCodec.setVideoScalingMode(MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
        mMediaCodec.configure(mVideoFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
        mInputSurface = mMediaCodec.createInputSurface();

And adding track of muxer from

if (outputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
            MediaFormat mediaFormat = mMediaCodec.getOutputFormat();
            mTrackIndex = mMediaMuxer.addVideoTrack(mediaFormat);
            mMediaMuxer.start();
        }

Expecting Output I always want media codec to run on the 720x1280, but I want media muxer to write video with different resolution like 720x1280 or any other resolution which is below it.

Over all goal which I want to achive is that I can configure MediaCodec to highest possible resolution, and on runtime I can create multiple video parallely with differnt resolutions.

Anuj J Pandey
  • 656
  • 1
  • 4
  • 17
  • 1
    See: [MediaMuxer video file size reducing (re-compress, decrease resolution)](https://stackoverflow.com/q/29943121/295004) – Morrison Chang Mar 03 '20 at 07:28
  • @MorrisonChang the code suggested on the link is doing it after once recording completed, I want to do it when I am writing frames direct to the muxer, do not want it post recording completion, instead need to it on runtime while recording. – Anuj J Pandey Mar 03 '20 at 08:43
  • 1
    I think you misunderstood what MediaMuxer is actually doing, it's Muxing and only Muxing. Look at faddens answer in the SO post referred by MorrisonChang. What you want to do is only achievable by using multiple instances of MediaCodec. The SO post you got from MorrisonChang is a good starting point, just replace input from file to input from other source and you are good to go. But, if you plan to target only newer devices check out how to work with MediaCodec asynchronously. – ChrisBe Mar 03 '20 at 15:52

0 Answers0