A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© zzj123 黑马粉丝团   /  2017-6-13 14:10  /  1471 人查看  /  0 人回复  /   2 人收藏 转载请遵从CC协议 禁止商业使用本文

Java读取视频时长


JAVE
The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project. Developers can take take advantage of JAVE to transcode audio and video files from a format to another. In example you cantranscode an AVI file to a MPEG one, you can change a DivX video stream into a (youtube like) Flash FLV one, you can convert a WAV audio file to a MP3 or a Ogg Vorbis one, you can separate and transcode audio and video tracks, you can resize videos, changing their sizes and proportions and so on. Many other formats, containers and operations are supported by JAVE.
如下网址是此工具包下载地址:http://www.sauronsoftware.it/projects/jave/index.php

用该API读取视频属性实例代码如下:
1.package com.itheima;
2.
3.import it.sauronsoftware.jave.Encoder;
4.import it.sauronsoftware.jave.MultimediaInfo;
5.
6.import java.io.File;
7.
8.public class ReadVideo {
9.
10.    public static void main(String[] args){
11.        File source = new File("E:\\测试视频\\R41.avi");
12.        Encoder encoder = new Encoder();
13.        try {
14.             MultimediaInfo m = encoder.getInfo(source);
15.             long ls = m.getDuration();
16.             System.out.println("此视频时长为:"+ls/60000+"分"+(ls`000)/1000+"秒!");
17.        } catch (Exception e) {
18.            e.printStackTrace();
19.        }
20.    }
21.}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马