forked from kokorin/Jaffree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExactDurationExample.java
38 lines (31 loc) · 1.29 KB
/
ExactDurationExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package examples;
import com.github.kokorin.jaffree.ffmpeg.FFmpeg;
import com.github.kokorin.jaffree.ffmpeg.FFmpegProgress;
import com.github.kokorin.jaffree.ffmpeg.FFmpegResult;
import com.github.kokorin.jaffree.ffmpeg.NullOutput;
import com.github.kokorin.jaffree.ffmpeg.ProgressListener;
import com.github.kokorin.jaffree.ffmpeg.UrlInput;
import java.util.concurrent.atomic.AtomicLong;
public class ExactDurationExample {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Exactly 1 argument expected: path to media file");
System.exit(1);
}
String pathToVideo = args[0];
final AtomicLong durationMillis = new AtomicLong();
FFmpegResult ffmpegResult = FFmpeg.atPath()
.addInput(
UrlInput.fromUrl(pathToVideo)
)
.addOutput(new NullOutput())
.setProgressListener(new ProgressListener() {
@Override
public void onProgress(FFmpegProgress progress) {
durationMillis.set(progress.getTimeMillis());
}
})
.execute();
System.out.println("Exact duration: " + durationMillis.get() + " milliseconds");
}
}