extract video frames with scale

extract video frames with scale
pull/166/head
xufulong 4 years ago
parent 8e3237ba3d
commit 5ba51d9b82
  1. 4
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  2. 18
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java

@ -264,9 +264,9 @@ public class VideoHandleActivity extends BaseActivity {
}
}
int mStartTime = 10;//start time
int mDuration = 20;//duration
int mDuration = 5;//duration
int mFrameRate = 10;//frameRate
commandLine = FFmpegUtil.videoToImage(srcFile, mStartTime, mDuration, mFrameRate, imagePath);
commandLine = FFmpegUtil.videoToImageWithScale(srcFile, mStartTime, mDuration, mFrameRate, 320, imagePath);
break;
case R.id.btn_pip://combine into picture-in-picture video
String inputFile1 = PATH + File.separator + "beyond.mp4";

@ -427,11 +427,19 @@ public class FFmpegUtil {
* @return convert success or not
*/
public static String[] videoToImage(String inputFile, int startTime, int duration, int frameRate, String targetFile) {
//-ss:start time
//-t:duration
//-r:frame rate
String toImage = "ffmpeg -i %s -ss %s -t %s -r %s %s";
toImage = String.format(Locale.CHINESE, toImage, inputFile, startTime, duration, frameRate, targetFile);
return videoToImageWithScale(inputFile, startTime, duration, frameRate, 0, targetFile);
}
public static String[] videoToImageWithScale(String inputFile, int startTime, int duration,
int frameRate, int width, String targetFile) {
String toImage;
if (width > 0) {
toImage = "ffmpeg -i %s -ss %d -t %d -an -vf fps=%d,scale=%d:-1 %s";
toImage = String.format(Locale.CHINESE, toImage, inputFile, startTime, duration, frameRate, width, targetFile);
} else {
toImage = "ffmpeg -i %s -ss %d -t %d -an -r %d %s";
toImage = String.format(Locale.CHINESE, toImage, inputFile, startTime, duration, frameRate, targetFile);
}
toImage = toImage + "%3d.jpg";
return toImage.split(" ");
}

Loading…
Cancel
Save