音视频剪切保持与原格式一致

音视频剪切保持与原格式一致
pull/107/head
xufulong 5 years ago
parent b08d782c99
commit 6c47625fcb
  1. 6
      app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java
  2. 6
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  3. 7
      app/src/main/java/com/frank/ffmpeg/util/FileUtil.java

@ -119,7 +119,11 @@ public class AudioHandleActivity extends BaseActivity {
mp3Converter.convertToMp3(inputFile, transformFile); mp3Converter.convertToMp3(inputFile, transformFile);
break; break;
case R.id.btn_cut://剪切(注意原文件与剪切文件格式一致,文件绝对路径最好不包含中文、特殊字符) case R.id.btn_cut://剪切(注意原文件与剪切文件格式一致,文件绝对路径最好不包含中文、特殊字符)
String cutFile = PATH + File.separator + "cut.mp3"; String suffix = FileUtil.getFileSuffix(srcFile);
if (suffix == null || suffix.isEmpty()) {
return;
}
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://合并,支持MP3、AAC、AMR等,不支持PCM裸流,不支持WAV(PCM裸流加音频头)

@ -111,7 +111,11 @@ public class VideoHandleActivity extends BaseActivity {
commandLine = FFmpegUtil.transformVideo(srcFile, transformVideo); commandLine = FFmpegUtil.transformVideo(srcFile, transformVideo);
break; break;
case R.id.btn_video_cut://视频剪切 case R.id.btn_video_cut://视频剪切
String cutVideo = PATH + File.separator + "cutVideo.mp4"; String suffix = FileUtil.getFileSuffix(srcFile);
if (suffix == null || suffix.isEmpty()) {
return;
}
String cutVideo = PATH + File.separator + "cutVideo" + suffix;
int startTime = 0; int startTime = 0;
int duration = 20; int duration = 20;
commandLine = FFmpegUtil.cutVideo(srcFile, startTime, duration, cutVideo); commandLine = FFmpegUtil.cutVideo(srcFile, startTime, duration, cutVideo);

@ -137,4 +137,11 @@ public class FileUtil {
|| path.endsWith(TYPE_MOV); || path.endsWith(TYPE_MOV);
} }
public static String getFileSuffix(String fileName) {
if (TextUtils.isEmpty(fileName) || !fileName.contains(".")) {
return null;
}
return fileName.substring(fileName.lastIndexOf("."));
}
} }

Loading…
Cancel
Save