From 0e6e6ccba55143febf16f95e00f7f180e1d43da9 Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Sat, 24 Jul 2021 00:06:52 +0800 Subject: [PATCH] set the rotate degree of video --- .../com/frank/ffmpeg/activity/VideoHandleActivity.kt | 10 ++++++++-- .../main/java/com/frank/ffmpeg/util/FFmpegUtil.java | 6 ++++++ app/src/main/res/layout/activity_video_handle.xml | 7 +++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt index 5df9aa1..fdf0006 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt @@ -118,7 +118,8 @@ class VideoHandleActivity : BaseActivity() { R.id.btn_speed, R.id.btn_flv, R.id.btn_thumbnail, - R.id.btn_add_subtitle + R.id.btn_add_subtitle, + R.id.btn_rotate ) } @@ -328,11 +329,16 @@ class VideoHandleActivity : BaseActivity() { } R.id.btn_add_subtitle//add subtitle into video -> { - Log.e(TAG, "add subtitle...") val subtitlePath = PATH + File.separator + "test.ass" val addSubtitlePath = PATH + File.separator + "subtitle" + suffix commandLine = FFmpegUtil.addSubtitleIntoVideo(srcFile, subtitlePath, addSubtitlePath) } + R.id.btn_rotate// set the rotate degree of video + -> { + val rotateDegree = 90 + val addSubtitlePath = PATH + File.separator + "rotate" + rotateDegree + suffix + commandLine = FFmpegUtil.rotateVideo(srcFile, rotateDegree, addSubtitlePath) + } else -> { } } 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 cdb9342..0b54844 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -693,4 +693,10 @@ public class FFmpegUtil { return pushStreams.split(" "); } + public static String[] rotateVideo(String inputPath, int rotateDegree, String outputPath) { + String rotateCmd = "ffmpeg -i %s -c copy -metadata:s:v:0 rotate=%d %s"; + rotateCmd = String.format(Locale.getDefault(), rotateCmd, inputPath, rotateDegree, outputPath); + return rotateCmd.split(" "); + } + } diff --git a/app/src/main/res/layout/activity_video_handle.xml b/app/src/main/res/layout/activity_video_handle.xml index f2959d0..f1ecc29 100644 --- a/app/src/main/res/layout/activity_video_handle.xml +++ b/app/src/main/res/layout/activity_video_handle.xml @@ -149,6 +149,13 @@ android:layout_marginTop="4dp" android:text="@string/video_thumbnail"/> +