From 79625ea94b005d08a7f6d8201f05ac94e686d8bc Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Thu, 21 Nov 2019 01:36:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E8=BD=ACgif:=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=88=86=E8=BE=A8=E7=8E=87=E3=80=81=E5=B8=A7=E7=8E=87?= =?UTF-8?q?=E6=9D=A5=E6=8F=90=E9=AB=98=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 视频转gif:设置分辨率、帧率来提高质量 --- .../frank/ffmpeg/activity/VideoHandleActivity.java | 5 ++++- .../main/java/com/frank/ffmpeg/util/FFmpegUtil.java | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) 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 4ee0454..cbef6b2 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java @@ -156,7 +156,10 @@ public class VideoHandleActivity extends BaseActivity { String Video2Gif = PATH + File.separator + "Video2Gif.gif"; int gifStart = 30; int gifDuration = 5; - commandLine = FFmpegUtil.generateGif(srcFile, gifStart, gifDuration, Video2Gif); + String resolution = "720x1280";//240x320、480x640、1080x1920 + int frameRate = 10; + commandLine = FFmpegUtil.generateGif(srcFile, gifStart, gifDuration, + resolution, frameRate, Video2Gif); break; case R.id.btn_screen_record://屏幕录制 // String screenRecord = PATH + File.separator + "screenRecord.mp4"; 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 146204c..e2a0031 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -173,14 +173,17 @@ public class FFmpegUtil { * @param startTime 开始时间 * @param duration 截取时长 * @param targetFile 目标文件 + * @param resolution 分辨率 + * @param frameRate 帧率 * @return Gif文件 */ @SuppressLint("DefaultLocale") - public static String[] generateGif(String srcFile, int startTime, int duration, String targetFile){ - //String screenShotCmd = "ffmpeg -i %s -vframes %d -f gif %s"; - String screenShotCmd = "ffmpeg -i %s -ss %d -t %d -s 320x240 -f gif %s"; - screenShotCmd = String.format(screenShotCmd, srcFile, startTime, duration, targetFile); - return screenShotCmd.split(" ");//以空格分割为字符串数组 + public static String[] generateGif(String srcFile, int startTime, int duration, + String resolution, int frameRate, String targetFile){ + String generateGifCmd = "ffmpeg -i %s -ss %d -t %d -s %s -r %d -f gif %s"; + generateGifCmd = String.format(generateGifCmd, srcFile, startTime, duration, + resolution, frameRate, targetFile); + return generateGifCmd.split(" ");//以空格分割为字符串数组 } /**