|  |  | @ -24,7 +24,7 @@ import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_BEGIN; | 
			
		
	
		
		
			
				
					
					|  |  |  | import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH; |  |  |  | import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | /** |  |  |  | /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  * 使用ffmpeg处理音频 |  |  |  |  * Using ffmpeg command to handle audio | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  * Created by frank on 2018/1/23. |  |  |  |  * Created by frank on 2018/1/23. | 
			
		
	
		
		
			
				
					
					|  |  |  |  */ |  |  |  |  */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -101,7 +101,7 @@ public class AudioHandleActivity extends BaseActivity { | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     /** |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |      * 调用ffmpeg处理音频 |  |  |  |      * Using ffmpeg cmd to handle audio | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |      * |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |      * @param srcFile srcFile |  |  |  |      * @param srcFile srcFile | 
			
		
	
		
		
			
				
					
					|  |  |  |      */ |  |  |  |      */ | 
			
		
	
	
		
		
			
				
					|  |  | @ -115,11 +115,11 @@ public class AudioHandleActivity extends BaseActivity { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return; |  |  |  |             return; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         switch (viewId) { |  |  |  |         switch (viewId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             case R.id.btn_transform://转码
 |  |  |  |             case R.id.btn_transform: | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 if (useFFmpeg) { //使用FFmpeg转码
 |  |  |  |                 if (useFFmpeg) { //use FFmpeg to transform
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     String transformFile = PATH + File.separator + "transformAudio.mp3"; |  |  |  |                     String transformFile = PATH + File.separator + "transformAudio.mp3"; | 
			
		
	
		
		
			
				
					
					|  |  |  |                     commandLine = FFmpegUtil.transformAudio(srcFile, transformFile); |  |  |  |                     commandLine = FFmpegUtil.transformAudio(srcFile, transformFile); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else { //使用MediaCodec与mp3lame转mp3
 |  |  |  |                 } else { //use MediaCodec and libmp3lame to transform
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     new Thread(new Runnable() { |  |  |  |                     new Thread(new Runnable() { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         @Override |  |  |  |                         @Override | 
			
		
	
		
		
			
				
					
					|  |  |  |                         public void run() { |  |  |  |                         public void run() { | 
			
		
	
	
		
		
			
				
					|  |  | @ -130,7 +130,7 @@ public class AudioHandleActivity extends BaseActivity { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     }).start(); |  |  |  |                     }).start(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 break; |  |  |  |                 break; | 
			
		
	
		
		
			
				
					
					|  |  |  |             case R.id.btn_cut://剪切(注意原文件与剪切文件格式一致,文件绝对路径最好不包含中文、特殊字符)
 |  |  |  |             case R.id.btn_cut://cut audio, it's best not include special characters
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 String suffix = FileUtil.getFileSuffix(srcFile); |  |  |  |                 String suffix = FileUtil.getFileSuffix(srcFile); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (suffix == null || suffix.isEmpty()) { |  |  |  |                 if (suffix == null || suffix.isEmpty()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return; |  |  |  |                     return; | 
			
		
	
	
		
		
			
				
					|  |  | @ -138,7 +138,7 @@ public class AudioHandleActivity extends BaseActivity { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String cutFile = PATH + File.separator + "cutAudio" + suffix; |  |  |  |                 String cutFile = PATH + File.separator + "cutAudio" + suffix; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 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://concat audio
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (!FileUtil.checkFileExist(appendFile)) { |  |  |  |                 if (!FileUtil.checkFileExist(appendFile)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return; |  |  |  |                     return; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
	
		
		
			
				
					|  |  | @ -148,7 +148,7 @@ public class AudioHandleActivity extends BaseActivity { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String concatFile = PATH + File.separator + "concat.mp3"; |  |  |  |                 String concatFile = PATH + File.separator + "concat.mp3"; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 commandLine = FFmpegUtil.concatAudio(fileList, concatFile); |  |  |  |                 commandLine = FFmpegUtil.concatAudio(fileList, concatFile); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 break; |  |  |  |                 break; | 
			
		
	
		
		
			
				
					
					|  |  |  |             case R.id.btn_mix://混音
 |  |  |  |             case R.id.btn_mix://mix audio
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (!FileUtil.checkFileExist(appendFile)) { |  |  |  |                 if (!FileUtil.checkFileExist(appendFile)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return; |  |  |  |                     return; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
	
		
		
			
				
					|  |  | @ -159,7 +159,7 @@ public class AudioHandleActivity extends BaseActivity { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String mixFile = PATH + File.separator + "mix" + mixSuffix; |  |  |  |                 String mixFile = PATH + File.separator + "mix" + mixSuffix; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 commandLine = FFmpegUtil.mixAudio(srcFile, appendFile, mixFile); |  |  |  |                 commandLine = FFmpegUtil.mixAudio(srcFile, appendFile, mixFile); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 break; |  |  |  |                 break; | 
			
		
	
		
		
			
				
					
					|  |  |  |             case R.id.btn_play_audio://解码播放(AudioTrack)
 |  |  |  |             case R.id.btn_play_audio://use AudioTrack to play audio
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 new Thread(new Runnable() { |  |  |  |                 new Thread(new Runnable() { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     @Override |  |  |  |                     @Override | 
			
		
	
		
		
			
				
					
					|  |  |  |                     public void run() { |  |  |  |                     public void run() { | 
			
		
	
	
		
		
			
				
					|  |  | @ -167,7 +167,7 @@ public class AudioHandleActivity extends BaseActivity { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 }).start(); |  |  |  |                 }).start(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return; |  |  |  |                 return; | 
			
		
	
		
		
			
				
					
					|  |  |  |             case R.id.btn_play_opensl://解码播放(OpenSL ES)
 |  |  |  |             case R.id.btn_play_opensl://use OpenSL ES to play audio
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 new Thread(new Runnable() { |  |  |  |                 new Thread(new Runnable() { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     @Override |  |  |  |                     @Override | 
			
		
	
		
		
			
				
					
					|  |  |  |                     public void run() { |  |  |  |                     public void run() { | 
			
		
	
	
		
		
			
				
					|  |  | @ -175,20 +175,19 @@ public class AudioHandleActivity extends BaseActivity { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 }).start(); |  |  |  |                 }).start(); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return; |  |  |  |                 return; | 
			
		
	
		
		
			
				
					
					|  |  |  |             case R.id.btn_audio_encode://音频编码
 |  |  |  |             case R.id.btn_audio_encode://audio encode
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 //可编码成WAV、AAC。如果需要编码成MP3,ffmpeg需要重新编译,把MP3库enable
 |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 String pcmFile = PATH + File.separator + "concat.pcm"; |  |  |  |                 String pcmFile = PATH + File.separator + "concat.pcm"; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String wavFile = PATH + File.separator + "new.wav"; |  |  |  |                 String wavFile = PATH + File.separator + "new.wav"; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //pcm数据的采样率,一般采样率为8000、16000、44100
 |  |  |  |                 //sample rate, normal is 8000/16000/44100
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 int sampleRate = 8000; |  |  |  |                 int sampleRate = 8000; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 //pcm数据的声道,单声道为1,立体声道为2
 |  |  |  |                 //channel num of pcm
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 int channel = 1; |  |  |  |                 int channel = 1; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 commandLine = FFmpegUtil.encodeAudio(pcmFile, wavFile, sampleRate, channel); |  |  |  |                 commandLine = FFmpegUtil.encodeAudio(pcmFile, wavFile, sampleRate, channel); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 break; |  |  |  |                 break; | 
			
		
	
		
		
			
				
					
					|  |  |  |             case R.id.btn_pcm_concat://PCM裸流音频文件合并
 |  |  |  |             case R.id.btn_pcm_concat://concat PCM streams
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 String srcPCM = PATH + File.separator + "audio.pcm";//第一个pcm文件
 |  |  |  |                 String srcPCM = PATH + File.separator + "audio.pcm"; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 String appendPCM = PATH + File.separator + "audio.pcm";//第二个pcm文件
 |  |  |  |                 String appendPCM = PATH + File.separator + "audio.pcm"; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 String concatPCM = PATH + File.separator + "concat.pcm";//合并后的文件
 |  |  |  |                 String concatPCM = PATH + File.separator + "concat.pcm"; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (!FileUtil.checkFileExist(srcPCM) || !FileUtil.checkFileExist(appendPCM)) { |  |  |  |                 if (!FileUtil.checkFileExist(srcPCM) || !FileUtil.checkFileExist(appendPCM)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return; |  |  |  |                     return; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |