Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import subprocess
|
|
| 3 |
import uuid
|
| 4 |
from fastapi import FastAPI, UploadFile, File, Header
|
| 5 |
from fastapi.responses import FileResponse
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
API_KEY = "MySecretWatermarkKey123"
|
|
@@ -16,12 +17,11 @@ async def add_watermark(file: UploadFile = File(...), watermark_text: str = "@Yo
|
|
| 16 |
|
| 17 |
with open(input_path, "wb") as buffer: buffer.write(await file.read())
|
| 18 |
|
| 19 |
-
# শক্তিশালী কমান্ড: ভিডিও কোয়ালিটি এবং থাম্বনেইল ঠিক রাখবে
|
| 20 |
cmd = [
|
| 21 |
"ffmpeg", "-i", input_path,
|
| 22 |
"-vf", f"drawtext=text='{watermark_text}':x=w-tw-20:y=h-th-20:fontsize=30:fontcolor=white@0.6",
|
| 23 |
"-c:v", "libx264", "-profile:v", "main", "-pix_fmt", "yuv420p",
|
| 24 |
-
"-preset", "ultrafast", "-c:a", "copy",
|
| 25 |
output_path
|
| 26 |
]
|
| 27 |
|
|
@@ -29,4 +29,9 @@ async def add_watermark(file: UploadFile = File(...), watermark_text: str = "@Yo
|
|
| 29 |
subprocess.run(cmd, check=True)
|
| 30 |
return FileResponse(output_path, media_type="video/mp4")
|
| 31 |
finally:
|
| 32 |
-
if os.path.exists(input_path): os.remove(input_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import uuid
|
| 4 |
from fastapi import FastAPI, UploadFile, File, Header
|
| 5 |
from fastapi.responses import FileResponse
|
| 6 |
+
import uvicorn
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
API_KEY = "MySecretWatermarkKey123"
|
|
|
|
| 17 |
|
| 18 |
with open(input_path, "wb") as buffer: buffer.write(await file.read())
|
| 19 |
|
|
|
|
| 20 |
cmd = [
|
| 21 |
"ffmpeg", "-i", input_path,
|
| 22 |
"-vf", f"drawtext=text='{watermark_text}':x=w-tw-20:y=h-th-20:fontsize=30:fontcolor=white@0.6",
|
| 23 |
"-c:v", "libx264", "-profile:v", "main", "-pix_fmt", "yuv420p",
|
| 24 |
+
"-preset", "ultrafast", "-c:a", "copy",
|
| 25 |
output_path
|
| 26 |
]
|
| 27 |
|
|
|
|
| 29 |
subprocess.run(cmd, check=True)
|
| 30 |
return FileResponse(output_path, media_type="video/mp4")
|
| 31 |
finally:
|
| 32 |
+
if os.path.exists(input_path): os.remove(input_path)
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
# Hugging Face এ পোর্ট ৭৯৬০ বা এনভায়রনমেন্ট পোর্ট ব্যবহার করা ভালো
|
| 36 |
+
port = int(os.environ.get("PORT", 7860))
|
| 37 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|