I am using MediaCodec, MediaMuxer and VirtualDisplay to record events on my phone and then create a mp4 file with that data.
I want the user to be able to define what part of the screen should be recorded, and to do that I can set the height and width of the MediaFormat for the encoder, but I seem not to be able to set any offsets so I will always record from the top left corner.
Is there a way to do this in a clever way?
Edit: Here is some code i use for setting things up to make stuff more clear.
MediaFormat encoderFormat = MediaFormat.createVideoFormat(MIME_TYPE, ENCODER_WIDTH, ENCODER_HEIGHT);
encoderFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, COLOR_FORMAT);
encoderFormat.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
encoderFormat.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
encoderFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
encoder = MediaCodec.createEncoderByType(MIME_TYPE);
encoder.setCallback(new encoderCallback());
encoder.configure(encoderFormat, null /* Surface */, null /* crypto */, MediaCodec.CONFIGURE_FLAG_ENCODE);
inputSurface = encoder.createInputSurface();
// Create a virtual mDisplay that will output to our encoder.
mVirtualDisplay = mMediaProjection.createVirtualDisplay(NAME,
VD_WIDTH, VD_HEIGHT, DENSITY, DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION, inputSurface, null /*Callback*/, null /*Handler*/);