From 639245060c021858c7f2bc9510d2dcdb68bf7b2b Mon Sep 17 00:00:00 2001
From: frank <839789740@qq.com>
Date: Tue, 8 May 2018 00:00:13 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9F=B3=E9=A2=91=E7=BC=96?=
=?UTF-8?q?=E7=A0=81=EF=BC=9Apcm=E7=BC=96=E7=A0=81=E6=88=90wav=E3=80=81aac?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
增加音频编码:pcm编码成wav、aac
---
.../frank/ffmpeg/activity/AudioHandleActivity.java | 12 ++++++++++++
.../main/java/com/frank/ffmpeg/util/FFmpegUtil.java | 13 +++++++++++++
app/src/main/res/layout/activity_audio_handle.xml | 11 ++++++++++-
app/src/main/res/values/strings.xml | 1 +
4 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
index 9732828..64a8832 100644
--- a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
+++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
@@ -67,6 +67,7 @@ public class AudioHandleActivity extends AppCompatActivity implements View.OnCli
findViewById(R.id.btn_mix).setOnClickListener(this);
findViewById(R.id.btn_play_audio).setOnClickListener(this);
findViewById(R.id.btn_play_opensl).setOnClickListener(this);
+ findViewById(R.id.btn_audio_encode).setOnClickListener(this);
}
private void setVisible() {
@@ -76,6 +77,7 @@ public class AudioHandleActivity extends AppCompatActivity implements View.OnCli
findViewById(R.id.btn_mix).setVisibility(View.VISIBLE);
findViewById(R.id.btn_play_audio).setVisibility(View.VISIBLE);
findViewById(R.id.btn_play_opensl).setVisibility(View.VISIBLE);
+ findViewById(R.id.btn_audio_encode).setVisibility(View.VISIBLE);
}
private void setGone() {
@@ -85,6 +87,7 @@ public class AudioHandleActivity extends AppCompatActivity implements View.OnCli
findViewById(R.id.btn_mix).setVisibility(View.GONE);
findViewById(R.id.btn_play_audio).setVisibility(View.GONE);
findViewById(R.id.btn_play_opensl).setVisibility(View.GONE);
+ findViewById(R.id.btn_audio_encode).setVisibility(View.GONE);
}
@Override
@@ -109,6 +112,9 @@ public class AudioHandleActivity extends AppCompatActivity implements View.OnCli
case R.id.btn_play_opensl:
handleType = 5;
break;
+ case R.id.btn_audio_encode:
+ handleType = 6;
+ break;
default:
handleType = 0;
break;
@@ -155,6 +161,12 @@ public class AudioHandleActivity extends AppCompatActivity implements View.OnCli
}
}).start();
return;
+ case 6://音频编码
+ //可编码成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);
+ break;
default:
break;
}
diff --git a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
index b904748..b8c7d05 100644
--- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
+++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
@@ -211,4 +211,17 @@ public class FFmpegUtil {
return combineVideo.split(" ");//以空格分割为字符串数组
}
+ /**
+ * 音频编码
+ * @param srcFile 源文件pcm裸流
+ * @param targetFile 编码后目标文件
+ * @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("#", "%");
+ return combineVideo.split(" ");
+ }
+
}
diff --git a/app/src/main/res/layout/activity_audio_handle.xml b/app/src/main/res/layout/activity_audio_handle.xml
index 26e0845..fb9b8ee 100644
--- a/app/src/main/res/layout/activity_audio_handle.xml
+++ b/app/src/main/res/layout/activity_audio_handle.xml
@@ -11,7 +11,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_transform"
- android:layout_marginTop="120dp"
+ android:layout_marginTop="80dp"
android:layout_centerHorizontal="true"/>
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 685e894..5638271 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -6,6 +6,7 @@
音频混合
音频解码AudioTrack播放
音频解码OpenSL播放
+ 音频编码
音频处理
音视频处理