From 5ba51d9b8242653f360045b33163040dc4fd9722 Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Sat, 26 Sep 2020 12:33:15 +0800 Subject: [PATCH] extract video frames with scale extract video frames with scale --- .../ffmpeg/activity/VideoHandleActivity.java | 4 ++-- .../java/com/frank/ffmpeg/util/FFmpegUtil.java | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 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 031e588..49bf0a4 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.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"; 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 70b3341..eda5a92 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -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(" "); }