增加音频编码:pcm编码成wav、aac

增加音频编码:pcm编码成wav、aac
pull/107/head
frank 7 years ago
parent 807efba375
commit 639245060c
  1. 12
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
  2. 13
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java
  3. 11
      app/src/main/res/layout/activity_audio_handle.xml
  4. 1
      app/src/main/res/values/strings.xml

@ -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;
}

@ -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(" ");
}
}

@ -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"/>
<Button
@ -66,4 +66,13 @@
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/btn_audio_encode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_encode"
android:layout_below="@+id/btn_play_opensl"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>

@ -6,6 +6,7 @@
<string name="audio_mix">音频混合</string>
<string name="audio_play">音频解码AudioTrack播放</string>
<string name="audio_opensl">音频解码OpenSL播放</string>
<string name="audio_encode">音频编码</string>
<string name="audio_handle">音频处理</string>
<string name="media_handle">音视频处理</string>

Loading…
Cancel
Save