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 0f7eee5..b3a7aa2 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt @@ -78,7 +78,7 @@ class AudioHandleActivity : BaseActivity() { txtProgress!!.visibility = View.VISIBLE txtProgress!!.text = String.format(Locale.getDefault(), "%d%%", progress) } else { - txtProgress!!.visibility = View.INVISIBLE + txtProgress!!.visibility = View.GONE } } MSG_INFO -> { @@ -119,7 +119,8 @@ class AudioHandleActivity : BaseActivity() { R.id.btn_audio_echo, R.id.btn_audio_tremolo, R.id.btn_audio_denoise, - R.id.btn_audio_silence + R.id.btn_audio_silence, + R.id.btn_audio_volume ) } @@ -250,15 +251,21 @@ class AudioHandleActivity : BaseActivity() { val tremoloPath = PATH + File.separator + "tremolo.mp3" commandLine = FFmpegUtil.audioTremolo(srcFile, frequency, depth, tremoloPath) } - R.id.btn_audio_denoise + R.id.btn_audio_denoise //audio denoise -> { val noisePath = PATH + File.separator + "denoise.mp3" commandLine = FFmpegUtil.audioDenoise(srcFile, noisePath) } - R.id.btn_audio_silence + R.id.btn_audio_silence //silence detect -> { commandLine = FFmpegUtil.audioSilenceDetect(srcFile) } + R.id.btn_audio_volume // modify volume + -> { + val volume = 0.5f // 0.0-1.0 + val volumePath = PATH + File.separator + "volume.mp3" + commandLine = FFmpegUtil.audioVolume(srcFile, volume, volumePath) + } 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 217c2de..886144d 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -146,6 +146,20 @@ public class FFmpegUtil { return silenceCmd.split(" "); } + /** + * Change volume of a chunk of audio + * + * @param inputPath input file + * @param volume volume + * @param outputPath output file + */ + public static String[] audioVolume(String inputPath, float volume, String outputPath) { + // output_volume = volume * input_volume + String volumeCmd = "ffmpeg -i %s -af volume=%f %s"; + volumeCmd = String.format(Locale.getDefault(), volumeCmd, inputPath, volume, outputPath); + return volumeCmd.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 a4abca0..3b4b0d9 100644 --- a/app/src/main/res/layout/activity_audio_handle.xml +++ b/app/src/main/res/layout/activity_audio_handle.xml @@ -106,6 +106,13 @@ android:text="@string/audio_silence" android:layout_marginTop="10dp" /> +