From 85d17ee351df7c80bfd67f5546c29bd392980fb4 Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Sat, 12 Jun 2021 17:56:38 +0800 Subject: [PATCH] add super equalizer of audio effect --- .../ffmpeg/activity/AudioHandleActivity.kt | 14 ++++++++++ .../com/frank/ffmpeg/util/FFmpegUtil.java | 26 +++++++++++++++++++ .../main/res/layout/activity_audio_handle.xml | 9 ++++++- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) 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 b3a7aa2..696aa0c 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt @@ -119,6 +119,7 @@ class AudioHandleActivity : BaseActivity() { R.id.btn_audio_echo, R.id.btn_audio_tremolo, R.id.btn_audio_denoise, + R.id.btn_audio_equalizer, R.id.btn_audio_silence, R.id.btn_audio_volume ) @@ -256,6 +257,19 @@ class AudioHandleActivity : BaseActivity() { val noisePath = PATH + File.separator + "denoise.mp3" commandLine = FFmpegUtil.audioDenoise(srcFile, noisePath) } + R.id.btn_audio_equalizer // equalizer plus + -> { + // key:band value:gain=[0-20] + val bandList = arrayListOf() + bandList.add("6b=5") + bandList.add("8b=4") + bandList.add("10b=3") + bandList.add("12b=2") + bandList.add("14b=1") + bandList.add("16b=0") + val equalizePath = PATH + File.separator + "equalize.mp3" + commandLine = FFmpegUtil.audioEqualizer(srcFile, bandList, equalizePath) + } R.id.btn_audio_silence //silence detect -> { commandLine = FFmpegUtil.audioSilenceDetect(srcFile) 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 886144d..45a147b 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -160,6 +160,32 @@ public class FFmpegUtil { return volumeCmd.split(" "); } + /** + * Apply 18 band of equalizer into audio + * + * @param inputPath input file + * @param bandList bandList + * @param outputPath output file + */ + public static String[] audioEqualizer(String inputPath, List bandList, String outputPath) { + // unit: Hz gain:0-20 + /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | 1b | 2b | 3b | 4b | 5b | 6b | 7b | 8b | 9b | + | 65 | 92 | 131 | 185 | 262 | 370 | 523 | 740 | 1047 | + |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | 10b | 11b | 12b | 13b | 14b | 15b | 16b | 17b | 18b | + | 1480 | 2093 | 2960 | 4186 | 5920 | 8372 | 11840 | 16744 | 20000 | + |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ + StringBuilder builder = new StringBuilder(); + for (String band:bandList) { + builder.append(band).append(":"); + } + builder.deleteCharAt(builder.length()-1); + String equalizerCmd = "ffmpeg -i %s -af superequalizer=%s -y %s"; + equalizerCmd = String.format(Locale.getDefault(), equalizerCmd, inputPath, builder.toString(), outputPath); + return equalizerCmd.split(" "); + } + /** * mux audio and video together * diff --git a/app/src/main/res/layout/activity_audio_handle.xml b/app/src/main/res/layout/activity_audio_handle.xml index 3b4b0d9..a53bc48 100644 --- a/app/src/main/res/layout/activity_audio_handle.xml +++ b/app/src/main/res/layout/activity_audio_handle.xml @@ -16,7 +16,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/audio_transform" - android:layout_marginTop="40dp" /> + android:layout_marginTop="10dp" />