modify the volume of audio

pull/190/head
xufuji456 4 years ago
parent e216dd7113
commit 5351985116
  1. 15
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt
  2. 14
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 7
      app/src/main/res/layout/activity_audio_handle.xml
  4. 2
      app/src/main/res/values-en/strings.xml
  5. 2
      app/src/main/res/values/strings.xml

@ -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 -> {
}
}

@ -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
*

@ -106,6 +106,13 @@
android:text="@string/audio_silence"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_audio_volume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_volume"
android:layout_marginTop="10dp" />
</LinearLayout>
<include

@ -13,6 +13,8 @@
<string name="audio_tremolo">Tremolo effect</string>
<string name="audio_denoise">Audio denoise</string>
<string name="audio_silence">Silence detect</string>
<string name="audio_volume">Audio volume</string>
<string name="audio_add_equalizer">Add equalizer</string>
<string name="audio_effect">Audio effect</string>
<string name="audio_equalizer">Audio equalizer:</string>
<string name="audio_style">Audio style:</string>

@ -13,6 +13,8 @@
<string name="audio_tremolo">惊悚效果</string>
<string name="audio_denoise">音频降噪</string>
<string name="audio_silence">静音检测</string>
<string name="audio_volume">修改音量</string>
<string name="audio_add_equalizer">均衡器+</string>
<string name="audio_effect">音乐均衡器</string>
<string name="audio_equalizer">均衡器:</string>
<string name="audio_style">风格:</string>

Loading…
Cancel
Save