BoxOfColors commited on
Commit
db26e7f
·
1 Parent(s): ba77b8a

Fix: replace custom transcode with gr.Video format=mp4; remove upload handler

Browse files
Files changed (1) hide show
  1. app.py +3 -40
app.py CHANGED
@@ -156,36 +156,6 @@ def strip_audio_from_video(video_path: str, output_path: str) -> None:
156
  overwrite_output=True, quiet=True
157
  )
158
 
159
- def _transcode_for_browser(video_path: str) -> str:
160
- """Re-encode *video_path* to H.264 baseline + AAC so all browsers can preview it.
161
-
162
- Returns the path to the transcoded file (written alongside the original).
163
- Falls back to returning the original path if transcoding fails.
164
- """
165
- if video_path is None:
166
- return video_path
167
- try:
168
- # Probe to check if audio stream exists
169
- probe = ffmpeg.probe(video_path)
170
- has_audio = any(s["codec_type"] == "audio" for s in probe.get("streams", []))
171
- out_path = video_path.rsplit(".", 1)[0] + "_browser.mp4"
172
- stream = ffmpeg.input(video_path)
173
- output_kwargs = dict(
174
- vcodec="libx264", preset="fast", crf=18,
175
- profile="baseline", level="3.0",
176
- pix_fmt="yuv420p",
177
- movflags="+faststart",
178
- )
179
- if has_audio:
180
- output_kwargs["acodec"] = "aac"
181
- output_kwargs["audio_bitrate"] = "128k"
182
- else:
183
- output_kwargs["an"] = None # no audio track
184
- stream.output(out_path, **output_kwargs).run(overwrite_output=True, quiet=True)
185
- return out_path
186
- except Exception as e:
187
- print(f"[transcode_for_browser] failed, using original: {e}")
188
- return video_path
189
 
190
  # ------------------------------------------------------------------ #
191
  # Temp directory registry — tracks dirs for cleanup on new generation #
@@ -2582,7 +2552,7 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
2582
  with gr.Tab("TARO"):
2583
  with gr.Row():
2584
  with gr.Column(scale=1):
2585
- taro_video = gr.Video(label="Input Video")
2586
  taro_seed = gr.Number(label="Seed (-1 = random)", value=-1, precision=0, elem_id="taro_seed")
2587
  taro_cfg = gr.Slider(label="CFG Scale", minimum=1, maximum=15, value=8.0, step=0.5, elem_id="taro_cfg")
2588
  taro_steps = gr.Slider(label="Sampling Steps", minimum=10, maximum=50, value=25, step=1, elem_id="taro_steps")
@@ -2647,7 +2617,7 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
2647
  with gr.Tab("MMAudio"):
2648
  with gr.Row():
2649
  with gr.Column(scale=1):
2650
- mma_video = gr.Video(label="Input Video")
2651
  mma_prompt = gr.Textbox(label="Prompt", placeholder="e.g. footsteps on gravel", elem_id="mma_prompt")
2652
  mma_neg = gr.Textbox(label="Negative Prompt", value="music", placeholder="music, speech", elem_id="mma_neg")
2653
  mma_seed = gr.Number(label="Seed (-1 = random)", value=-1, precision=0, elem_id="mma_seed")
@@ -2701,7 +2671,7 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
2701
  with gr.Tab("HunyuanFoley"):
2702
  with gr.Row():
2703
  with gr.Column(scale=1):
2704
- hf_video = gr.Video(label="Input Video")
2705
  hf_prompt = gr.Textbox(label="Prompt", placeholder="e.g. rain hitting a metal roof", elem_id="hf_prompt")
2706
  hf_neg = gr.Textbox(label="Negative Prompt", value="noisy, harsh", elem_id="hf_neg")
2707
  hf_seed = gr.Number(label="Seed (-1 = random)", value=-1, precision=0, elem_id="hf_seed")
@@ -2750,13 +2720,6 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
2750
  hf_slot_vids, hf_slot_waves,
2751
  )
2752
 
2753
- # ---- Browser-safe transcode on upload ----
2754
- # Re-encodes uploaded video to H.264 baseline so all browsers can preview it.
2755
- # Each tab transcodes independently; cross-tab sync propagates the result.
2756
- taro_video.upload(fn=_transcode_for_browser, inputs=[taro_video], outputs=[taro_video])
2757
- mma_video.upload(fn=_transcode_for_browser, inputs=[mma_video], outputs=[mma_video])
2758
- hf_video.upload(fn=_transcode_for_browser, inputs=[hf_video], outputs=[hf_video])
2759
-
2760
  # ---- Cross-tab video sync ----
2761
  _sync = lambda v: (gr.update(value=v), gr.update(value=v))
2762
  taro_video.change(fn=_sync, inputs=[taro_video], outputs=[mma_video, hf_video])
 
156
  overwrite_output=True, quiet=True
157
  )
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  # ------------------------------------------------------------------ #
161
  # Temp directory registry — tracks dirs for cleanup on new generation #
 
2552
  with gr.Tab("TARO"):
2553
  with gr.Row():
2554
  with gr.Column(scale=1):
2555
+ taro_video = gr.Video(label="Input Video", format="mp4")
2556
  taro_seed = gr.Number(label="Seed (-1 = random)", value=-1, precision=0, elem_id="taro_seed")
2557
  taro_cfg = gr.Slider(label="CFG Scale", minimum=1, maximum=15, value=8.0, step=0.5, elem_id="taro_cfg")
2558
  taro_steps = gr.Slider(label="Sampling Steps", minimum=10, maximum=50, value=25, step=1, elem_id="taro_steps")
 
2617
  with gr.Tab("MMAudio"):
2618
  with gr.Row():
2619
  with gr.Column(scale=1):
2620
+ mma_video = gr.Video(label="Input Video", format="mp4")
2621
  mma_prompt = gr.Textbox(label="Prompt", placeholder="e.g. footsteps on gravel", elem_id="mma_prompt")
2622
  mma_neg = gr.Textbox(label="Negative Prompt", value="music", placeholder="music, speech", elem_id="mma_neg")
2623
  mma_seed = gr.Number(label="Seed (-1 = random)", value=-1, precision=0, elem_id="mma_seed")
 
2671
  with gr.Tab("HunyuanFoley"):
2672
  with gr.Row():
2673
  with gr.Column(scale=1):
2674
+ hf_video = gr.Video(label="Input Video", format="mp4")
2675
  hf_prompt = gr.Textbox(label="Prompt", placeholder="e.g. rain hitting a metal roof", elem_id="hf_prompt")
2676
  hf_neg = gr.Textbox(label="Negative Prompt", value="noisy, harsh", elem_id="hf_neg")
2677
  hf_seed = gr.Number(label="Seed (-1 = random)", value=-1, precision=0, elem_id="hf_seed")
 
2720
  hf_slot_vids, hf_slot_waves,
2721
  )
2722
 
 
 
 
 
 
 
 
2723
  # ---- Cross-tab video sync ----
2724
  _sync = lambda v: (gr.update(value=v), gr.update(value=v))
2725
  taro_video.change(fn=_sync, inputs=[taro_video], outputs=[mma_video, hf_video])