springBoot获取上传视频的时长

  • Post author:
  • Post category:其他


1.依赖

  <!-- 此依赖网上仓库没有,需自己找到,手动安装到本地仓库 -->
	<dependency>
        <groupId>local</groupId>
        <artifactId>jave</artifactId>
        <version>1.0.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.3</version>
    </dependency>
  1. 启动类 添加(此步是为了让文件支持强转):

    @SpringBootApplication( exclude = {MultipartAutoConfiguration.class})

    @Bean(“multipartResolver”)

    public CommonsMultipartResolver multipartResolver(){


    CommonsMultipartResolver resolver = new CommonsMultipartResolver();

    resolver.setDefaultEncoding(“UTF-8”);

    resolver.setMaxInMemorySize(10000);

    return resolver;

    }

    在这里插入图片描述

    3.代码:

    public AttachmentDTO uploadVideo(MultipartFile multipartFile) {


    //强转(步骤2就是为这铺垫)

    CommonsMultipartFile cf = (CommonsMultipartFile)multipartFile;

    DiskFileItem fi = (DiskFileItem) cf.getFileItem();

    java.io.File source = fi.getStoreLocation();

    // 获取视频时长

    Encoder encoder = new Encoder();

    MultimediaInfo m = null;

    m = encoder.getInfo(source);

    long ls = m.getDuration()/1000;

    int hour = (int) (ls/3600);

    int minute = (int) (ls%3600)/60;

    int second = (int) (ls-hour

    3600-minute

    60);

    }



版权声明:本文为weixin_44315847原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。