• Java获取视频的大小、时长


    前端上传视频之后,根据上传的视频文件获取视频的大小和时长

    1、获取视频时长

    private String ReadVideoTime(File source) {
    Encoder encoder = new Encoder();
    String length = "";
    try {
    MultimediaInfo 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);
    length = hour+"'"+minute+"''"+second+"'''";
    } catch (Exception e) {
    e.printStackTrace();
    }
    return length;
    }

    2、获取视频大小

    /**
    * 获取视频大小
    * @param source
    * @return
    */
    private String ReadVideoSize(File source) {
    FileChannel fc= null;
    String size = "";
    try {
    @SuppressWarnings("resource")
    FileInputStream fis = new FileInputStream(source);
    fc= fis.getChannel();
    BigDecimal fileSize = new BigDecimal(fc.size());
    size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (null!=fc){
    try{
    fc.close();
    }catch(IOException e){
    e.printStackTrace();
    }
    }
    }
    return size;
    }

    ***获取视频大小的时候,由于用到了流,使用完之后一定要及时的关闭流,避免无法删除视频文件***

  • 相关阅读:
    TPLINK TLWR710N设置详解
    hehe.....
    AS3写FTP登录过程
    QQ
    网页设计标准尺寸:
    女孩,你愿意做他的第几个女朋友
    監聽一個變量的值變化
    dispatchEvent
    10
    C#常用代码
  • 原文地址:https://www.cnblogs.com/dalianmao890710/p/7344306.html
Copyright © 2020-2023  润新知