简体   繁体   English

如何在没有root的情况下从Android Canvas捕获视频?

[英]How I can capture video from Android Canvas without root?

I'm developing a painting app, with canvas and SurfaceView, and I want to record user operations, and generate video. 我正在开发一个绘画应用程序,使用canvas和SurfaceView,我想记录用户操作,并生成视频。

In this moment I'm trying: 在这一刻,我正在努力:

public static Bitmap captureView(View v) {
    Log.v(CAPTURE_TAG, "init");
    v.setDrawingCacheEnabled(true);
    v.buildDrawingCache(true);
    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    //v.destroyDrawingCache();
    v.setDrawingCacheEnabled(false); // clear drawing cache
    Log.v(CAPTURE_TAG, "Fin:");
    return b;
}

and I call this every 50ms, using timer, and AsynTask, on AsynkTask, on onPostExecute method I save the bitmap in external storage: 我使用定时器和AsynTask在AsynkTask上每隔50ms调用一次on on OnPostExecute方法,我将位图保存在外部存储器中:

public class takeCaptureTask extends AsyncTask<View, Void, Bitmap> {

    @Override
    protected void onPostExecute(Bitmap result) {
        Log.v("taskCapt", "Fin - InitSave");
        new saveCaptureTask().execute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Log.v("taskCapt", "init");
    }

    @Override
    protected Bitmap doInBackground(View... params) {
        return Utils.captureView(params[0]);
    }
}

And finally generate video using NDK and ffmpeg. 最后使用NDK和ffmpeg生成视频。

My problem is the performance, using this, every screenshot take 200ms (5FPS), and I need at least 15 FPS. 我的问题是性能,使用这个,每个截图需要200ms(5FPS),我需要至少15 FPS。

My questions are: 我的问题是:
1- I'm in the correct way to do the screen recording without root? 1-我是否以正确的方式在没有root的情况下进行屏幕录制?
2- can I take screenshot of canvas using other methods? 2-我可以使用其他方法截取画布的截图吗?
3- It's posible take screenshots from NDK without root? 3-这可以从没有root的NDK截取屏幕截图吗? in this case, how? 在这种情况下,怎么样?
4- It's faster save data to External Storage using NDK? 4-使用NDK将数据保存到外部存储的速度更快?
5- How buffer a lot of images to process it later? 5-如何缓存大量图像以便以后处理它?

My appologies for my bad English. 我对我英语不好的看法。

Thanks a lot for your help! 非常感谢你的帮助!

This would depend on how you are drawing. 这取决于你的绘画方式。 You can actually using Bitmap and Canvas as a draw buffer, and that would be very easy to capture. 您实际上可以使用Bitmap和Canvas作为绘制缓冲区,这将非常容易捕获。 There's so many ways to do this, including only do a screen cap if there was a change in the view 有很多方法可以做到这一点,包括只在视图发生变化时才进行屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM