openfree commited on
Commit
0e61865
ยท
verified ยท
1 Parent(s): 034130a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -43
app.py CHANGED
@@ -630,46 +630,41 @@ def merge_videos_with_audio(video_files, audio_file, audio_volume, output_fps):
630
 
631
  status = f"{len(video_paths)}๊ฐœ์˜ ๋น„๋””์˜ค ๋กœ๋“œ ์ค‘..."
632
 
633
- # ๋น„๋””์˜ค ํด๋ฆฝ ๋กœ๋“œ ๋ฐ ํฌ๊ธฐ ํ™•์ธ
634
  video_clips = []
635
- max_width = 0
636
- max_height = 0
637
 
638
  for i, video_path in enumerate(video_paths):
639
  status = f"๋น„๋””์˜ค {i+1}/{len(video_paths)} ๋กœ๋“œ ์ค‘: {os.path.basename(video_path)}"
640
  clip = VideoFileClip(video_path)
641
  video_clips.append(clip)
642
 
643
- # ์ตœ๋Œ€ ํฌ๊ธฐ ์ถ”์ 
644
- if clip.w > max_width:
645
- max_width = clip.w
646
- if clip.h > max_height:
647
- max_height = clip.h
648
 
649
- # ์ž„์‹œ ๋ณ€์ˆ˜ ์ •๋ฆฌ๋ฅผ ์œ„ํ•œ ๋ฐฐ๊ฒฝ ํด๋ฆฝ ์ €์žฅ
650
- background_clips = []
651
 
652
- # ๋ชจ๋“  ๋น„๋””์˜ค๋ฅผ ์ตœ๋Œ€ ํฌ๊ธฐ๋กœ ์กฐ์ • (์›๋ณธ ํ’ˆ์งˆ ์œ ์ง€)
653
- resized_clips = []
654
- for clip in video_clips:
655
- if clip.w != max_width or clip.h != max_height:
656
- # ํŒจ๋”ฉ ์ถ”๊ฐ€ ๋ฐฉ์‹ (์›๋ณธ ํ’ˆ์งˆ ์œ ์ง€)
657
- # ๊ฒ€์€์ƒ‰ ๋ฐฐ๊ฒฝ ์ƒ์„ฑ
658
- background = ColorClip(size=(max_width, max_height), color=(0,0,0), duration=clip.duration)
659
- background_clips.append(background)
660
-
661
- # ํด๋ฆฝ์„ ์ค‘์•™์— ๋ฐฐ์น˜
662
- x_center = (max_width - clip.w) // 2
663
- y_center = (max_height - clip.h) // 2
664
-
665
- resized_clip = CompositeVideoClip([
666
- background,
667
- clip.set_position((x_center, y_center))
668
- ])
669
-
670
- resized_clips.append(resized_clip)
671
- else:
672
- resized_clips.append(clip)
673
 
674
  # ์ฒซ ๋ฒˆ์งธ ๋น„๋””์˜ค์˜ FPS๋ฅผ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์‚ฌ์šฉ
675
  if output_fps == 0:
@@ -678,7 +673,7 @@ def merge_videos_with_audio(video_files, audio_file, audio_volume, output_fps):
678
  status = "๋น„๋””์˜ค ๋ณ‘ํ•ฉ ์ค‘..."
679
 
680
  # ๋น„๋””์˜ค ๋ณ‘ํ•ฉ
681
- final_video = concatenate_videoclips(resized_clips, method="compose")
682
 
683
  # ์˜ค๋””์˜ค ์ฒ˜๋ฆฌ
684
  if audio_file:
@@ -763,16 +758,15 @@ def merge_videos_with_audio(video_files, audio_file, audio_volume, output_fps):
763
  # ๋ฆฌ์†Œ์Šค ์ •๋ฆฌ
764
  for clip in video_clips:
765
  clip.close()
766
- for clip in background_clips:
767
- clip.close()
768
- for i, clip in enumerate(resized_clips):
769
- if clip != video_clips[i] if i < len(video_clips) else True: # ๋ฆฌ์‚ฌ์ด์ฆˆ๋œ ๊ฒฝ์šฐ๋งŒ
770
- clip.close()
771
  if audio_file and 'audio_clip' in locals():
772
  audio_clip.close()
773
  final_video.close()
774
 
775
- return temp_filepath, f"โœ… ์„ฑ๊ณต์ ์œผ๋กœ {len(video_paths)}๊ฐœ์˜ ๋น„๋””์˜ค๋ฅผ ๋ณ‘ํ•ฉํ–ˆ์Šต๋‹ˆ๋‹ค! (ํฌ๊ธฐ: {max_width}x{max_height})"
776
 
777
  except Exception as e:
778
  logging.error(f"Video merge error: {str(e)}")
@@ -1057,9 +1051,9 @@ with demo:
1057
 
1058
  gr.Markdown("""
1059
  **ํฌ๊ธฐ ์ฒ˜๋ฆฌ**:
1060
- - ๋ชจ๋“  ๋น„๋””์˜ค๋Š” ๊ฐ€์žฅ ํฐ ๋น„๋””์˜ค์˜ ํฌ๊ธฐ์— ๋งž์ถฐ์ง‘๋‹ˆ๋‹ค
1061
- - ์ž‘์€ ๋น„๋””์˜ค๋Š” ๊ฒ€์€์ƒ‰ ํŒจ๋”ฉ์ด ์ถ”๊ฐ€๋˜์–ด ์ค‘์•™์— ๋ฐฐ์น˜๋ฉ๋‹ˆ๋‹ค
1062
- - ์›๋ณธ ํ™”์งˆ์ด ๊ทธ๋Œ€๋กœ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค
1063
  """)
1064
 
1065
  merge_videos_btn = gr.Button("๐ŸŽฌ ๋น„๋””์˜ค ๋ณ‘ํ•ฉ", variant="primary", elem_id="merge-btn")
@@ -1080,9 +1074,9 @@ with demo:
1080
  4. '๋น„๋””์˜ค ๋ณ‘ํ•ฉ' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š”
1081
 
1082
  **ํŠน์ง•**:
1083
- - โœ… ์ž‘์€ ๋น„๋””์˜ค๋Š” ํŒจ๋”ฉ ์ถ”๊ฐ€๋กœ ์›๋ณธ ํ™”์งˆ ์œ ์ง€
1084
  - โœ… ์—…๋กœ๋“œํ•œ ์˜ค๋””์˜ค๊ฐ€ ์ „์ฒด ๋น„๋””์˜ค์— ์ ์šฉ๋ฉ๋‹ˆ๋‹ค
1085
- - โœ… ์›๋ณธ ํ™”์งˆ์ด ์ตœ๋Œ€ํ•œ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค
1086
 
1087
  **ํŒ**:
1088
  - ํŒŒ์ผ๋ช…์„ 01.mp4, 02.mp4, 03.mp4 ํ˜•์‹์œผ๋กœ ์ง€์ •ํ•˜๋ฉด ์ˆœ์„œ ๊ด€๋ฆฌ๊ฐ€ ์‰ฝ์Šต๋‹ˆ๋‹ค
 
630
 
631
  status = f"{len(video_paths)}๊ฐœ์˜ ๋น„๋””์˜ค ๋กœ๋“œ ์ค‘..."
632
 
633
+ # ๋น„๋””์˜ค ํด๋ฆฝ ๋กœ๋“œ
634
  video_clips = []
635
+ clip_sizes = []
 
636
 
637
  for i, video_path in enumerate(video_paths):
638
  status = f"๋น„๋””์˜ค {i+1}/{len(video_paths)} ๋กœ๋“œ ์ค‘: {os.path.basename(video_path)}"
639
  clip = VideoFileClip(video_path)
640
  video_clips.append(clip)
641
 
642
+ # ๊ฐ ํด๋ฆฝ์˜ ํฌ๊ธฐ ์ €์žฅ
643
+ try:
644
+ clip_sizes.append((clip.w, clip.h))
645
+ except:
646
+ clip_sizes.append(clip.size)
647
 
648
+ # ์ฒซ ๋ฒˆ์งธ ๋น„๋””์˜ค์˜ ํฌ๊ธฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•จ
649
+ target_width, target_height = clip_sizes[0]
650
 
651
+ # ๋ชจ๋“  ๋น„๋””์˜ค์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ™์€์ง€ ํ™•์ธ
652
+ all_same_size = all(size == (target_width, target_height) for size in clip_sizes)
653
+
654
+ if not all_same_size:
655
+ logging.warning(f"๋น„๋””์˜ค ํฌ๊ธฐ๊ฐ€ ์„œ๋กœ ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋น„๋””์˜ค ํฌ๊ธฐ({target_width}x{target_height})๋กœ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค.")
656
+
657
+ # ํฌ๊ธฐ๊ฐ€ ๋‹ค๋ฅธ ๋น„๋””์˜ค๋“ค์„ ์กฐ์ •
658
+ adjusted_clips = []
659
+ for i, clip in enumerate(video_clips):
660
+ if clip_sizes[i] != (target_width, target_height):
661
+ # ๋ฆฌ์‚ฌ์ด์ฆˆ
662
+ adjusted_clip = clip.resize((target_width, target_height))
663
+ adjusted_clips.append(adjusted_clip)
664
+ else:
665
+ adjusted_clips.append(clip)
666
+
667
+ video_clips = adjusted_clips
 
 
 
 
668
 
669
  # ์ฒซ ๋ฒˆ์งธ ๋น„๋””์˜ค์˜ FPS๋ฅผ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์‚ฌ์šฉ
670
  if output_fps == 0:
 
673
  status = "๋น„๋””์˜ค ๋ณ‘ํ•ฉ ์ค‘..."
674
 
675
  # ๋น„๋””์˜ค ๋ณ‘ํ•ฉ
676
+ final_video = concatenate_videoclips(video_clips, method="compose")
677
 
678
  # ์˜ค๋””์˜ค ์ฒ˜๋ฆฌ
679
  if audio_file:
 
758
  # ๋ฆฌ์†Œ์Šค ์ •๋ฆฌ
759
  for clip in video_clips:
760
  clip.close()
761
+ if 'adjusted_clips' in locals():
762
+ for clip in adjusted_clips:
763
+ if clip not in video_clips:
764
+ clip.close()
 
765
  if audio_file and 'audio_clip' in locals():
766
  audio_clip.close()
767
  final_video.close()
768
 
769
+ return temp_filepath, f"โœ… ์„ฑ๊ณต์ ์œผ๋กœ {len(video_paths)}๊ฐœ์˜ ๋น„๋””์˜ค๋ฅผ ๋ณ‘ํ•ฉํ–ˆ์Šต๋‹ˆ๋‹ค! (ํฌ๊ธฐ: {target_width}x{target_height})"
770
 
771
  except Exception as e:
772
  logging.error(f"Video merge error: {str(e)}")
 
1051
 
1052
  gr.Markdown("""
1053
  **ํฌ๊ธฐ ์ฒ˜๋ฆฌ**:
1054
+ - ์ฒซ ๋ฒˆ์งธ ๋น„๋””์˜ค์˜ ํฌ๊ธฐ๊ฐ€ ๊ธฐ์ค€์ด ๋ฉ๋‹ˆ๋‹ค
1055
+ - ๋‹ค๋ฅธ ํฌ๊ธฐ์˜ ๋น„๋””์˜ค๋Š” ์ฒซ ๋ฒˆ์งธ ๋น„๋””์˜ค ํฌ๊ธฐ๋กœ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค
1056
+ - ์ตœ์ƒ์˜ ๊ฒฐ๊ณผ๋ฅผ ์œ„ํ•ด ๊ฐ™์€ ํฌ๊ธฐ์˜ ๋น„๋””์˜ค๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”
1057
  """)
1058
 
1059
  merge_videos_btn = gr.Button("๐ŸŽฌ ๋น„๋””์˜ค ๋ณ‘ํ•ฉ", variant="primary", elem_id="merge-btn")
 
1074
  4. '๋น„๋””์˜ค ๋ณ‘ํ•ฉ' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š”
1075
 
1076
  **ํŠน์ง•**:
1077
+ - โœ… ์ฒซ ๋ฒˆ์งธ ๋น„๋””์˜ค์˜ ํฌ๊ธฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ†ตํ•ฉ
1078
  - โœ… ์—…๋กœ๋“œํ•œ ์˜ค๋””์˜ค๊ฐ€ ์ „์ฒด ๋น„๋””์˜ค์— ์ ์šฉ๋ฉ๋‹ˆ๋‹ค
1079
+ - โœ… ๋†’์€ ๋น„ํŠธ๋ ˆ์ดํŠธ๋กœ ํ’ˆ์งˆ ์œ ์ง€
1080
 
1081
  **ํŒ**:
1082
  - ํŒŒ์ผ๋ช…์„ 01.mp4, 02.mp4, 03.mp4 ํ˜•์‹์œผ๋กœ ์ง€์ •ํ•˜๋ฉด ์ˆœ์„œ ๊ด€๋ฆฌ๊ฐ€ ์‰ฝ์Šต๋‹ˆ๋‹ค