add the echo effect

pull/190/head
xufuji456 4 years ago
parent ace1031095
commit ccc10ed69f
  1. 9
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt
  2. 18
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 10
      app/src/main/res/layout/activity_audio_handle.xml
  4. 1
      app/src/main/res/values-en/strings.xml
  5. 1
      app/src/main/res/values/strings.xml

@ -102,7 +102,8 @@ class AudioHandleActivity : BaseActivity() {
R.id.btn_play_opensl,
R.id.btn_audio_encode,
R.id.btn_pcm_concat,
R.id.btn_audio_speed
R.id.btn_audio_speed,
R.id.btn_audio_echo
)
}
@ -220,6 +221,12 @@ class AudioHandleActivity : BaseActivity() {
val speedPath = PATH + File.separator + "speed.mp3"
commandLine = FFmpegUtil.changeAudioSpeed(srcFile, speedPath, speed)
}
R.id.btn_audio_echo//setting echo effect
-> {
val echo = 1000 // echo effect, range from 0 to 90000
val echoPath = PATH + File.separator + "echo.mp3"
commandLine = FFmpegUtil.audioEcho(srcFile, echo, echoPath)
}
else -> {
}
}

@ -85,6 +85,24 @@ public class FFmpegUtil {
}
//mixing formula: value = sample1 + sample2 - (sample1 * sample2 / (pow(2, 16-1) - 1))
/**
* Set echo and delay effect
*
* @param inputPath input file
* @param delay delay to play
* @param outputPath output file
* @return mix success or not
*/
public static String[] audioEcho(String inputPath, int delay, String outputPath) {
// in_gain (0, 1], Default is 0.6
// out_gain (0, 1], Default is 0.3
// delays (0 - 90000]. Default is 1000
// decays (0 - 1.0]. Default is 0.5
String echoCmd = "ffmpeg -i %s -af aecho=0.8:0.8:%d:0.5 %s";
echoCmd = String.format(Locale.getDefault(), echoCmd, inputPath, delay, outputPath);
return echoCmd.split(" ");
}
/**
* mux audio and video together
*

@ -65,7 +65,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pcm_concat"
android:layout_marginTop="10dp" />
android:layout_marginTop="10dp"
android:visibility="gone"/>
<Button
android:id="@+id/btn_audio_speed"
@ -74,6 +75,13 @@
android:text="@string/audio_speed"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_audio_echo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_echo"
android:layout_marginTop="10dp" />
</LinearLayout>
<include

@ -9,6 +9,7 @@
<string name="audio_encode">PCM encode</string>
<string name="pcm_concat">PCM concat</string>
<string name="audio_speed">Audio speed</string>
<string name="audio_echo">Echo effect</string>
<string name="audio_effect">Audio effect</string>
<string name="audio_equalizer">Audio equalizer:</string>
<string name="audio_style">Audio style:</string>

@ -9,6 +9,7 @@
<string name="audio_encode">PCM编码</string>
<string name="pcm_concat">PCM合并</string>
<string name="audio_speed">音频速度</string>
<string name="audio_echo">空灵效果</string>
<string name="audio_effect">音乐均衡器</string>
<string name="audio_equalizer">均衡器:</string>
<string name="audio_style">风格:</string>

Loading…
Cancel
Save