Update app.py
Browse files
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 |
-
|
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 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
|
649 |
-
#
|
650 |
-
|
651 |
|
652 |
-
# ๋ชจ๋
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
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(
|
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 |
-
|
767 |
-
clip
|
768 |
-
|
769 |
-
|
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)}๊ฐ์ ๋น๋์ค๋ฅผ ๋ณํฉํ์ต๋๋ค! (ํฌ๊ธฐ: {
|
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 ํ์์ผ๋ก ์ง์ ํ๋ฉด ์์ ๊ด๋ฆฌ๊ฐ ์ฝ์ต๋๋ค
|