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. 24
      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,6 +36,8 @@ 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
@ -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);
@ -137,7 +143,11 @@ public class AudioHandleActivity extends BaseActivity {
if (!FileUtil.checkFileExist(appendFile)) { if (!FileUtil.checkFileExist(appendFile)) {
return; return;
} }
String mixFile = PATH + File.separator + "mix.aac"; String mixSuffix = FileUtil.getFileSuffix(srcFile);
if (mixSuffix == null || mixSuffix.isEmpty()) {
return;
}
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)

Loading…
Cancel
Save