From e77e4202e38c3768553933b624fe0c7f60742cbc Mon Sep 17 00:00:00 2001 From: Qiming Date: Thu, 3 Nov 2022 11:38:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=94=BB=E4=B8=AD=E7=94=BB=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=9A=E8=AE=A9=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E6=96=87=E4=BB=B6=EF=BC=9B=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=9D=A5=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E7=94=BB=E4=B8=AD=E7=94=BB=E7=9A=84=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ffmpeg/activity/VideoHandleActivity.kt | 31 +++++++++++++------ .../com/frank/ffmpeg/util/FFmpegUtil.java | 26 ++++++++++++++++ 2 files changed, 47 insertions(+), 10 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 75131ba..30e8233 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt @@ -53,6 +53,9 @@ class VideoHandleActivity : BaseActivity() { private var list :List ?= null private var isJointing = false + private var firstSrcFile: String = "" + private var selectingSecondFile = false + @SuppressLint("HandlerLeak") private val mHandler = object : Handler() { override fun handleMessage(msg: Message) { @@ -295,17 +298,25 @@ class VideoHandleActivity : BaseActivity() { commandLine = FFmpegUtil.videoToImage(srcFile, mStartTime, mDuration, mFrameRate, outputPath) } 12 -> { //combine into picture-in-picture video - val inputFile1 = PATH + File.separator + "beyond.mp4" - val inputFile2 = PATH + File.separator + "small_girl.mp4" - if (!FileUtil.checkFileExist(inputFile1) && !FileUtil.checkFileExist(inputFile2)) { - return + // NOTE: The first video should be bigger than the second one. + if (selectingSecondFile) { // User has selected 2 files + selectingSecondFile = false + if (!FileUtil.checkFileExist(firstSrcFile) && !FileUtil.checkFileExist(srcFile)) { + showToast("请选择两个源文件") + return + } + //x and y coordinate points need to be calculated according to the size of full video and small video + //For example: full video is 320x240, small video is 120x90, so x=200 y=150 + //val x = 200 + //val y = 150 + outputPath = PATH + File.separator + "PicInPic.mp4" + commandLine = FFmpegUtil.picInPicVideoInCorner(firstSrcFile, srcFile, 2, outputPath) + } else { + firstSrcFile = srcFile + selectingSecondFile = true + showToast("画中画:请再选择一个文件") + selectFile() // pop up to select another source file } - //x and y coordinate points need to be calculated according to the size of full video and small video - //For example: full video is 320x240, small video is 120x90, so x=200 y=150 - val x = 200 - val y = 150 - outputPath = PATH + File.separator + "PicInPic.mp4" - commandLine = FFmpegUtil.picInPicVideo(inputFile1, inputFile2, x, y, outputPath) } 13 -> { //playing speed of video outputPath = PATH + File.separator + "speed.mp4" 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 9406f1f..7262420 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -638,6 +638,32 @@ public class FFmpegUtil { return insert(pipVideo.split(" "), 2, inputPath1, 4, inputPath2, outputPath); } + /** + * convert videos into picture-in-picture mode + * + * @param whichCorner 0: top-left; 1: top-right; 2: bottom-left; 3: bottom-right + * @return convert success or not + */ + public static String[] picInPicVideoInCorner(String inputPath1, String inputPath2, int whichCorner, String outputPath) { + String pipCmd = "ffmpeg -i -i -filter_complex "; + switch (whichCorner) { + case 1: + pipCmd += "overlay=W-w"; + break; + case 2: + pipCmd += "overlay=0:H-h"; + break; + case 3: + pipCmd += "overlay=W-w:H-h"; + break; + case 0: + default: + pipCmd += "overlay"; + break; + } + return insert(pipCmd.split(" "), 2, inputPath1, 4, inputPath2, outputPath); + } + /** * move moov box in the front of mdat box, when moox box is behind mdat box(only mp4) * From dd45dd5aa271ed62810c46f088fc1abc693b331c Mon Sep 17 00:00:00 2001 From: Qiming Date: Thu, 3 Nov 2022 12:45:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=9F=B3=E9=A2=91=E5=A4=84=E7=90=86|?= =?UTF-8?q?=E6=B3=A2=E5=BD=A2=E5=9B=BE=EF=BC=9A=E6=94=AF=E6=8C=81=E5=90=84?= =?UTF-8?q?=E5=A3=B0=E9=81=93=E5=88=86=E5=BC=80=E7=94=BB=E6=B3=A2=E5=BD=A2?= =?UTF-8?q?=EF=BC=9B=E8=A7=A3=E5=86=B3=E4=B8=80=E4=B8=AA=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AndroidMedia/build.gradle | 2 +- app/build.gradle | 2 +- .../java/com/frank/ffmpeg/activity/AudioHandleActivity.kt | 2 +- app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AndroidMedia/build.gradle b/AndroidMedia/build.gradle index 181e8fa..81872ac 100644 --- a/AndroidMedia/build.gradle +++ b/AndroidMedia/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'com.android.library' //apply plugin: 'com.android.application' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion rootProject.ext.compileSdkVersion diff --git a/app/build.gradle b/app/build.gradle index 8d259e3..a880e40 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.application' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion rootProject.ext.compileSdkVersion diff --git a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt index 36e3688..1a82b79 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt @@ -261,7 +261,7 @@ class AudioHandleActivity : BaseActivity() { 12 -> { // audio waveform outputPath = PATH + File.separator + "waveform.png" val resolution = "1280x720" - commandLine = FFmpegUtil.showAudioWaveform(srcFile, resolution, outputPath) + commandLine = FFmpegUtil.showAudioWaveform(srcFile, resolution, 1, outputPath) } 13 -> { //audio encode val pcmFile = PATH + File.separator + "raw.pcm" 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 7262420..f592cc7 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -870,9 +870,9 @@ public class FFmpegUtil { return insert(trimCmd.split(" "), 2, inputPath, outputPath); } - public static String[] showAudioWaveform(String inputPath, String resolution, String outputPath) { - String waveformCmd = "ffmpeg -i -filter_complex showwavespic=s=%s"; - waveformCmd = String.format(Locale.getDefault(), waveformCmd, resolution); + public static String[] showAudioWaveform(String inputPath, String resolution, int splitChannels, String outputPath) { + String waveformCmd = "ffmpeg -i -filter_complex showwavespic=s=%s:split_channels=%d"; + waveformCmd = String.format(Locale.getDefault(), waveformCmd, resolution, splitChannels); return insert(waveformCmd.split(" "), 2, inputPath, outputPath); }