jar

		<!-- 获取视频第一帧依赖 -->
       <dependency>
           <groupId>org.bytedeco</groupId>
           <artifactId>javacpp</artifactId>
           <version>1.4.1</version>
       </dependency>
       <dependency>
           <groupId>org.bytedeco</groupId>
           <artifactId>javacv</artifactId>
           <version>1.4.1</version>
       </dependency>
       <dependency>
           <groupId>org.bytedeco.javacpp-presets</groupId>
           <artifactId>ffmpeg-platform</artifactId>
           <version>3.4.2-1.4.1</version>
       </dependency>

代码

package com.qike.aliyun.media.utils;

import org.bytedeco.javacv.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

public class VideoFrameGrabber {

    public static void main(String[] args) throws Exception {
		// 视频地址
        FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("https://douyin-xjy.oss-cn-hangzhou.aliyuncs.com/douyin-xjy/hecheng/2023/04/18/fe5bc62a0b6e4500b1d2ad60541222f9.mp4");

        grabber.start();

        Java2DFrameConverter converter = new Java2DFrameConverter();

        BufferedImage image = converter.convert(grabber.grabImage());
		// 本地图片保存地址
        ImageIO.write(image, "png", new File("/Users/liushuangshuang/Desktop/图片/first_frame.png"));

        grabber.stop();

    }

}

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐