Tim13ekd commited on
Commit
27e5085
·
verified ·
1 Parent(s): cd88d93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -1,15 +1,23 @@
1
  from fastapi import FastAPI, UploadFile, File
2
  from fastapi.responses import FileResponse
 
3
  import subprocess
4
  import uuid
5
  import os
6
 
7
  app = FastAPI()
8
 
 
9
  @app.get("/")
10
  def health():
11
  return {"status": "ok", "ffmpeg": True}
12
 
 
 
 
 
 
 
13
  @app.post("/trim")
14
  async def trim(
15
  file: UploadFile = File(...),
@@ -19,9 +27,11 @@ async def trim(
19
  input_path = f"/tmp/{uuid.uuid4()}_in.mp4"
20
  output_path = f"/tmp/{uuid.uuid4()}_out.mp4"
21
 
 
22
  with open(input_path, "wb") as f:
23
  f.write(await file.read())
24
 
 
25
  cmd = [
26
  "ffmpeg", "-y",
27
  "-ss", str(start),
@@ -30,9 +40,9 @@ async def trim(
30
  "-c", "copy",
31
  output_path
32
  ]
33
-
34
  subprocess.run(cmd, check=True)
35
 
 
36
  return FileResponse(
37
  output_path,
38
  media_type="video/mp4",
 
1
  from fastapi import FastAPI, UploadFile, File
2
  from fastapi.responses import FileResponse
3
+ from fastapi.openapi.docs import get_swagger_ui_html
4
  import subprocess
5
  import uuid
6
  import os
7
 
8
  app = FastAPI()
9
 
10
+ # -------- Healthcheck Endpoint --------
11
  @app.get("/")
12
  def health():
13
  return {"status": "ok", "ffmpeg": True}
14
 
15
+ # -------- Custom Swagger /docs --------
16
+ @app.get("/docs", include_in_schema=False)
17
+ def custom_swagger():
18
+ return get_swagger_ui_html(openapi_url="/openapi.json", title="FFmpeg API Docs")
19
+
20
+ # -------- Trim Video Endpoint --------
21
  @app.post("/trim")
22
  async def trim(
23
  file: UploadFile = File(...),
 
27
  input_path = f"/tmp/{uuid.uuid4()}_in.mp4"
28
  output_path = f"/tmp/{uuid.uuid4()}_out.mp4"
29
 
30
+ # Upload speichern
31
  with open(input_path, "wb") as f:
32
  f.write(await file.read())
33
 
34
+ # FFmpeg Befehl ausführen
35
  cmd = [
36
  "ffmpeg", "-y",
37
  "-ss", str(start),
 
40
  "-c", "copy",
41
  output_path
42
  ]
 
43
  subprocess.run(cmd, check=True)
44
 
45
+ # Output zurückgeben
46
  return FileResponse(
47
  output_path,
48
  media_type="video/mp4",