From 485a2195226ae37b6d724505acfb82c94443203c Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Mon, 4 Nov 2024 16:22:00 +0900 Subject: [PATCH] feat: add debug option for every ffmpeg commend --- .../kr/mafoo/photo/service/RecapService.java | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/RecapService.java b/photo-service/src/main/java/kr/mafoo/photo/service/RecapService.java index 8e0e9b9..5fafeff 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/RecapService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/RecapService.java @@ -78,6 +78,7 @@ private Mono generateRecapFrame(String recapId, String memberName, Strin String recapCreatedDate = DateTimeFormatter.ofPattern("yyyy.MM.dd").format(LocalDate.now()); FFmpegBuilder builder = new FFmpegBuilder() + .addExtraArgs("-loglevel", "debug") .addExtraArgs( "-filter_complex", String.format( @@ -107,29 +108,38 @@ private Mono generateRecapFrame(String recapId, String memberName, Strin private Mono generateRecapPhotos(List downloadedPath, String recapId) { return Mono.fromRunnable(() -> { - - FFmpegBuilder builder = new FFmpegBuilder() + try { + FFmpegBuilder builder = new FFmpegBuilder() + .addExtraArgs("-loglevel", "debug") .addInput(recapProperties.getFrameFilePath(recapId)); - for (String path : downloadedPath) { - builder.addInput(path); - } + for (String path : downloadedPath) { + builder.addInput(path); + } - StringBuilder filterComplex = new StringBuilder(); + StringBuilder filterComplex = new StringBuilder(); - for (int inputIndex = 1; inputIndex <= downloadedPath.size(); inputIndex++) { - filterComplex.append(String.format("[%d]scale='min(1200,iw)':'min(1776,ih)':force_original_aspect_ratio=decrease[photo_scaled_%d]; ", inputIndex, inputIndex)); - filterComplex.append(String.format("[recap_bg][photo_scaled_%d]overlay=(W-w)/2:(H-h)/2+80[final%d];", inputIndex, inputIndex)); - } + for (int inputIndex = 1; inputIndex <= downloadedPath.size(); inputIndex++) { + filterComplex.append(String.format( + "[%d]scale='min(1200,iw)':'min(1776,ih)':force_original_aspect_ratio=decrease[photo_scaled_%d]; ", + inputIndex, inputIndex)); + filterComplex.append(String.format( + "[recap_bg][photo_scaled_%d]overlay=(W-w)/2:(H-h)/2+80[final%d];", + inputIndex, inputIndex)); + } - builder.addExtraArgs("-filter_complex", filterComplex.toString()); + builder.addExtraArgs("-filter_complex", filterComplex.toString()); - for (int outputIndex = 1; outputIndex <= downloadedPath.size(); outputIndex++) { - builder.addOutput(recapProperties.getPhotoFilePath(recapId, outputIndex)) - .addExtraArgs("-map", String.format("[final%d]", outputIndex)); - } + for (int outputIndex = 1; outputIndex <= downloadedPath.size(); outputIndex++) { + builder.addOutput(recapProperties.getPhotoFilePath(recapId, outputIndex)) + .addExtraArgs("-map", String.format("[final%d]", outputIndex)); + } - ffmpegExecutor.createJob(builder).run(); + ffmpegExecutor.createJob(builder).run(); + } catch (Exception e) { + log.error("Failed to generate recap photos", e); + throw new RuntimeException("Failed to generate recap photos", e); + } }).then(); } @@ -139,8 +149,9 @@ private Mono generateRecapVideo(String recapId) { String recapVideoPath = recapProperties.getVideoFilePath(recapId); FFmpegBuilder builder = new FFmpegBuilder() + .addExtraArgs("-loglevel", "debug") .addExtraArgs("-r", "2") - .addInput(recapProperties.getPhotoFilePath(recapId)) + .addInput(recapProperties.getPhotoFilePath(recapId)) .addOutput(recapVideoPath) .done();