BoxOfColors commited on
Commit
34affeb
·
1 Parent(s): 8429f30

transcode_for_browser: write H.264 into same upload dir so Gradio file server allows it

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -175,14 +175,13 @@ def _transcode_for_browser(video_path: str) -> str:
175
  if video_streams and video_streams[0].get("codec_name") == "h264":
176
  print(f"[transcode_for_browser] already H.264, skipping")
177
  return video_path
178
- # Write to a fresh gradio-served temp dir so Gradio re-probes from scratch
179
- # and never sees the H.265 source for this returned value.
180
- import hashlib as _hashlib, os as _os
181
- basename = _os.path.basename(video_path)
182
- tag = _hashlib.sha256((video_path + "_h264").encode()).hexdigest()
183
- out_dir = f"/tmp/gradio/{tag}"
184
- _os.makedirs(out_dir, exist_ok=True)
185
- out_path = _os.path.join(out_dir, basename)
186
  kwargs = dict(
187
  vcodec="libx264", preset="fast", crf=18,
188
  pix_fmt="yuv420p", movflags="+faststart",
 
175
  if video_streams and video_streams[0].get("codec_name") == "h264":
176
  print(f"[transcode_for_browser] already H.264, skipping")
177
  return video_path
178
+ # Write the H.264 output into the SAME directory as the original upload.
179
+ # Gradio's file server only allows paths under dirs it registered — the
180
+ # upload dir is already allowed, so a sibling file there will serve fine.
181
+ import os as _os
182
+ upload_dir = _os.path.dirname(video_path)
183
+ stem = _os.path.splitext(_os.path.basename(video_path))[0]
184
+ out_path = _os.path.join(upload_dir, stem + "_h264.mp4")
 
185
  kwargs = dict(
186
  vcodec="libx264", preset="fast", crf=18,
187
  pix_fmt="yuv420p", movflags="+faststart",