From 979b25dbbf6f096c1bb76c5164a302b9961d05a8 Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Thu, 19 Aug 2021 00:22:59 +0800 Subject: [PATCH] change time unit from int to float --- .../frank/ffmpeg/activity/AudioHandleActivity.kt | 2 +- .../frank/ffmpeg/activity/VideoHandleActivity.kt | 6 +++--- .../java/com/frank/ffmpeg/util/FFmpegUtil.java | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt index 71093d3..e86c61d 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt @@ -174,7 +174,7 @@ class AudioHandleActivity : BaseActivity() { return } val cutFile = PATH + File.separator + "cutAudio" + suffix - commandLine = FFmpegUtil.cutAudio(srcFile, 10, 15, cutFile) + commandLine = FFmpegUtil.cutAudio(srcFile, 10.5f, 15.0f, cutFile) } R.id.btn_concat//concat audio -> { diff --git a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt index acd005d..b04bf5d 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt @@ -165,8 +165,8 @@ class VideoHandleActivity : BaseActivity() { R.id.btn_video_cut//cut video -> { val cutVideo = PATH + File.separator + "cutVideo" + suffix - val startTime = 0 - val duration = 20 + val startTime = 5.5f + val duration = 20.0f commandLine = FFmpegUtil.cutVideo(srcFile, startTime, duration, cutVideo) } R.id.btn_video_concat//concat video together @@ -174,7 +174,7 @@ class VideoHandleActivity : BaseActivity() { R.id.btn_screen_shot//video snapshot -> { val screenShot = PATH + File.separator + "screenShot.jpg" - val time = 18 + val time = 10.5f commandLine = FFmpegUtil.screenShot(srcFile, time, screenShot) } R.id.btn_water_mark//add watermark to video diff --git a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java index 8cd1ced..0e97cfa 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -41,8 +41,8 @@ public class FFmpegUtil { * @param outputPath output file * @return cut success or not */ - public static String[] cutAudio(String inputPath, int startTime, int duration, String outputPath) { - String cutAudioCmd = "ffmpeg -ss %d -accurate_seek -t %d -i %s -acodec copy -vn %s"; + public static String[] cutAudio(String inputPath, float startTime, float duration, String outputPath) { + String cutAudioCmd = "ffmpeg -ss %f -accurate_seek -t %f -i %s -acodec copy -vn %s"; cutAudioCmd = String.format(Locale.getDefault(), cutAudioCmd, startTime, duration, inputPath, outputPath); return cutAudioCmd.split(" "); } @@ -333,12 +333,12 @@ public class FFmpegUtil { * @param outputPath output file * @return cut video success or not */ - public static String[] cutVideo(String inputPath, int startTime, int duration, String outputPath) { + public static String[] cutVideo(String inputPath, float startTime, float duration, String outputPath) { // -map 0 -codec copy (copy all tracks) // -map 0:v -vcodec copy (copy track of video) // -map 0:a -acodec copy (copy all tracks of audio) // -map 0:s -scodec copy (copy all tracks of subtitle) - String cutVideoCmd = "ffmpeg -ss %d -accurate_seek -t %d -i %s -map 0 -codec copy -avoid_negative_ts 1 %s"; + String cutVideoCmd = "ffmpeg -ss %f -accurate_seek -t %f -i %s -map 0 -codec copy -avoid_negative_ts 1 %s"; cutVideoCmd = String.format(Locale.getDefault(), cutVideoCmd, startTime, duration, inputPath, outputPath); return cutVideoCmd.split(" "); } @@ -347,13 +347,13 @@ public class FFmpegUtil { * screenshot from video, you could assign the specific time * * @param inputPath input file - * @param time which time you want to shot + * @param offset which time you want to shot * @param outputPath output file * @return screenshot success or not */ - public static String[] screenShot(String inputPath, int time, String outputPath) { - String screenShotCmd = "ffmpeg -ss %d -i %s -f image2 -vframes 1 -an %s"; - screenShotCmd = String.format(Locale.getDefault(), screenShotCmd, time, inputPath, outputPath); + public static String[] screenShot(String inputPath, float offset, String outputPath) { + String screenShotCmd = "ffmpeg -ss %f -i %s -f image2 -vframes 1 -an %s"; + screenShotCmd = String.format(Locale.getDefault(), screenShotCmd, offset, inputPath, outputPath); return screenShotCmd.split(" "); }