Java obtains video time of video file
1. Import maven dependencies
<dependency> <groupId>org.mp4parser</groupId> <artifactId>isoparser</artifactId> <version>1.9.41</version> </dependency>
2. Code cases
import .; import org.; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import .*; public class Test { public static void main(String[] args) throws ParseException { long spsj = readDuration(("C:\\Users\\Administrator\\Desktop\\ceshi.mp4")); (spsj); } public static long readDuration(Path mp4Path) { if ((mp4Path) || !(mp4Path)) { ("The file path does not exist or is unreadable" + mp4Path); return 0; } try { IsoFile isoFile = new IsoFile(()); long duration = ().getMovieHeaderBox().getDuration(); long timescale = ().getMovieHeaderBox().getTimescale(); return duration / timescale; } catch (IOException e) { (); return 0; } } }
3、SLF4J: Failed to load class “org.”
If an error is reported during operation:
SLF4J: Failed to load class "org.".
Problem analysis:
org.
Usually present inand
In this article, although the simple package has been introduced into the project maven, there is still an error.
This indicates that the simple package is not actually loaded.
In order to make the package load better, the problem was solved after adding type as jar to the dependency.
<!-- Depend on software version --> <properties> <>1.7.30</> </properties> <!-- /artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${}</version> </dependency> <!-- /artifact/org.slf4j/slf4j-simple--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>${}</version> <!-- Notice,If nothingtypeforjarAn error is reported--> <type>jar</type> </dependency>
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.