【问题标题】:How to take snapshot of videoview while video is playing in android?如何在android中播放视频时拍摄videoview的快照?
【发布时间】:2016-06-08 07:46:50
【问题描述】:

我的黑屏不是视频内容,请帮帮我。

我的代码:

 private Bitmap takeScreenshot() {
    relate.setDrawingCacheEnabled(true);
    relate.buildDrawingCache();
    return relate.getDrawingCache();
}

private void saveBitmap(Bitmap bitmap) {
    //  File imagePath = new File(Environment.getExternalStorageDirectory()     + "/screenshot.png");

    FileOutputStream fos;
    // String path ="data/data/com.focusmedica.eyeactivity/files/Images" +    filename;

    try {
        fos =new FileOutputStream(path);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
        sentmail(path);
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}

我正在使用canvasvideoview 上绘制一些东西。只有我得到黑屏。 我的videoviewrelative layout 里面。 提前致谢.....

【问题讨论】:

  • 你用的是surfaceview还是textureview?
  • 不,我没有同时使用这两个,实际上我是 android 新手,所以我不知道这些东西...@gvsharma

标签: android


【解决方案1】:

您可以从android 获取视频视图的快照或帧。

你可以试试这个代码来获取videoview帧。

    public static Bitmap createVideoThumbnail(Context context, Uri uri, int i)
    {
     MediaMetadataRetriever mediametadataretriever = new MediaMetadataRetriever();

try {
    mediametadataretriever.setDataSource(context, uri);
    Bitmap bitmap = mediametadataretriever.getFrameAtTime(-1L);
    if(null != bitmap)
    {
        int j = getThumbnailSize(context, i);
        return ThumbnailUtils.extractThumbnail(bitmap, j, j, 2);
    }
    return bitmap;
} catch (Throwable t) {
    // TODO log
    return null;
} finally {
    try
    {
        mediametadataretriever.release();
    }
    catch(RuntimeException e) { }
    }
}

您可以根据需要使用此方法。

【讨论】:

  • 谢谢兄弟,这个方法帮了我很多..@gvsharma
  • @GvSharma 你能告诉我什么是 getThumbnailSize
  • @GowthamanM,它是一种调整位图高度和宽度的方法。
【解决方案2】:

我有一个替代解决方案来替换Android MediaMetadataRetrievergetFrameAt 方法。 AV_FrameCapture 使用MediaCodec 解码视频帧并使用OpenGL 将视频帧转换为RGB 位图。由于AndroidMediaMetadataRetriever不保证调用getFrameAtTime时返回结果,所以这个AV_FrameCapture可以用来提取一帧视频,准确度

https://stackoverflow.com/a/60633395/6676310

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    • 2012-05-11
    相关资源
    最近更新 更多