3

i need to capture video from required portion of the screen like -

enter image description here

I have tried

...
try {
        camera.unlock();
        recorder.setCamera(camera);
        recorder.setOrientationHint(cameraRotationDegree);
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        **recorder.setVideoSize(sz.width, sz.height);**
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
        recorder.setOutputFile(fileName);
        recorder.prepare();
        recorder.start();
        isRecording = true;
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

but it records while screen.

is it possible to capture video from required portion of the screen?

fadden
  • 51,356
  • 5
  • 116
  • 166
Mansi
  • 1,939
  • 4
  • 22
  • 40
  • no. not snapshot. record video from required portion of the screen – Mansi Nov 20 '15 at 10:15
  • ok look at this tutorial it may help you because you already getting camera whole screen now to appear only for perticular area follow[-this](http://stackoverflow.com/questions/12720774/how-to-make-camera-appear-in-particular-screen-area-in-android) – sud Nov 20 '15 at 10:16
  • Just to be clear... do you want to present the full camera preview in the upper part of the screen, and record the full frame? Show a cut-off camera preview and record the full frame? Show a cut-off camera preview and only record the visible part? – fadden Nov 20 '15 at 17:04
  • @fadden i want to show cut - off camera preview and record only that visible part. – Mansi Nov 21 '15 at 04:59
  • @Mansi Have you found any solution for this? It'd be great help :) – Nisarg Jul 12 '16 at 10:30
  • @Nisarg: no. as per my R & D its not possible in android. Android always records full screen video. – Mansi Jul 12 '16 at 10:45
  • @Mansi Okay Thanks and For *DF* we've been searching since 20 days :( – Nisarg Jul 12 '16 at 10:59
  • @Nisarg: if you want to crop video it's possible from server side – Mansi Jul 13 '16 at 05:51
  • @Mansi Yes but there are lots of things we have to apply on video after its being captured like trimming, filter effects etc. So for this scenario its not possible from server side i guess. – Nisarg Jul 13 '16 at 06:02

1 Answers1

0

The video is being cut off on the display by being obscured by static content. You can't record from the display, and even if you could, you'd just end up with the static content in the video as well.

One approach is to direct the video to a SurfaceTexture, which converts each incoming frame to an OpenGL ES "external" texture. You would then render the desired portion of the frame twice, once to the display, once to a video encoder. This is fairly involved, but you can find examples of the various bits in Grafika.

A less efficient but perhaps more straightforward approach would be to post-process the video file with something like ffmpeg. I haven't worked with it, but it seems fairly sophisticated, and may provide an easy way to re-encode a video with cropping.

The simplest option is to simply fit the camera preview into your layout, and work with the full frame.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • It's possible to call **MediaCodec** from `onPreviewFrame()`, isn't it? – Alex Cohn Nov 24 '15 at 11:26
  • 1
    It's possible. I usually ignore it as an option because the frame rate will be low -- in addition to the usual overhead associated with working with `byte[]`, you have to do a color conversion on each frame, because MediaCodec's YUV inputs aren't the same as Camera's outputs (need to swap U and V). If that's not a concern, though, you could do a software copy of the relevant parts of each frame and feed them to MediaCodec on an API 18+ device. – fadden Nov 24 '15 at 16:19
  • Still much faster than software-only x264, and without the involved licensing concerns. – Alex Cohn Nov 24 '15 at 16:43
  • @AlexCohn: With ffmpeg post-processing, you can capture at full speed and do the processing offline. With `onPreviewFrame()` you're doing the extra work "inline" and will be unable to keep up with the preview. The latter is certainly a viable option when a lower frame rate is acceptable. The SurfaceTexture-based approach is the best all around, but it does require a visit to the deep end of Android. – fadden Nov 24 '15 at 16:50
  • If you can do conversions offline, MediaRecorder is just OK. Regarding YUV formats, note that ffmpeg does not support NV21 out-of-the-box, too. – Alex Cohn Nov 25 '15 at 07:02