音频编码方法改为采样率、声道传参形式

pull/107/head
frank 7 years ago
parent 31afb9b67f
commit 5fe02096fa
  1. 6
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
  2. 9
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java

@ -165,7 +165,11 @@ public class AudioHandleActivity extends AppCompatActivity implements View.OnCli
//可编码成WAV、AAC。如果需要编码成MP3、AMR,ffmpeg需要重新编译,把MP3、AMR库enable
String pcmFile = PATH + File.separator + "audio.pcm";
String wavFile = PATH + File.separator + "output.wav";
commandLine = FFmpegUtil.encodeAudio(pcmFile, wavFile);
//pcm数据的采样率,一般采样率为8000、16000、44100
int sampleRate = 8000;
//pcm数据的声道,单声道为1,立体声道为2
int channel = 1;
commandLine = FFmpegUtil.encodeAudio(pcmFile, wavFile, sampleRate, channel);
break;
default:
break;

@ -215,12 +215,13 @@ public class FFmpegUtil {
* 音频编码
* @param srcFile 源文件pcm裸流
* @param targetFile 编码后目标文件
* @param sampleRate 采样率
* @param channel 声道:单声道为1/立体声道为2
* @return 音频编码的命令行
*/
public static String[] encodeAudio(String srcFile, String targetFile){
String combineVideo = "ffmpeg -f s16le -ar 8000 -ac 1 -i %s %s";
combineVideo = String.format(combineVideo, srcFile, targetFile);
combineVideo = combineVideo.replace("#", "%");
public static String[] encodeAudio(String srcFile, String targetFile, int sampleRate, int channel){
String combineVideo = "ffmpeg -f s16le -ar %d -ac %d -i %s %s";
combineVideo = String.format(combineVideo, sampleRate, channel, srcFile, targetFile);
return combineVideo.split(" ");
}

Loading…
Cancel
Save