From a27413030e0ed152ed14b5a41c04dfc37f2e9805 Mon Sep 17 00:00:00 2001 From: xufuji456 Date: Sun, 9 Oct 2022 18:20:14 +0800 Subject: [PATCH] Feature: zoompan photo to video --- .../ffmpeg/activity/VideoHandleActivity.kt | 3 +- .../com/frank/ffmpeg/util/FFmpegUtil.java | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt index ba90675..75131ba 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.kt @@ -332,7 +332,8 @@ class VideoHandleActivity : BaseActivity() { } 18 -> { // zoom photo to video outputPath = PATH + File.separator + "zoom.mp4" - commandLine = FFmpegUtil.photoZoomToVideo(srcFile, outputPath) + val position = 0 + commandLine = FFmpegUtil.photoZoomToVideo(srcFile, position, outputPath) } else -> { } 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 24cf02e..9406f1f 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -664,12 +664,36 @@ public class FFmpegUtil { /** * Photo zoom to video * @param inputPath inputPath + * @param position position + * 0:center + * 1:left to right + * 2:right to left + * 3:down to up + * 4:up to down * @param outputPath outputPath * @return zoomCmd */ - public static String[] photoZoomToVideo(String inputPath, String outputPath) { - String zoomCmd = "ffmpeg -loop 1 -i -vf zoompan=z='if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0015))':d=125 -t 8"; - return insert(zoomCmd.split(" "), 4, inputPath, outputPath); + public static String[] photoZoomToVideo(String inputPath, int position, String outputPath) { + String zoomCmd = "ffmpeg -i -vf "; + switch (position) { + case 1: + zoomCmd += "zoompan='1.3':x='if(lte(on,1),(iw/zoom)/2,x-0.5)':y='if(lte(on,1),(ih-ih/zoom)/2,y)':d=180"; + break; + case 2: + zoomCmd += "zoompan='1.3':x='if(lte(on,-1),(iw-iw/zoom)/2,x+0.5)':y='if(lte(on,1),(ih-ih/zoom)/2,y)':d=180"; + break; + case 3: + zoomCmd += "zoompan='1.3':x='if(lte(on,1),(iw-iw/zoom)/2,x)':y='if(lte(on,-1),(ih-ih/zoom)/2,y+0.5)':d=180"; + break; + case 4: + zoomCmd += "zoompan='1.3':x='if(lte(on,1),(iw-iw/zoom)/2,x)':y='if(lte(on,1),(ih/zoom)/2,y-0.5)':d=180"; + break; + case 0: + default: + zoomCmd += "zoompan=z='min(zoom+0.0015,1.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=180"; + break; + } + return insert(zoomCmd.split(" "), 2, inputPath, outputPath); } /**