Skip to content

Commit eb74367

Browse files
author
xufuji456
committed
use superfast of preset to improve speed
1 parent 2a2b3af commit eb74367

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

‎app/src/main/java/com/frank/ffmpeg/handler/FFmpegHandler.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class FFmpegHandler {
3636

3737
private boolean isContinue = false;
3838

39+
private long startTimestamp = 0;
40+
3941
public FFmpegHandler(Handler mHandler) {
4042
this.mHandler = mHandler;
4143
}
@@ -60,6 +62,7 @@ public void executeFFmpegCmd(final String[] commandLine) {
6062
public void onBegin() {
6163
Log.i(TAG, "handle onBegin...");
6264
mHandler.obtainMessage(MSG_BEGIN).sendToTarget();
65+
startTimestamp = System.currentTimeMillis();
6366
}
6467

6568
@Override
@@ -74,7 +77,16 @@ public void onProgress(int progress, int duration) {
7477

7578
@Override
7679
public void onEnd(int resultCode, String resultMsg) {
77-
Log.i(TAG, "handle onEnd...");
80+
long time = System.currentTimeMillis() - startTimestamp;
81+
long seconds = time / 1000;
82+
long minute = seconds / 60;
83+
long second = seconds % 60;
84+
long millisecond = time % 1000;
85+
if (minute > 0) {
86+
Log.i(TAG, "handle onEnd time=" + minute + ":" + second + "." + millisecond);
87+
} else {
88+
Log.i(TAG, "handle onEnd time=" + second + "." + millisecond);
89+
}
7890
if (isContinue) {
7991
mHandler.obtainMessage(MSG_CONTINUE).sendToTarget();
8092
} else {

‎app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,8 @@ public static String[] extractVideo(String inputPath, String outputPath) {
305305
* @return transform video success or not
306306
*/
307307
public static String[] transformVideo(String inputPath, String outputPath) {
308-
//just copy codec
309-
// String transformVideoCmd = "ffmpeg -i %s -vcodec copy -acodec copy %s";
310-
// assign the frameRate, bitRate and resolution
311-
// String transformVideoCmd = "ffmpeg -i %s -r 25 -b 200 -s 1080x720 %s";
312-
// assign the encoder
313-
// ffmpeg -i %s -vcodec libx264 -acodec libmp3lame %s
314-
String transformVideoCmd = "ffmpeg -i -vcodec libx264 -acodec libmp3lame";
308+
// preset: ultrafast > superfast > veryfast > fast > medium > slow > veryslow
309+
String transformVideoCmd = "ffmpeg -i -vcodec libx264 -acodec libmp3lame -threads 8 -preset superfast";
315310
return insert(transformVideoCmd.split(" "), 2, inputPath, outputPath);
316311
}
317312

@@ -339,9 +334,9 @@ public static String[] transformVideoWithEncode(String inputPath, int width, int
339334
String transformVideoCmd;
340335
if (width > 0 && height > 0) {
341336
String scale = "-vf scale=" + width + ":" + height;
342-
transformVideoCmd = "ffmpeg -i -vcodec libx264 -acodec aac " + scale;
337+
transformVideoCmd = "ffmpeg -i -vcodec libx264 -threads 8 -preset superfast -acodec aac " + scale;
343338
} else {
344-
transformVideoCmd = "ffmpeg -i -vcodec libx264 -acodec aac";
339+
transformVideoCmd = "ffmpeg -i -vcodec libx264 -threads 8 -preset superfast -acodec aac";
345340
}
346341
return insert(transformVideoCmd.split(" "), 2, inputPath, outputPath);
347342
}
@@ -572,7 +567,6 @@ public static String[] multiVideo(String input1, String input2, String outputPat
572567
* @return reverse success or not
573568
*/
574569
public static String[] reverseVideo(String inputPath, String outputPath) {
575-
//-vf reverse: only video reverse, -an: disable audio
576570
//tip: reverse will cost a lot of time, only short video are recommended
577571
String reverseVideo = "ffmpeg -i -vf reverse -an";
578572
return insert(reverseVideo.split(" "), 2, inputPath, outputPath);

‎picture/ffmpeg_group.png‎

-88.4 KB
Loading

0 commit comments

Comments
 (0)