Java code get video length

Source: Internet
Author: User

Java code get video length

1  Packagetest;2 3 ImportJava.io.File;4 ImportJava.math.BigDecimal;5 6 ImportIt.sauronsoftware.jave.Encoder;7 ImportIt.sauronsoftware.jave.MultimediaInfo;8 9 Ten  Public classReadvideo { One     /** A * Length of time to read video -      * @paramVideopath Video Path -      * @return the      */     -      Public Staticstring Readvideo (String videopath) { -String durationstr = ""; -File File =NewFile (Videopath);//Videopath Incoming value ("D:\\666.mp4") +Encoder Encoder =NewEncoder (); -         Longsum = 0; +         Try { AMultimediainfo m =encoder.getinfo (file); atsum = m.getduration ()/1000;//duration sum unit: Seconds -              -}Catch(Exception e) { - e.printstacktrace (); -         } -         DoubleSUM1 = (Double) sum; inSystem.out.println ("Video duration total seconds:" +sum1); -          toBigDecimal Duration =bigdecimal.valueof (sum); +Durationstr =durationformattostring (duration); -System.out.println ("Video duration:" +durationstr); the          *         returnDurationstr; $     }Panax Notoginseng      -     /** the * Convert video duration to "00:00:00.000" string format +      * @paramDuration Video Duration (units: seconds) A      * @return the      */ +      Public StaticString durationformattostring (BigDecimal duration) -     { $BigDecimal nine = bigdecimal.valueof (9); $BigDecimal sixty = bigdecimal.valueof (60);  -          -BigDecimal second = Duration.divideandremainder (sixty) [1]; theBigDecimal minute = Duration.subtract (second). Divide (sixty). Divideandremainder (sixty) [1]; -BigDecimal hour = duration.subtract (second). Dividetointegralvalue (bigdecimal.valueof (3600));Wuyi          theString str = ""; -         if(Hour.compareto (Nine) >0) Wu         { -str + = Hour.intvalue () + ":"; About         } $         Else -         { -str + = "0" + hour.intvalue () + ":"; -         } A         if(Minute.compareto (Nine) >0) +         { thestr + = Minute.intvalue () + ":"; -         } $         Else the         { thestr + = "0" + minute.intvalue () + ":"; the         } the         if(Second.compareto (Nine) >0) -         { instr + = Second.intvalue () + ". 000"; the         } the         Else About         { thestr + = "0" + second.intvalue () + ". 000"; the         } the         returnstr; +     } -  the}

Need to introduce JAR packages

http://www.sauronsoftware.it/projects/jave/download.php

Https://pan.baidu.com/s/1slTz7it

Reference URL: http://www.cnblogs.com/mysgk/p/4117134.html

Java code get video length

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.