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(" ");//以空格分割为字符串数组 } /**