use superfast of preset to improve speed

master
xufuji456 2 years ago
parent 2a2b3afba6
commit eb743677c1
  1. 14
      app/src/main/java/com/frank/ffmpeg/handler/FFmpegHandler.java
  2. 14
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. BIN
      picture/ffmpeg_group.png

@ -36,6 +36,8 @@ public class FFmpegHandler {
private boolean isContinue = false; private boolean isContinue = false;
private long startTimestamp = 0;
public FFmpegHandler(Handler mHandler) { public FFmpegHandler(Handler mHandler) {
this.mHandler = mHandler; this.mHandler = mHandler;
} }
@ -60,6 +62,7 @@ public class FFmpegHandler {
public void onBegin() { public void onBegin() {
Log.i(TAG, "handle onBegin..."); Log.i(TAG, "handle onBegin...");
mHandler.obtainMessage(MSG_BEGIN).sendToTarget(); mHandler.obtainMessage(MSG_BEGIN).sendToTarget();
startTimestamp = System.currentTimeMillis();
} }
@Override @Override
@ -74,7 +77,16 @@ public class FFmpegHandler {
@Override @Override
public void onEnd(int resultCode, String resultMsg) { public void onEnd(int resultCode, String resultMsg) {
Log.i(TAG, "handle onEnd..."); long time = System.currentTimeMillis() - startTimestamp;
long seconds = time / 1000;
long minute = seconds / 60;
long second = seconds % 60;
long millisecond = time % 1000;
if (minute > 0) {
Log.i(TAG, "handle onEnd time=" + minute + ":" + second + "." + millisecond);
} else {
Log.i(TAG, "handle onEnd time=" + second + "." + millisecond);
}
if (isContinue) { if (isContinue) {
mHandler.obtainMessage(MSG_CONTINUE).sendToTarget(); mHandler.obtainMessage(MSG_CONTINUE).sendToTarget();
} else { } else {

@ -305,13 +305,8 @@ public class FFmpegUtil {
* @return transform video success or not * @return transform video success or not
*/ */
public static String[] transformVideo(String inputPath, String outputPath) { public static String[] transformVideo(String inputPath, String outputPath) {
//just copy codec // preset: ultrafast > superfast > veryfast > fast > medium > slow > veryslow
// String transformVideoCmd = "ffmpeg -i %s -vcodec copy -acodec copy %s"; String transformVideoCmd = "ffmpeg -i -vcodec libx264 -acodec libmp3lame -threads 8 -preset superfast";
// assign the frameRate, bitRate and resolution
// String transformVideoCmd = "ffmpeg -i %s -r 25 -b 200 -s 1080x720 %s";
// assign the encoder
// ffmpeg -i %s -vcodec libx264 -acodec libmp3lame %s
String transformVideoCmd = "ffmpeg -i -vcodec libx264 -acodec libmp3lame";
return insert(transformVideoCmd.split(" "), 2, inputPath, outputPath); return insert(transformVideoCmd.split(" "), 2, inputPath, outputPath);
} }
@ -339,9 +334,9 @@ public class FFmpegUtil {
String transformVideoCmd; String transformVideoCmd;
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
String scale = "-vf scale=" + width + ":" + height; String scale = "-vf scale=" + width + ":" + height;
transformVideoCmd = "ffmpeg -i -vcodec libx264 -acodec aac " + scale; transformVideoCmd = "ffmpeg -i -vcodec libx264 -threads 8 -preset superfast -acodec aac " + scale;
} else { } else {
transformVideoCmd = "ffmpeg -i -vcodec libx264 -acodec aac"; transformVideoCmd = "ffmpeg -i -vcodec libx264 -threads 8 -preset superfast -acodec aac";
} }
return insert(transformVideoCmd.split(" "), 2, inputPath, outputPath); return insert(transformVideoCmd.split(" "), 2, inputPath, outputPath);
} }
@ -572,7 +567,6 @@ public class FFmpegUtil {
* @return reverse success or not * @return reverse success or not
*/ */
public static String[] reverseVideo(String inputPath, String outputPath) { public static String[] reverseVideo(String inputPath, String outputPath) {
//-vf reverse: only video reverse, -an: disable audio
//tip: reverse will cost a lot of time, only short video are recommended //tip: reverse will cost a lot of time, only short video are recommended
String reverseVideo = "ffmpeg -i -vf reverse -an"; String reverseVideo = "ffmpeg -i -vf reverse -an";
return insert(reverseVideo.split(" "), 2, inputPath, outputPath); return insert(reverseVideo.split(" "), 2, inputPath, outputPath);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 60 KiB

Loading…
Cancel
Save