add time to gif

add time to gif
pull/166/head
xufulong 4 years ago
parent 2f51cd54a7
commit 3ac4fb0f31
  1. 3
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  2. 10
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java

@ -228,7 +228,8 @@ public class VideoHandleActivity extends BaseActivity {
int frameRate = 10;
String palettePath = PATH + "/palette.png";
FileUtil.deleteFile(palettePath);
String[] paletteCmd = FFmpegUtil.generatePalette(srcFile, frameRate, width, palettePath);
String[] paletteCmd = FFmpegUtil.generatePalette(srcFile, gifStart, gifDuration,
frameRate, width, palettePath);
String[] gifCmd = FFmpegUtil.generateGifByPalette(srcFile, palettePath, gifStart, gifDuration,
frameRate, width, Video2Gif);
List<String[]> cmdList = new ArrayList<>();

@ -288,13 +288,17 @@ public class FFmpegUtil {
*
* @param srcFile input file
* @param frameRate frameRate of the gif
* @param startTime startTime in the video
* @param duration duration, how long you want to
* @param width width
* @param targetFile output file
* @return generate palette success or not
*/
public static String[] generatePalette(String srcFile, int frameRate, int width, String targetFile) {
String paletteCmd = "ffmpeg -i %s -vf fps=%d,scale=%d:-1:flags=lanczos,palettegen %s";
paletteCmd = String.format(Locale.getDefault(), paletteCmd, srcFile, frameRate, width, targetFile);
public static String[] generatePalette(String srcFile, int startTime, int duration,
int frameRate, int width, String targetFile) {
String paletteCmd = "ffmpeg -i %s -ss %d -t %d -vf fps=%d,scale=%d:-1:flags=lanczos,palettegen %s";
paletteCmd = String.format(Locale.getDefault(), paletteCmd, srcFile, startTime,
duration, frameRate, width, targetFile);
return paletteCmd.split(" ");
}

Loading…
Cancel
Save