Spaces:
Running on Zero
Running on Zero
Commit ·
34affeb
1
Parent(s): 8429f30
transcode_for_browser: write H.264 into same upload dir so Gradio file server allows it
Browse files
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
|
| 179 |
-
#
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
_os.
|
| 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",
|