FFmpeg增加libmp3lame库,支持mp3编码

FFmpeg增加libmp3lame库,支持mp3编码
pull/107/head
xufulong 5 years ago
parent 0726a7f022
commit d3c98a22d0
  1. 5
      app/CMakeLists.txt
  2. BIN
      app/libs/armeabi-v7a/libffmpeg.so
  3. 32
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java

@ -38,20 +38,19 @@ add_library( ffmpeg
IMPORTED ) IMPORTED )
set_target_properties( ffmpeg set_target_properties( ffmpeg
PROPERTIES IMPORTED_LOCATION PROPERTIES IMPORTED_LOCATION
../../../../libs/armeabi-v7a/libffmpeg.so ) ../../../../libs/${CMAKE_ANDROID_ARCH_ABI}/libffmpeg.so )
add_library( mp3lame add_library( mp3lame
SHARED SHARED
IMPORTED ) IMPORTED )
set_target_properties( mp3lame set_target_properties( mp3lame
PROPERTIES IMPORTED_LOCATION PROPERTIES IMPORTED_LOCATION
../../../../libs/armeabi-v7a/libmp3lame.so ) ../../../../libs/${CMAKE_ANDROID_ARCH_ABI}/libmp3lame.so )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(src/main/cpp) include_directories(src/main/cpp)
include_directories(src/main/cpp/include) include_directories(src/main/cpp/include)
include_directories(src/main/cpp/include/armeabi-v7a)
find_library( # Sets the name of the path variable. find_library( # Sets the name of the path variable.
log-lib log-lib

Binary file not shown.

@ -8,6 +8,7 @@ import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import java.io.File; import java.io.File;
import com.frank.ffmpeg.AudioPlayer; import com.frank.ffmpeg.AudioPlayer;
@ -35,8 +36,10 @@ public class AudioHandleActivity extends BaseActivity {
private int viewId; private int viewId;
private FFmpegHandler ffmpegHandler; private FFmpegHandler ffmpegHandler;
private final static boolean useFFmpeg = true;
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
private Handler mHandler = new Handler(){ private Handler mHandler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
@ -97,6 +100,7 @@ public class AudioHandleActivity extends BaseActivity {
/** /**
* 调用ffmpeg处理音频 * 调用ffmpeg处理音频
*
* @param srcFile srcFile * @param srcFile srcFile
*/ */
private void doHandleAudio(final String srcFile) { private void doHandleAudio(final String srcFile) {
@ -110,13 +114,15 @@ public class AudioHandleActivity extends BaseActivity {
} }
switch (viewId) { switch (viewId) {
case R.id.btn_transform://转码 case R.id.btn_transform://转码
// String transformFile = PATH + File.separator + "transform.aac"; String transformFile;
// commandLine = FFmpegUtil.transformAudio(srcFile, transformFile); if (useFFmpeg) { //使用FFmpeg转码
//使用mp3lame进行转码 transformFile = PATH + File.separator + "transformAudio.mp3";
String inputFile = PATH + File.separator + "hello.aac"; commandLine = FFmpegUtil.transformAudio(srcFile, transformFile);
String transformFile = PATH + File.separator + "transform.mp3"; } else { //使用MediaCodec与mp3lame转mp3
transformFile = PATH + File.separator + "transformAudio.mp3";
Mp3Converter mp3Converter = new Mp3Converter(); Mp3Converter mp3Converter = new Mp3Converter();
mp3Converter.convertToMp3(inputFile, transformFile); mp3Converter.convertToMp3(srcFile, transformFile);
}
break; break;
case R.id.btn_cut://剪切(注意原文件与剪切文件格式一致,文件绝对路径最好不包含中文、特殊字符) case R.id.btn_cut://剪切(注意原文件与剪切文件格式一致,文件绝对路径最好不包含中文、特殊字符)
String suffix = FileUtil.getFileSuffix(srcFile); String suffix = FileUtil.getFileSuffix(srcFile);
@ -127,17 +133,21 @@ public class AudioHandleActivity extends BaseActivity {
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裸流加音频头)
if (!FileUtil.checkFileExist(appendFile)){ if (!FileUtil.checkFileExist(appendFile)) {
return; return;
} }
String concatFile = PATH + File.separator + "concat.mp3"; String concatFile = PATH + File.separator + "concat.mp3";
commandLine = FFmpegUtil.concatAudio(srcFile, appendFile, concatFile); commandLine = FFmpegUtil.concatAudio(srcFile, appendFile, concatFile);
break; break;
case R.id.btn_mix://混音 case R.id.btn_mix://混音
if (!FileUtil.checkFileExist(appendFile)){ if (!FileUtil.checkFileExist(appendFile)) {
return;
}
String mixSuffix = FileUtil.getFileSuffix(srcFile);
if (mixSuffix == null || mixSuffix.isEmpty()) {
return; return;
} }
String mixFile = PATH + File.separator + "mix.aac"; 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://解码播放(AudioTrack)
@ -170,7 +180,7 @@ public class AudioHandleActivity extends BaseActivity {
String srcPCM = PATH + File.separator + "audio.pcm";//第一个pcm文件 String srcPCM = PATH + File.separator + "audio.pcm";//第一个pcm文件
String appendPCM = PATH + File.separator + "audio.pcm";//第二个pcm文件 String appendPCM = PATH + File.separator + "audio.pcm";//第二个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;
} }

Loading…
Cancel
Save