From 3f4c9422736df8f5e21d898971e17520952c10fa Mon Sep 17 00:00:00 2001
From: xufulong <839789740@qq.com>
Date: Thu, 18 Jun 2020 00:04:21 +0800
Subject: [PATCH] show progress of video transformation
show progress of video transformation
---
.../ffmpeg/activity/VideoHandleActivity.java | 24 +++++++++++++++----
.../com/frank/ffmpeg/util/FFmpegUtil.java | 5 ++--
.../main/res/layout/activity_video_handle.xml | 7 +++---
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
index b627fa9..30ac0bc 100644
--- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
+++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
@@ -10,7 +10,7 @@ import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
-import android.widget.ProgressBar;
+import android.widget.TextView;
import com.frank.ffmpeg.FFmpegCmd;
import com.frank.ffmpeg.R;
@@ -25,9 +25,11 @@ import com.frank.ffmpeg.util.FileUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_BEGIN;
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH;
+import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_PROGRESS;
/**
* video process by FFmpeg command
@@ -38,8 +40,9 @@ public class VideoHandleActivity extends BaseActivity {
private final static String TAG = VideoHandleActivity.class.getSimpleName();
private static final String PATH = Environment.getExternalStorageDirectory().getPath();
- private ProgressBar progressVideo;
private LinearLayout layoutVideoHandle;
+ private LinearLayout layoutProgress;
+ private TextView txtProgress;
private int viewId;
private FFmpegHandler ffmpegHandler;
private final static boolean useFFmpegCmd = true;
@@ -55,13 +58,23 @@ public class VideoHandleActivity extends BaseActivity {
super.handleMessage(msg);
switch (msg.what) {
case MSG_BEGIN:
- progressVideo.setVisibility(View.VISIBLE);
+ layoutProgress.setVisibility(View.VISIBLE);
layoutVideoHandle.setVisibility(View.GONE);
break;
case MSG_FINISH:
- progressVideo.setVisibility(View.GONE);
+ layoutProgress.setVisibility(View.GONE);
layoutVideoHandle.setVisibility(View.VISIBLE);
break;
+ case MSG_PROGRESS:
+ int progress = msg.arg1;
+ int duration = msg.arg2;
+ if (progress > 0) {
+ txtProgress.setVisibility(View.VISIBLE);
+ txtProgress.setText(String.format(Locale.getDefault(), "%d%%", progress));
+ } else {
+ txtProgress.setVisibility(View.INVISIBLE);
+ }
+ break;
default:
break;
}
@@ -83,7 +96,8 @@ public class VideoHandleActivity extends BaseActivity {
}
private void intView() {
- progressVideo = getView(R.id.progress_video);
+ layoutProgress = getView(R.id.layout_progress);
+ txtProgress = getView(R.id.txt_progress);
layoutVideoHandle = getView(R.id.layout_video_handle);
initViewsWithClick(
R.id.btn_video_transform,
diff --git a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
index 449226f..7aeaa28 100644
--- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
+++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
@@ -143,11 +143,12 @@ public class FFmpegUtil {
* @return transform video success or not
*/
public static String[] transformVideo(String srcFile, String targetFile) {
+ //just copy codec
+// String transformVideoCmd = "ffmpeg -i %s -vcodec copy -acodec copy %s";
// assign the frameRate, bitRate and resolution
// String transformVideoCmd = "ffmpeg -i %s -r 25 -b 200 -s 1080x720 %s";
// assign the encoder
-// String transformVideoCmd = "ffmpeg -i %s -vcodec libx264 -acodec copy %s";
- String transformVideoCmd = "ffmpeg -i %s -vcodec copy -acodec copy %s";
+ String transformVideoCmd = "ffmpeg -i %s -vcodec libx264 -acodec libmp3lame %s";
transformVideoCmd = String.format(transformVideoCmd, srcFile, targetFile);
return transformVideoCmd.split(" ");
}
diff --git a/app/src/main/res/layout/activity_video_handle.xml b/app/src/main/res/layout/activity_video_handle.xml
index 28a49ed..752d80d 100644
--- a/app/src/main/res/layout/activity_video_handle.xml
+++ b/app/src/main/res/layout/activity_video_handle.xml
@@ -5,12 +5,11 @@
android:layout_height="match_parent"
tools:context="com.frank.ffmpeg.activity.VideoHandleActivity">
-
+ android:layout_centerInParent="true"/>