From 6c47625fcb78fdfcf3ed0aefeefcbdce2bd9efd4 Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Sat, 23 Nov 2019 14:48:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E8=A7=86=E9=A2=91=E5=89=AA=E5=88=87?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E4=B8=8E=E5=8E=9F=E6=A0=BC=E5=BC=8F=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 音视频剪切保持与原格式一致 --- .../com/frank/ffmpeg/activity/AudioHandleActivity.java | 6 +++++- .../com/frank/ffmpeg/activity/VideoHandleActivity.java | 6 +++++- app/src/main/java/com/frank/ffmpeg/util/FileUtil.java | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) 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 3d833cf..8da9c59 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.java @@ -119,7 +119,11 @@ public class AudioHandleActivity extends BaseActivity { mp3Converter.convertToMp3(inputFile, transformFile); break; 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); break; case R.id.btn_concat://合并,支持MP3、AAC、AMR等,不支持PCM裸流,不支持WAV(PCM裸流加音频头) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java index 08a9da4..74cca13 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java @@ -111,7 +111,11 @@ public class VideoHandleActivity extends BaseActivity { commandLine = FFmpegUtil.transformVideo(srcFile, transformVideo); break; 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 duration = 20; commandLine = FFmpegUtil.cutVideo(srcFile, startTime, duration, cutVideo); diff --git a/app/src/main/java/com/frank/ffmpeg/util/FileUtil.java b/app/src/main/java/com/frank/ffmpeg/util/FileUtil.java index 293fc14..f1997a0 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FileUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FileUtil.java @@ -137,4 +137,11 @@ public class FileUtil { || path.endsWith(TYPE_MOV); } + public static String getFileSuffix(String fileName) { + if (TextUtils.isEmpty(fileName) || !fileName.contains(".")) { + return null; + } + return fileName.substring(fileName.lastIndexOf(".")); + } + }