translate the note of MainActivity into English

translate the note of MainActivity into English
pull/166/head
xufulong 5 years ago
parent 17cab296b8
commit 143b465f79
  1. 20
      app/src/main/java/com/frank/ffmpeg/activity/MainActivity.java
  2. 21
      app/src/main/java/com/frank/ffmpeg/activity/MediaHandleActivity.java

@ -7,7 +7,7 @@ import android.view.View;
import com.frank.ffmpeg.R;
/**
* 使用ffmpeg进行音视频处理入口
* The main entrance of all Activity
* Created by frank on 2018/1/23.
*/
public class MainActivity extends BaseActivity {
@ -38,31 +38,31 @@ public class MainActivity extends BaseActivity {
public void onViewClick(View v) {
Intent intent = new Intent();
switch (v.getId()) {
case R.id.btn_audio://音频处理
case R.id.btn_audio://handle audio
intent.setClass(MainActivity.this, AudioHandleActivity.class);
break;
case R.id.btn_video://视频处理
case R.id.btn_video://handle video
intent.setClass(MainActivity.this, VideoHandleActivity.class);
break;
case R.id.btn_media://音视频处理
case R.id.btn_media://handle media
intent.setClass(MainActivity.this, MediaHandleActivity.class);
break;
case R.id.btn_play://音视频播放
case R.id.btn_play://media play
intent.setClass(MainActivity.this, MediaPlayerActivity.class);
break;
case R.id.btn_push://FFmpeg推流
case R.id.btn_push://pushing
intent.setClass(MainActivity.this, PushActivity.class);
break;
case R.id.btn_live://实时推流直播:AAC音频编码、H264视频编码、RTMP推流
case R.id.btn_live://realtime living with rtmp stream
intent.setClass(MainActivity.this, LiveActivity.class);
break;
case R.id.btn_filter://滤镜特效
case R.id.btn_filter://filter effect
intent.setClass(MainActivity.this, FilterActivity.class);
break;
case R.id.btn_preview://视频拖动实时预览
case R.id.btn_preview://preview thumbnail
intent.setClass(MainActivity.this, VideoPreviewActivity.class);
break;
case R.id.btn_probe://解析音视频多媒体格式
case R.id.btn_probe://probe media format
intent.setClass(MainActivity.this, ProbeFormatActivity.class);
break;
default:

@ -11,6 +11,7 @@ import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import com.frank.ffmpeg.R;
import com.frank.ffmpeg.handler.FFmpegHandler;
import com.frank.ffmpeg.util.FFmpegUtil;
@ -23,7 +24,7 @@ import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_CONTINUE;
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH;
/**
* 使用ffmpeg进行音视频合成与分离
* using ffmpeg to handle media
* Created by frank on 2018/1/23.
*/
public class MediaHandleActivity extends BaseActivity {
@ -49,25 +50,21 @@ public class MediaHandleActivity extends BaseActivity {
String muxFile = PATH + File.separator + "media-mux.mp4";
try {
//使用MediaPlayer获取视频时长
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(videoFile);
mediaPlayer.prepare();
//单位为ms
//ms
int videoDuration = mediaPlayer.getDuration() / 1000;
Log.i(TAG, "videoDuration=" + videoDuration);
mediaPlayer.release();
//使用MediaMetadataRetriever获取音频时长
MediaMetadataRetriever mediaRetriever = new MediaMetadataRetriever();
mediaRetriever.setDataSource(audioFile);
//单位为ms
String duration = mediaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
int audioDuration = (int) (Long.parseLong(duration) / 1000);
Log.i(TAG, "audioDuration=" + audioDuration);
mediaRetriever.release();
//如果视频时长比音频长,采用音频时长,否则用视频时长
int mDuration = Math.min(audioDuration, videoDuration);
//使用纯视频与音频进行合成
//mux video and audio
String[] commandLine = FFmpegUtil.mediaMux(temp, audioFile, mDuration, muxFile);
if (ffmpegHandler != null) {
ffmpegHandler.isContinue(false);
@ -127,7 +124,8 @@ public class MediaHandleActivity extends BaseActivity {
}
/**
* 调用ffmpeg处理音视频
* execute ffmpeg cmd to handle media
*
* @param srcFile srcFile
*/
private void doHandleMedia(String srcFile) {
@ -141,9 +139,8 @@ public class MediaHandleActivity extends BaseActivity {
}
switch (viewId) {
case R.id.btn_mux://音视频合成
case R.id.btn_mux://mux
try {
//视频文件有音频,先把纯视频文件抽取出来
videoFile = srcFile;
commandLine = FFmpegUtil.extractVideo(srcFile, temp);
if (ffmpegHandler != null) {
@ -153,11 +150,11 @@ public class MediaHandleActivity extends BaseActivity {
e.printStackTrace();
}
break;
case R.id.btn_extract_audio://提取音频
case R.id.btn_extract_audio://extract audio
String extractAudio = PATH + File.separator + "extractAudio.aac";
commandLine = FFmpegUtil.extractAudio(srcFile, extractAudio);
break;
case R.id.btn_extract_video://提取视频
case R.id.btn_extract_video://extract video
String extractVideo = PATH + File.separator + "extractVideo.mp4";
commandLine = FFmpegUtil.extractVideo(srcFile, extractVideo);
break;

Loading…
Cancel
Save