change audio speed

pull/166/head
xufulong 4 years ago
parent 06272ed7a5
commit 0d7d2907cf
  1. 8
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
  2. 16
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 8
      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

@ -108,7 +108,8 @@ public class AudioHandleActivity extends BaseActivity {
R.id.btn_play_audio, R.id.btn_play_audio,
R.id.btn_play_opensl, R.id.btn_play_opensl,
R.id.btn_audio_encode, R.id.btn_audio_encode,
R.id.btn_pcm_concat R.id.btn_pcm_concat,
R.id.btn_audio_speed
); );
} }
@ -208,6 +209,11 @@ public class AudioHandleActivity extends BaseActivity {
FileUtil.concatFile(srcPCM, appendPCM, concatPCM); FileUtil.concatFile(srcPCM, appendPCM, concatPCM);
mHandler.obtainMessage(MSG_FINISH).sendToTarget(); mHandler.obtainMessage(MSG_FINISH).sendToTarget();
return; return;
case R.id.btn_audio_speed://change audio speed
float speed = 2.0f;//from 0.5 to 2.0
String speedPath = PATH + File.separator + "speed.mp3";
commandLine = FFmpegUtil.changeAudioSpeed(srcFile, speedPath, speed);
break;
default: default:
break; break;
} }

@ -520,6 +520,22 @@ public class FFmpegUtil {
return speedCmd.split(" "); return speedCmd.split(" ");
} }
/**
* Changing the speed of playing, speed range at 0.5-2 in audio.
* @param inputFile the inputFile of normal speed
* @param outputFile the outputFile which you want to change speed
* @param speed speed of playing
* @return change speed success or not
*/
public static String[] changeAudioSpeed(String inputFile, String outputFile, float speed) {
if (speed > 2 || speed < 0.5) {
throw new IllegalArgumentException("audio speed range is from 0.5 to 2");
}
String speedCmd = "ffmpeg -i %s -filter_complex atempo=%.2f %s";
speedCmd = String.format(Locale.getDefault(), speedCmd, inputFile, speed, outputFile);
return speedCmd.split(" ");
}
/** /**
* Rebuild the keyframe index of FLV, make it seekable * Rebuild the keyframe index of FLV, make it seekable
* @param inputFile inputFile * @param inputFile inputFile

@ -66,6 +66,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/pcm_concat" android:text="@string/pcm_concat"
android:layout_marginTop="10dp" /> android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_audio_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_speed"
android:layout_marginTop="10dp" />
</LinearLayout> </LinearLayout>
<include <include

@ -8,6 +8,7 @@
<string name="audio_opensl">OpenSL play</string> <string name="audio_opensl">OpenSL play</string>
<string name="audio_encode">Audio encode</string> <string name="audio_encode">Audio encode</string>
<string name="pcm_concat">PCM concat</string> <string name="pcm_concat">PCM concat</string>
<string name="audio_speed">Audio speed</string>
<string name="audio_handle">Audio handle</string> <string name="audio_handle">Audio handle</string>
<string name="media_handle">Media handle</string> <string name="media_handle">Media handle</string>

@ -8,6 +8,7 @@
<string name="audio_opensl">音频解码OpenSL播放</string> <string name="audio_opensl">音频解码OpenSL播放</string>
<string name="audio_encode">音频编码</string> <string name="audio_encode">音频编码</string>
<string name="pcm_concat">PCM合并</string> <string name="pcm_concat">PCM合并</string>
<string name="audio_speed">音频速度</string>
<string name="audio_handle">音频处理</string> <string name="audio_handle">音频处理</string>
<string name="media_handle">音视频处理</string> <string name="media_handle">音视频处理</string>

Loading…
Cancel
Save