| | |
| | | |
| | | import com.coremedia.iso.IsoFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | |
| | | |
| | |
| | | * @return 单位为毫秒 |
| | | */ |
| | | public static long getMp4Duration(String videoPath) throws IOException { |
| | | IsoFile isoFile = new IsoFile(videoPath); |
| | | long lengthInSeconds = |
| | | isoFile.getMovieBox().getMovieHeaderBox().getDuration() / |
| | | isoFile.getMovieBox().getMovieHeaderBox().getTimescale(); |
| | | return lengthInSeconds; |
| | | try { |
| | | File file = File.createTempFile("temp", ".mp4"); //创建临时文件 |
| | | Image2Binary.toBDFile(videoPath,file.getCanonicalPath()); |
| | | IsoFile isoFile = new IsoFile(file.getPath()); |
| | | long lengthInSeconds = |
| | | isoFile.getMovieBox().getMovieHeaderBox().getDuration() / |
| | | isoFile.getMovieBox().getMovieHeaderBox().getTimescale(); |
| | | return lengthInSeconds; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | |