Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 파일제목 변경 (#29) #32

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,12 @@ public List<String> extractAndUploadFrames(File videoFile, Long videoId) {


String outputPath = outputDir.getAbsolutePath() + "/frame_%03d.jpg";
// 필터 설정: 4.2초 주기 동안 2.4초 동안 5개의 이미지를 추출하고, 나머지 1.8초는 건너뛰기
// 정상 동작하는 필터 (그러나 5번 이미지가 5장씩 나옴)
// String filter = "select='if(gte(mod(t,4.2),0),if(lt(mod(t,4.2),2.3),1,0),0)',fps=1.1905";
// String filter = "select='if(gte(mod(t,4.2),0),if(lt(mod(t,4.2),2.4),1,0),0)',fps=2.083";

// 아래는 시도해본 흔적들... 필터를 수정하시면 됩니다
// String filter = "select='if(lt(mod(t,4.2),2.37),1,0)',fps=2.109";
// String filter = "select='if(lt(mod(t,4.2),2.34),1,if(lt(mod(t,4.2),4.2),0,1))',fps=2.136";
String filter = "select='lt(mod(t,4.2),2.461)',fps=2.031";
//2.47, 2.475, 2.472, 2.468, 2.463(best), 2.461(best), 2.462(최악)
// 필터 설정: 4.2초 주기 동안 2.463초 동안 5개의 이미지를 추출하고, 나머지 1.n초는 건너뛰기, fps=5%2.463
String filter = "select='lt(mod(t,4.4),2.43)',fps=2.057";
//2.47, 2.475, 2.472, 2.468, 2.463(best), 2.461(best), 2.462(최악), 2.45(최악), 2.464(최악)
//2.465
//4.4초 주기 동안 0.48초 간격(총 2.44초 동안 5개 이미지 추출)
// String filter = "select='lt(mod(t,4.4),2.44)',fps=2.049";

ProcessBuilder processBuilder = new ProcessBuilder(
"ffmpeg", "-i", videoFile.getAbsolutePath(),
Expand Down Expand Up @@ -140,13 +136,14 @@ public List<String> extractAndUploadFrames(File videoFile, Long videoId) {
List<File> frameBatch = new ArrayList<>();
int frameCount = 0;
int frameIndex = 1;
int objectIndex = 1;
int cameraIndex = 1;

for (File file : files) {
frameBatch.add(file);
frameCount++;

// 9개 프레임 묶음 처리
if (frameBatch.size() == 9 || frameCount == files.length) {
if (frameBatch.size() == 9 || frameBatch.size() + frameCount == files.length) {
log.info("Processing batch of 9 frames...");

// 앞 5개는 업로드
Expand All @@ -155,7 +152,7 @@ public List<String> extractAndUploadFrames(File videoFile, Long videoId) {
MultipartFile multipartFile = convertToMultipartFile(frameFile);

// S3 업로드
String frameUrl = s3Manager.uploadFile("framestest13/" + String.format("frame_%03d.jpg", frameIndex), multipartFile);
String frameUrl = s3Manager.uploadFile("framestest13/" + String.format("frame_%d_%d_%03d.jpg", objectIndex, cameraIndex, frameIndex), multipartFile);
frameUrls.add(frameUrl);

// 프레임 메타데이터 저장
Expand All @@ -170,6 +167,7 @@ public List<String> extractAndUploadFrames(File videoFile, Long videoId) {
frameFile.delete();

frameIndex++;
cameraIndex++;
}

// 뒤 4개는 삭제
Expand All @@ -179,6 +177,9 @@ public List<String> extractAndUploadFrames(File videoFile, Long videoId) {
frameFile.delete();
}

objectIndex++;
cameraIndex = 1;

// 묶음 초기화
frameBatch.clear();
}
Expand Down
Loading