From 5002560f11d87fed13062e6775b2ffbbfa267aec Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Wed, 13 May 2020 00:21:41 +0800 Subject: [PATCH] combine a series of pictures into video combine a series of pictures into video --- app/src/main/cpp/ffmpeg/ffmpeg.c | 2 +- .../ffmpeg/activity/VideoHandleActivity.java | 23 ++++++++++++++++--- .../com/frank/ffmpeg/util/FFmpegUtil.java | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/ffmpeg/ffmpeg.c b/app/src/main/cpp/ffmpeg/ffmpeg.c index dc25d4c..ea0eef0 100644 --- a/app/src/main/cpp/ffmpeg/ffmpeg.c +++ b/app/src/main/cpp/ffmpeg/ffmpeg.c @@ -4343,7 +4343,7 @@ int run(int argc, char **argv) // exit_program(received_nb_signals ? 255 : main_return_code); end: - av_log(NULL, AV_LOG_ERROR, "FFmpeg result=%d\n", main_return_code); + av_log(NULL, AV_LOG_INFO, "FFmpeg result=%d\n", main_return_code); ffmpeg_cleanup(0); return main_return_code; } 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 747bfa1..fd2a6be 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java +++ b/app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java @@ -321,16 +321,33 @@ public class VideoHandleActivity extends BaseActivity { */ private void handlePhoto() { // The path of pictures, naming format: img+number.jpg - // Here assigns the directory is img under the root path String picturePath = PATH + "/img/"; if (!FileUtil.checkFileExist(picturePath)) { return; } + String tempPath = PATH + "/temp/"; + File tempFile = new File(tempPath); + if (tempFile.exists()) { + tempFile.delete(); + } + tempFile.mkdirs(); + File photoFile = new File(picturePath); + File[] files = photoFile.listFiles(); + List cmdList = new ArrayList<>(); + //the resolution of photo which you want to convert + String resolution = "640x320"; + for (File file : files) { + String inputPath = file.getAbsolutePath(); + String outputPath = tempPath + file.getName(); + String[] convertCmd = FFmpegUtil.convertResolution(inputPath, resolution, outputPath); + cmdList.add(convertCmd); + } String combineVideo = PATH + File.separator + "combineVideo.mp4"; int frameRate = 2;// suggested synthetic frameRate:1-10 - String[] commandLine = FFmpegUtil.pictureToVideo(picturePath, frameRate, combineVideo); + String[] commandLine = FFmpegUtil.pictureToVideo(tempPath, frameRate, combineVideo); + cmdList.add(commandLine); if (ffmpegHandler != null) { - ffmpegHandler.executeFFmpegCmd(commandLine); + ffmpegHandler.executeFFmpegCmds(cmdList); } } 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 05aba19..dac8dc2 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -228,7 +228,7 @@ public class FFmpegUtil { * @param imgPath the path of the image * @param location the location in the video(1:top left 2:top right 3:bottom left 4:bottom right) * @param bitRate bitRate - * @param offsetXY the offset of x and y in the video + * @param offsetXY the offset of x and y in the video * @param targetFile output file * @return add watermark success or not */ @@ -345,7 +345,7 @@ public class FFmpegUtil { */ @SuppressLint("DefaultLocale") public static String[] convertResolution(String srcFile, String resolution, String targetFile) { - String convertCmd = "ffmpeg -i %s -s %s %s"; + String convertCmd = "ffmpeg -i %s -s %s -pix_fmt yuv420p %s"; convertCmd = String.format(convertCmd, srcFile, resolution, targetFile); return convertCmd.split(" "); }