From b91a61f0eacaba656d64fcd5d44404a3b611662b Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Sat, 10 Oct 2020 00:12:35 +0800 Subject: [PATCH] buld keyframe index of flv buld keyframe index of flv --- .../frank/ffmpeg/activity/VideoHandleActivity.java | 11 ++++++++++- .../main/java/com/frank/ffmpeg/util/FFmpegUtil.java | 12 ++++++++++++ app/src/main/res/layout/activity_video_handle.xml | 7 +++++++ app/src/main/res/values-en/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 31 insertions(+), 1 deletion(-) 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 0911e46..cf714ad 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java @@ -128,7 +128,8 @@ public class VideoHandleActivity extends BaseActivity { R.id.btn_to_image, R.id.btn_pip, R.id.btn_moov, - R.id.btn_speed + R.id.btn_speed, + R.id.btn_flv ); } @@ -310,6 +311,14 @@ public class VideoHandleActivity extends BaseActivity { String speed = PATH + File.separator + "speed.mp4"; commandLine = FFmpegUtil.changeSpeed(srcFile, speed, 2f, false); break; + case R.id.btn_flv://rebuild the keyframe index of flv + if (!".flv".equalsIgnoreCase(FileUtil.getFileSuffix(srcFile))) { + Log.e(TAG, "It's not flv file, suffix=" + FileUtil.getFileSuffix(srcFile)); + return; + } + String outputPath = PATH + File.separator + "frame_index.flv"; + commandLine = FFmpegUtil.buildFlvIndex(srcFile, outputPath); + break; default: break; } 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 46dd2e1..57d9507 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -520,4 +520,16 @@ public class FFmpegUtil { return speedCmd.split(" "); } + /** + * Rebuild the keyframe index of FLV, make it seekable + * @param inputFile inputFile + * @param targetFile targetFile + * @return command of build flv index + */ + public static String[] buildFlvIndex(String inputFile, String targetFile) { + String denoiseVideo = "ffmpeg -i %s -flvflags add_keyframe_index %s"; + denoiseVideo = String.format(denoiseVideo, inputFile, targetFile); + return denoiseVideo.split(" "); + } + } diff --git a/app/src/main/res/layout/activity_video_handle.xml b/app/src/main/res/layout/activity_video_handle.xml index 752d80d..6e4ebe3 100644 --- a/app/src/main/res/layout/activity_video_handle.xml +++ b/app/src/main/res/layout/activity_video_handle.xml @@ -128,6 +128,13 @@ android:layout_marginTop="4dp" android:text="@string/video_speed"/> +