1
- FFmpeg Java
2
- ===========
1
+ # FFmpeg CLI Wrapper for Java
3
2
4
- by Andrew Brampton ([ bramp.net] ( https://bramp.net ) ) (c) 2013-2014,2016
3
+ by Andrew Brampton ([ bramp.net] ( https://bramp.net ) ) (c) 2013-2024
5
4
6
5
[ ![ "Buy Me A Coffee"] ( https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png )] ( https://www.buymeacoffee.com/bramp )
7
6
8
- A fluent interface to running FFmpeg from Java.
7
+ A fluent interface for running FFmpeg from Java.
9
8
10
9
![ Java] ( https://img.shields.io/badge/Java-8+-brightgreen.svg )
11
10
[ ![ Build Status] ( https://github.com/bramp/ffmpeg-cli-wrapper/actions/workflows/maven.yml/badge.svg )] ( https://github.com/bramp/ffmpeg-cli-wrapper/actions/workflows/maven.yml )
@@ -15,8 +14,7 @@ A fluent interface to running FFmpeg from Java.
15
14
16
15
[ GitHub] ( https://github.com/bramp/ffmpeg-cli-wrapper ) | [ API docs] ( https://bramp.github.io/ffmpeg-cli-wrapper/ )
17
16
18
- Install
19
- -------
17
+ ## Install
20
18
21
19
We currently support Java 8 and above. Use Maven to install the dependency.
22
20
@@ -28,12 +26,12 @@ We currently support Java 8 and above. Use Maven to install the dependency.
28
26
</dependency >
29
27
```
30
28
31
- Usage
32
- -----
29
+ ## Usage
33
30
34
31
### Video Encoding
35
32
36
33
Code:
34
+
37
35
``` java
38
36
FFmpeg ffmpeg = new FFmpeg (" /path/to/ffmpeg" );
39
37
FFprobe ffprobe = new FFprobe (" /path/to/ffprobe" );
@@ -73,64 +71,67 @@ executor.createTwoPassJob(builder).run();
73
71
### Get Media Information
74
72
75
73
Code:
74
+
76
75
``` java
77
76
FFprobe ffprobe = new FFprobe (" /path/to/ffprobe" );
78
77
FFmpegProbeResult probeResult = ffprobe. probe(" input.mp4" );
79
78
80
79
FFmpegFormat format = probeResult. getFormat();
81
80
System . out. format(" %nFile: '%s' ; Format: '%s' ; Duration: %.3fs" ,
82
- format. filename,
83
- format. format_long_name,
84
- format. duration
81
+ format. filename,
82
+ format. format_long_name,
83
+ format. duration
85
84
);
86
85
87
86
FFmpegStream stream = probeResult. getStreams(). get(0 );
88
87
System . out. format(" %nCodec: '%s' ; Width: %dpx ; Height: %dpx" ,
89
- stream. codec_long_name,
90
- stream. width,
91
- stream. height
88
+ stream. codec_long_name,
89
+ stream. width,
90
+ stream. height
92
91
);
93
92
```
94
93
95
94
### Get progress while encoding
95
+
96
96
``` java
97
97
FFmpegExecutor executor = new FFmpegExecutor (ffmpeg, ffprobe);
98
98
99
99
FFmpegProbeResult in = ffprobe. probe(" input.flv" );
100
100
101
101
FFmpegBuilder builder = new FFmpegBuilder ()
102
- .setInput(in) // Or filename
103
- .addOutput(" output.mp4" )
104
- .done();
102
+ .setInput(in) // Or filename
103
+ .addOutput(" output.mp4" )
104
+ .done();
105
105
106
106
FFmpegJob job = executor. createJob(builder, new ProgressListener () {
107
107
108
- // Using the FFmpegProbeResult determine the duration of the input
109
- final double duration_ns = in. getFormat(). duration * TimeUnit . SECONDS. toNanos(1 );
110
-
111
- @Override
112
- public void progress (Progress progress ) {
113
- double percentage = progress. out_time_ns / duration_ns;
114
-
115
- // Print out interesting information about the progress
116
- System . out. println(String . format(
117
- " [%.0f%%] status:%s frame:%d time:%s ms fps:%.0f speed:%.2fx" ,
118
- percentage * 100 ,
119
- progress. status,
120
- progress. frame,
121
- FFmpegUtils . toTimecode(progress. out_time_ns, TimeUnit . NANOSECONDS ),
122
- progress. fps. doubleValue(),
123
- progress. speed
124
- ));
125
- }
108
+ // Using the FFmpegProbeResult determine the duration of the input
109
+ final double duration_ns = in. getFormat(). duration * TimeUnit . SECONDS. toNanos(1 );
110
+
111
+ @Override
112
+ public void progress (Progress progress ) {
113
+ double percentage = progress. out_time_ns / duration_ns;
114
+
115
+ // Print out interesting information about the progress
116
+ System . out. println(String . format(
117
+ " [%.0f%%] status:%s frame:%d time:%s ms fps:%.0f speed:%.2fx" ,
118
+ percentage * 100 ,
119
+ progress. status,
120
+ progress. frame,
121
+ FFmpegUtils . toTimecode(progress. out_time_ns, TimeUnit . NANOSECONDS ),
122
+ progress. fps. doubleValue(),
123
+ progress. speed
124
+ ));
125
+ }
126
126
});
127
127
128
128
job. run();
129
129
```
130
130
131
- Building & Releasing
132
- --------------
131
+ ## Building & Releasing
132
+
133
133
If you wish to make changes, then building and releasing is simple:
134
+
134
135
``` bash
135
136
# To build
136
137
mvn
@@ -148,8 +149,7 @@ git checkout ffmpeg-0.x
148
149
mvn clean javadoc:aggregate scm-publish:publish-scm
149
150
```
150
151
151
- Bumpings Deps
152
- -----
152
+ ## Bumpings Deps
153
153
154
154
``` bash
155
155
# Update Maven Plugins
@@ -159,26 +159,24 @@ mvn versions:display-plugin-updates
159
159
mvn versions:display-dependency-updates
160
160
```
161
161
162
- Install FFmpeg on Ubuntu
163
- -----------------
162
+ ## Install FFmpeg on Ubuntu
164
163
165
164
We only the support the original FFmpeg, not the libav version. Before Ubuntu 12.04, and in 15.04
166
165
and later the original FFmpeg is shipped. If you have to run on a version with libav, you can install
167
166
FFmpeg from a PPA, or using the static build. More information [ here] ( http://askubuntu.com/q/373322/34845 )
168
167
169
- Get involved!
170
- -------------
168
+ ## Get involved
171
169
172
170
We welcome contributions. Please check the [ issue tracker] ( https://github.com/bramp/ffmpeg-cli-wrapper/issues ) .
173
171
If you see something you wish to work on, please either comment on the issue, or just send a pull
174
172
request. Want to work on something else, then just open a issue, and we can discuss! We appreciate
175
173
documentation improvements, code cleanup, or new features. Please be mindful that all work is done
176
174
on a volunteer basis, thus we can be slow to reply.
177
175
178
- Licence (Simplified BSD License)
179
- --------------------------------
180
- ```
181
- Copyright (c) 2016-2022 , Andrew Brampton
176
+ ## Licence (Simplified BSD License)
177
+
178
+ ``` plaintext
179
+ Copyright (c) 2013-2024 , Andrew Brampton
182
180
All rights reserved.
183
181
184
182
Redistribution and use in source and binary forms, with or without
0 commit comments