Add ffmpeg test page

master
徐灿辉 5 years ago
parent 1812b5525e
commit 5c2d973b32
  1. 8
      app/src/main/AndroidManifest.xml
  2. 72
      app/src/main/java/com/github/xch168/ffmpeg/invoker/demo/FFmpegTestActivity.java
  3. 4
      app/src/main/java/com/github/xch168/ffmpeg/invoker/demo/MainActivity.java
  4. 27
      app/src/main/res/layout/activity_ffmpeg_test.xml
  5. 8
      app/src/main/res/layout/activity_main.xml

@ -1,14 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.github.xch168.ffmpeg.invoker.demo"> package="com.github.xch168.ffmpeg.invoker.demo">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme"
tools:ignore="AllowBackup">
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -16,6 +21,7 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".FFmpegTestActivity"/>
</application> </application>
</manifest> </manifest>

@ -0,0 +1,72 @@
package com.github.xch168.ffmpeg.invoker.demo;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Looper;
import android.view.View;
import android.widget.Toast;
import com.github.xch168.ffmpeg.invoker.FFmpegInvoker;
import java.io.File;
public class FFmpegTestActivity extends AppCompatActivity {
private String videoPath = "/storage/emulated/0/DCIM/Camera/fb639313f7f3d58cc793f20095439c88.mp4";
private FFmpegInvoker.Callback mCallback = new FFmpegInvoker.Callback() {
@Override
public void onSuccess() {
Looper.prepare();
Toast.makeText(FFmpegTestActivity.this, "处理成功", Toast.LENGTH_SHORT).show();
Looper.loop();
}
@Override
public void onFailure() {
Looper.prepare();
Toast.makeText(FFmpegTestActivity.this, "处理失败", Toast.LENGTH_SHORT).show();
Looper.loop();
}
@Override
public void onProgress(float progress) {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ffmpeg_test);
}
public static void open(Context context) {
Intent intent = new Intent(context, FFmpegTestActivity.class);
context.startActivity(intent);
}
public void cutVideo(View view) {
String savePath = getSaveDir() + "out.mp4";
String cmd = "ffmpeg -y -ss 1 -t 100 -accurate_seek -i " + videoPath + " -codec copy " + savePath;
FFmpegInvoker.exec(cmd.split(" "), 100, mCallback);
}
public void extractFrame(View view) {
String savePath = getSaveDir() + "out.png";
String cmd = "ffmpeg -ss 10 -i " + videoPath + " -vframes 1 -y " + savePath;
FFmpegInvoker.exec(cmd.split(" "), 100, mCallback);
}
public static String getSaveDir() {
String savePath = Environment.getExternalStorageDirectory().getPath() + "/FFmpegInvoker/";
File file = new File(savePath);
if (!file.exists()) {
file.mkdirs();
}
return savePath;
}
}

@ -60,4 +60,8 @@ public class MainActivity extends AppCompatActivity {
} }
return configInfoBuilder.toString(); return configInfoBuilder.toString();
} }
public void toTestFFmpeg(View view) {
FFmpegTestActivity.open(this);
}
} }

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.github.xch168.ffmpeg.invoker.demo.FFmpegTestActivity">
<Button
android:id="@+id/btn_cut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:text="剪辑"
android:onClick="cutVideo"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/btn_cut"
app:layout_constraintLeft_toRightOf="@+id/btn_cut"
android:layout_marginLeft="10dp"
android:text="提取帧"
android:onClick="extractFrame"/>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -6,6 +6,14 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="com.github.xch168.ffmpeg.invoker.demo.MainActivity"> tools:context="com.github.xch168.ffmpeg.invoker.demo.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:text="进入测试"
android:onClick="toTestFFmpeg"/>
<TextView <TextView
android:id="@+id/tv_cpu_abi" android:id="@+id/tv_cpu_abi"
android:layout_width="wrap_content" android:layout_width="wrap_content"

Loading…
Cancel
Save