相关疑难解决方法(0)

android捕获视频帧

我需要获取一个视频文件的框架(它可能在sdcard,cache dir或app dir上).我在我的应用程序中有android.media包,我有类MediaMetadataRetriever.要将第一帧放入位图,我使用代码:

public static Bitmap getVideoFrame(Context context, Uri videoUri) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setMode(MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY);
        retriever.setDataSource(context, videoUri);
        return retriever.captureFrame();
    } catch (IllegalArgumentException ex) {
        throw new RuntimeException();
    } catch (RuntimeException ex) {
        throw new RuntimeException();
    } finally {
        retriever.release();
    }
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用.当我设置数据源时,它抛出异常(java.lang.RuntimeException:setDataSource failed:status = 0x80000000).你知道怎么让这段代码工作吗?或者你有没有使用ffmpeg或其他外部库的类似(简单)解决方案?videoUri是一个有效的uri(媒体播放器可以播放来自该URI的视频)

video android frame capture

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

capture ×1

frame ×1

video ×1