translate the note of LiveActivity into English

translate the note of LiveActivity into English
pull/166/head
xufulong 5 years ago
parent 143b465f79
commit ef988b0d86
  1. 37
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
  2. 18
      app/src/main/java/com/frank/ffmpeg/activity/LiveActivity.java
  3. 2
      app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.java
  4. 2
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java

@ -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;
} }
@ -200,7 +199,7 @@ public class AudioHandleActivity extends BaseActivity {
default: default:
break; break;
} }
if (ffmpegHandler != null && commandLine != null) { if (ffmpegHandler != null && commandLine != null) {
ffmpegHandler.executeFFmpegCmd(commandLine); ffmpegHandler.executeFFmpegCmd(commandLine);
} }
} }

@ -21,7 +21,7 @@ import com.frank.live.param.VideoParam;
import com.frank.live.LivePusherNew; import com.frank.live.LivePusherNew;
/** /**
* h264与rtmp实时推流直播 * Realtime living with rtmp stream
* Created by frank on 2018/1/28. * Created by frank on 2018/1/28.
*/ */
@ -68,16 +68,16 @@ public class LiveActivity extends BaseActivity implements CompoundButton.OnCheck
} }
private void initPusher() { private void initPusher() {
int width = 640;//分辨率设置 int width = 640;//resolution
int height = 480; int height = 480;
int videoBitRate = 800_000;//kb/s int videoBitRate = 800_000;//kb/s
int videoFrameRate = 10;//fps int videoFrameRate = 10;//fps
VideoParam videoParam = new VideoParam(width, height, VideoParam videoParam = new VideoParam(width, height,
Integer.valueOf(Camera2Helper.CAMERA_ID_BACK), videoBitRate, videoFrameRate); Integer.valueOf(Camera2Helper.CAMERA_ID_BACK), videoBitRate, videoFrameRate);
int sampleRate = 44100;//采样率:Hz int sampleRate = 44100;//sample rate: Hz
int channelConfig = AudioFormat.CHANNEL_IN_STEREO;//立体声道 int channelConfig = AudioFormat.CHANNEL_IN_STEREO;
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;//pcm16位 int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int numChannels = 2;//声道数 int numChannels = 2;//channel number
AudioParam audioParam = new AudioParam(sampleRate, channelConfig, audioFormat, numChannels); AudioParam audioParam = new AudioParam(sampleRate, channelConfig, audioFormat, numChannels);
livePusher = new LivePusherNew(this, videoParam, audioParam); livePusher = new LivePusherNew(this, videoParam, audioParam);
livePusher.setPreviewDisplay(textureView.getHolder()); livePusher.setPreviewDisplay(textureView.getHolder());
@ -86,14 +86,14 @@ public class LiveActivity extends BaseActivity implements CompoundButton.OnCheck
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch (buttonView.getId()) { switch (buttonView.getId()) {
case R.id.btn_live://开始/停止直播 case R.id.btn_live://start or stop living
if (isChecked) { if (isChecked) {
livePusher.startPush(LIVE_URL, this); livePusher.startPush(LIVE_URL, this);
} else { } else {
livePusher.stopPush(); livePusher.stopPush();
} }
break; break;
case R.id.btn_mute://设置静音 case R.id.btn_mute://mute or not
Log.i(TAG, "isChecked=" + isChecked); Log.i(TAG, "isChecked=" + isChecked);
livePusher.setMute(isChecked); livePusher.setMute(isChecked);
break; break;
@ -118,7 +118,7 @@ public class LiveActivity extends BaseActivity implements CompoundButton.OnCheck
@Override @Override
void onViewClick(View view) { void onViewClick(View view) {
if (view.getId() == R.id.btn_swap) {//切换摄像头 if (view.getId() == R.id.btn_swap) {//switch camera
livePusher.switchCamera(); livePusher.switchCamera();
} }
} }

@ -124,7 +124,7 @@ public class MediaHandleActivity extends BaseActivity {
} }
/** /**
* execute ffmpeg cmd to handle media * Using ffmpeg cmd to handle media
* *
* @param srcFile srcFile * @param srcFile srcFile
*/ */

@ -108,7 +108,7 @@ public class VideoHandleActivity extends BaseActivity {
} }
/** /**
* call FFmpeg cmd to process video * Using FFmpeg cmd to handle video
* *
* @param srcFile srcFile * @param srcFile srcFile
*/ */

Loading…
Cancel
Save