How to record as a video what is happening inside the View? (Android)

Is it possible to record all the actions inside a view in Android as a video? Maybe using C / C ++ or something else?

I know there is a way to write using the shell, but root is required. It would be better without it. We would also do this from the SDK version 16.

+4
source share
2 answers

You can use the javacv library to combine a set of raster images taken from a view; The code will look like this:

FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("/sdcard/test.mp4",256,256);
try {
    recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
    recorder.setFormat("mp4");
    recorder.setFrameRate(30);
    recorder.setPixelFormat(avutil.PIX_FMT_YUV420P10);
    recorder.setVideoBitrate(1200);
    recorder.startUnsafe();
    for (int i=0;i< 5;i++)
    {
        view.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        view.setDrawingCacheEnabled(false);
        recorder.record(bitmap);
    }
    recorder.stop();
}
catch (Exception e){
    e.printStackTrace();
}

And here is a complete example on how to record

+4
source

Views . , .

, MediaProjection , . API 21.

API 16 . , .

+3

All Articles