show progress of video transformation

show progress of video transformation
pull/166/head
xufulong 5 years ago
parent 55c1a6f3c8
commit 3f4c942273
  1. 24
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  2. 5
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 7
      app/src/main/res/layout/activity_video_handle.xml

@ -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,

@ -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(" ");
}

@ -5,12 +5,11 @@
android:layout_height="match_parent"
tools:context="com.frank.ffmpeg.activity.VideoHandleActivity">
<ProgressBar
android:id="@+id/progress_video"
<include
layout="@layout/item_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"/>
android:layout_centerInParent="true"/>
<ScrollView
android:layout_width="match_parent"

Loading…
Cancel
Save