修复部分音频剪切失败问题

修复部分音频剪切失败问题
pull/107/head
xufulong 5 years ago
parent 9690ec36df
commit 196dfa12d5
  1. 4
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
  2. 2
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java

@ -118,8 +118,8 @@ public class AudioHandleActivity extends BaseActivity {
Mp3Converter mp3Converter = new Mp3Converter(); Mp3Converter mp3Converter = new Mp3Converter();
mp3Converter.convertToMp3(inputFile, transformFile); mp3Converter.convertToMp3(inputFile, transformFile);
break; break;
case R.id.btn_cut://剪切(注意原文件与剪切文件格式一致) case R.id.btn_cut://剪切(注意原文件与剪切文件格式一致,文件绝对路径最好不包含中文、特殊字符)
String cutFile = PATH + File.separator + "cut.aac"; String cutFile = PATH + File.separator + "cut.mp3";
commandLine = FFmpegUtil.cutAudio(srcFile, 10, 15, cutFile); commandLine = FFmpegUtil.cutAudio(srcFile, 10, 15, cutFile);
break; break;
case R.id.btn_concat://合并,支持MP3、AAC、AMR等,不支持PCM裸流,不支持WAV(PCM裸流加音频头) case R.id.btn_concat://合并,支持MP3、AAC、AMR等,不支持PCM裸流,不支持WAV(PCM裸流加音频头)

@ -36,7 +36,7 @@ public class FFmpegUtil {
*/ */
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
public static String[] cutAudio(String srcFile, int startTime, int duration, String targetFile){ public static String[] cutAudio(String srcFile, int startTime, int duration, String targetFile){
String cutAudioCmd = "ffmpeg -i %s -ss %d -t %d %s"; String cutAudioCmd = "ffmpeg -i %s -acodec copy -ss %d -t %d %s";
cutAudioCmd = String.format(cutAudioCmd, srcFile, startTime, duration, targetFile); cutAudioCmd = String.format(cutAudioCmd, srcFile, startTime, duration, targetFile);
return cutAudioCmd.split(" ");//以空格分割为字符串数组 return cutAudioCmd.split(" ");//以空格分割为字符串数组
} }

Loading…
Cancel
Save