视频转gif:设置分辨率、帧率来提高质量

视频转gif:设置分辨率、帧率来提高质量
pull/107/head
xufulong 5 years ago
parent e64559b722
commit 79625ea94b
  1. 5
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  2. 13
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java

@ -156,7 +156,10 @@ public class VideoHandleActivity extends BaseActivity {
String Video2Gif = PATH + File.separator + "Video2Gif.gif"; String Video2Gif = PATH + File.separator + "Video2Gif.gif";
int gifStart = 30; int gifStart = 30;
int gifDuration = 5; 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; break;
case R.id.btn_screen_record://屏幕录制 case R.id.btn_screen_record://屏幕录制
// String screenRecord = PATH + File.separator + "screenRecord.mp4"; // String screenRecord = PATH + File.separator + "screenRecord.mp4";

@ -173,14 +173,17 @@ public class FFmpegUtil {
* @param startTime 开始时间 * @param startTime 开始时间
* @param duration 截取时长 * @param duration 截取时长
* @param targetFile 目标文件 * @param targetFile 目标文件
* @param resolution 分辨率
* @param frameRate 帧率
* @return Gif文件 * @return Gif文件
*/ */
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
public static String[] generateGif(String srcFile, int startTime, int duration, String targetFile){ public static String[] generateGif(String srcFile, int startTime, int duration,
//String screenShotCmd = "ffmpeg -i %s -vframes %d -f gif %s"; String resolution, int frameRate, String targetFile){
String screenShotCmd = "ffmpeg -i %s -ss %d -t %d -s 320x240 -f gif %s"; String generateGifCmd = "ffmpeg -i %s -ss %d -t %d -s %s -r %d -f gif %s";
screenShotCmd = String.format(screenShotCmd, srcFile, startTime, duration, targetFile); generateGifCmd = String.format(generateGifCmd, srcFile, startTime, duration,
return screenShotCmd.split(" ");//以空格分割为字符串数组 resolution, frameRate, targetFile);
return generateGifCmd.split(" ");//以空格分割为字符串数组
} }
/** /**

Loading…
Cancel
Save