利用阿里云OSS的下载链接实现视频截帧

我以前是拿到自己文件服务器的文件url
但是使用了OSS之后不需要那么麻烦了,测试了一下,文件链接确实可以截帧
代码

 /**
     * 捕捉图片第一帧
     * @throws Exception
     */
    public static void fetchFrame(String videoUrl,String imgUrl)throws Exception{
//

        FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoUrl);
        Java2DFrameConverter converter = new Java2DFrameConverter();
        frameGrabber.start();
        //解码长度
        int length = frameGrabber.getLengthInFrames();
        //时间
        int i = 0;
        Frame frame = null;
        while(i < length){
            //过滤前五帧,避免出现全黑的图片
            frame = frameGrabber.grabFrame();
            if(i > 10 && (frame.image != null)){
                break;
            }
            i ++;
        }
        // Frame frame = frameGrabber.grabFrame();
        BufferedImage bufferedImage = converter.convert(frame);
        //照片保存文件夹
        File targetFile = new File(imgUrl);
        //文件夹不存在就新建
        if(!targetFile.isDirectory()){
            targetFile.mkdirs();
        }
        //写入文件夹,以jpg图片格式
        ImageIO.write(bufferedImage, "jpg", targetFile);
        //停止转化为帧
        frameGrabber.stop();
    }
发布了29 篇原创文章 · 获赞 3 · 访问量 546

猜你喜欢

转载自blog.csdn.net/weixin_43404791/article/details/104651136