combine a series of pictures into video

combine a series of pictures into video
pull/166/head
xufulong 5 years ago
parent 6b12be960b
commit 5002560f11
  1. 2
      app/src/main/cpp/ffmpeg/ffmpeg.c
  2. 23
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  3. 4
      app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java

@ -4343,7 +4343,7 @@ int run(int argc, char **argv)
// exit_program(received_nb_signals ? 255 : main_return_code); // exit_program(received_nb_signals ? 255 : main_return_code);
end: 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); ffmpeg_cleanup(0);
return main_return_code; return main_return_code;
} }

@ -321,16 +321,33 @@ public class VideoHandleActivity extends BaseActivity {
*/ */
private void handlePhoto() { private void handlePhoto() {
// The path of pictures, naming format: img+number.jpg // The path of pictures, naming format: img+number.jpg
// Here assigns the directory is img under the root path
String picturePath = PATH + "/img/"; String picturePath = PATH + "/img/";
if (!FileUtil.checkFileExist(picturePath)) { if (!FileUtil.checkFileExist(picturePath)) {
return; 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<String[]> 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"; String combineVideo = PATH + File.separator + "combineVideo.mp4";
int frameRate = 2;// suggested synthetic frameRate:1-10 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) { if (ffmpegHandler != null) {
ffmpegHandler.executeFFmpegCmd(commandLine); ffmpegHandler.executeFFmpegCmds(cmdList);
} }
} }

@ -228,7 +228,7 @@ public class FFmpegUtil {
* @param imgPath the path of the image * @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 location the location in the video(1:top left 2:top right 3:bottom left 4:bottom right)
* @param bitRate bitRate * @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 * @param targetFile output file
* @return add watermark success or not * @return add watermark success or not
*/ */
@ -345,7 +345,7 @@ public class FFmpegUtil {
*/ */
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
public static String[] convertResolution(String srcFile, String resolution, String targetFile) { 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); convertCmd = String.format(convertCmd, srcFile, resolution, targetFile);
return convertCmd.split(" "); return convertCmd.split(" ");
} }

Loading…
Cancel
Save