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