Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,24 +61,27 @@ def process_video_task(url: str, cookie: Optional[str], task_id: str):
|
|
| 61 |
for chunk in r.iter_bytes(chunk_size=8192):
|
| 62 |
f.write(chunk)
|
| 63 |
|
| 64 |
-
# 2. Update DB:
|
| 65 |
db.execute("UPDATE jobs SET status = 'encoding' WHERE task_id = ?", (task_id,))
|
| 66 |
db.commit()
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
(
|
| 69 |
ffmpeg
|
| 70 |
.input(temp_in_path)
|
| 71 |
-
.output(temp_out_path,
|
| 72 |
.run(capture_stdout=True, capture_stderr=True)
|
| 73 |
)
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
# β
β
β
FIX: Get duration using ffprobe β
β
β
|
| 77 |
-
#
|
| 78 |
probe = ffmpeg.probe(temp_out_path)
|
| 79 |
duration = int(float(probe['format']['duration'])) # Get duration in seconds
|
| 80 |
|
| 81 |
-
#
|
| 82 |
final_file_name = f"{task_id}_out.mp4"
|
| 83 |
db.execute(
|
| 84 |
"UPDATE jobs SET status = 'complete', file_name = ?, duration = ? WHERE task_id = ?",
|
|
|
|
| 61 |
for chunk in r.iter_bytes(chunk_size=8192):
|
| 62 |
f.write(chunk)
|
| 63 |
|
| 64 |
+
# 2. Update DB: "Fixing" (not encoding)
|
| 65 |
db.execute("UPDATE jobs SET status = 'encoding' WHERE task_id = ?", (task_id,))
|
| 66 |
db.commit()
|
| 67 |
|
| 68 |
+
#
|
| 69 |
+
# β
β
β
THE FIX IS HERE β
β
β
|
| 70 |
+
# We changed this from vcodec='libx264' to 'c=copy'
|
| 71 |
+
# This is the FAST (0% CPU) "re-package"
|
| 72 |
+
#
|
| 73 |
(
|
| 74 |
ffmpeg
|
| 75 |
.input(temp_in_path)
|
| 76 |
+
.output(temp_out_path, c='copy', movflags='+faststart') # <-- CHANGED
|
| 77 |
.run(capture_stdout=True, capture_stderr=True)
|
| 78 |
)
|
| 79 |
|
| 80 |
+
# 3. Get duration using ffprobe
|
|
|
|
|
|
|
| 81 |
probe = ffmpeg.probe(temp_out_path)
|
| 82 |
duration = int(float(probe['format']['duration'])) # Get duration in seconds
|
| 83 |
|
| 84 |
+
# 4. Update DB: Complete
|
| 85 |
final_file_name = f"{task_id}_out.mp4"
|
| 86 |
db.execute(
|
| 87 |
"UPDATE jobs SET status = 'complete', file_name = ?, duration = ? WHERE task_id = ?",
|