robertusdanan commited on
Commit
4d556fd
·
verified ·
1 Parent(s): a5e98ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  import os, json, subprocess, textwrap, uuid
3
  import spaces
4
 
5
- # Ubah angka durasi pemesanannya menjadi 60 detik
6
  @spaces.GPU(duration=60)
7
  def render_video(video_file, srt_file, thumb_file, hermes_json, allowed_crop):
8
  try:
@@ -47,13 +46,15 @@ def render_video(video_file, srt_file, thumb_file, hermes_json, allowed_crop):
47
  words = text.split()
48
  dur_sub = ne - ns
49
  if dur_sub > 0 and (len(words) / dur_sub) > 6.0: continue
50
- max_w = 4
 
 
51
  chunks = [" ".join(words[j:j+max_w]) for j in range(0, len(words), max_w)]
52
  if not chunks: continue
53
  c_dur = (ne_adj - ns_adj) / len(chunks)
54
  for k, c_txt in enumerate(chunks):
55
  c_st, c_en = ns_adj + k * c_dur, ns_adj + (k+1) * c_dur
56
- wrp = textwrap.fill(c_txt, width=22)
57
  new_srt.append(f"{srt_idx}\n{ft(c_st)} --> {ft(c_en)}\n{wrp}")
58
  srt_idx += 1
59
  run_t += dur
@@ -64,20 +65,18 @@ def render_video(video_file, srt_file, thumb_file, hermes_json, allowed_crop):
64
 
65
  crop_filter = "crop=iw-200:ih:100:0," if allowed_crop == "true" else ""
66
 
67
- # OPTIMASI 1: boxblur dikurangi dari 20:5 menjadi 10:2. (Sangat menghemat tenaga CPU)
68
- # OPTIMASI 2: MarginV tetap 260 agar subtitle presisi di bawah gameplay.
69
  full_filter = filt_str + f"""[raw_vid]split[raw_bg][raw_fg];
70
  [raw_bg]{crop_filter}scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,boxblur=10:2,setsar=1,fps=30[bg];
71
  [raw_fg]{crop_filter}scale=1080:1920:force_original_aspect_ratio=decrease,setsar=1,fps=30[fg];
72
  [bg][fg]overlay=(W-w)/2:(H-h)/2[mainvid];
73
  [1:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1,fps=30[thumbv];
74
- [thumbv][mainvid]concat=n=2:v=1:a=0,subtitles={clip_srt_path}:force_style='Fontsize=15,Bold=1,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=2.5,Shadow=1,Alignment=8,MarginV=260'[withsubs];
75
  [2:a][raw_aud]concat=n=2:v=0:a=1[outa]"""
76
 
77
  ff_txt = f"{wrk}/full_filter.txt"
78
  open(ff_txt, "w").write(full_filter)
79
 
80
- # OPTIMASI 3: Preset diubah menjadi 'ultrafast'. (Kecepatan render meningkat drastis)
81
  subprocess.run([
82
  "ffmpeg", "-y", "-i", video_file,
83
  "-loop", "1", "-t", "1.5", "-i", thumb_file,
 
2
  import os, json, subprocess, textwrap, uuid
3
  import spaces
4
 
 
5
  @spaces.GPU(duration=60)
6
  def render_video(video_file, srt_file, thumb_file, hermes_json, allowed_crop):
7
  try:
 
46
  words = text.split()
47
  dur_sub = ne - ns
48
  if dur_sub > 0 and (len(words) / dur_sub) > 6.0: continue
49
+
50
+ # KONTROL PANJANG TEKS: Dibatasi maksimal 3 kata per baris agar tidak menumpuk
51
+ max_w = 3
52
  chunks = [" ".join(words[j:j+max_w]) for j in range(0, len(words), max_w)]
53
  if not chunks: continue
54
  c_dur = (ne_adj - ns_adj) / len(chunks)
55
  for k, c_txt in enumerate(chunks):
56
  c_st, c_en = ns_adj + k * c_dur, ns_adj + (k+1) * c_dur
57
+ wrp = textwrap.fill(c_txt, width=18)
58
  new_srt.append(f"{srt_idx}\n{ft(c_st)} --> {ft(c_en)}\n{wrp}")
59
  srt_idx += 1
60
  run_t += dur
 
65
 
66
  crop_filter = "crop=iw-200:ih:100:0," if allowed_crop == "true" else ""
67
 
68
+ # Posisi MarginV=260 dan boxblur dioptimalkan agar ringan & presisi
 
69
  full_filter = filt_str + f"""[raw_vid]split[raw_bg][raw_fg];
70
  [raw_bg]{crop_filter}scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,boxblur=10:2,setsar=1,fps=30[bg];
71
  [raw_fg]{crop_filter}scale=1080:1920:force_original_aspect_ratio=decrease,setsar=1,fps=30[fg];
72
  [bg][fg]overlay=(W-w)/2:(H-h)/2[mainvid];
73
  [1:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1,fps=30[thumbv];
74
+ [thumbv][mainvid]concat=n=2:v=1:a=0,subtitles={clip_srt_path}:force_style='Fontsize=15,Bold=1,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=2.5,Shadow=1,Alignment=10,MarginV=260'[withsubs];
75
  [2:a][raw_aud]concat=n=2:v=0:a=1[outa]"""
76
 
77
  ff_txt = f"{wrk}/full_filter.txt"
78
  open(ff_txt, "w").write(full_filter)
79
 
 
80
  subprocess.run([
81
  "ffmpeg", "-y", "-i", video_file,
82
  "-loop", "1", "-t", "1.5", "-i", thumb_file,