Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -297,23 +297,27 @@ def video_webm():
|
|
| 297 |
|
| 298 |
@app.route('/video/mp4')
|
| 299 |
def video_mp4():
|
| 300 |
-
"""MP4 streaming
|
| 301 |
cmd = [
|
| 302 |
'ffmpeg',
|
|
|
|
|
|
|
| 303 |
'-f', 'rawvideo',
|
| 304 |
'-pix_fmt', 'rgb24',
|
| 305 |
'-s', f'{VIDEO_WIDTH}x{VIDEO_HEIGHT}',
|
| 306 |
-
'-r',
|
| 307 |
'-i', '-',
|
| 308 |
-
'-c:v', '
|
| 309 |
-
'-preset', '
|
| 310 |
-
'-tune', '
|
| 311 |
'-b:v', '2M',
|
|
|
|
| 312 |
'-f', 'mp4',
|
| 313 |
'-movflags', 'frag_keyframe+empty_moov',
|
| 314 |
'-'
|
| 315 |
]
|
| 316 |
|
|
|
|
| 317 |
process = subprocess.Popen(
|
| 318 |
cmd,
|
| 319 |
stdin=subprocess.PIPE,
|
|
|
|
| 297 |
|
| 298 |
@app.route('/video/mp4')
|
| 299 |
def video_mp4():
|
| 300 |
+
"""GPU-accelerated MP4 streaming using NVENC"""
|
| 301 |
cmd = [
|
| 302 |
'ffmpeg',
|
| 303 |
+
'-hwaccel', 'cuda', # Use GPU for decoding
|
| 304 |
+
'-hwaccel_output_format', 'cuda', # Keep data on GPU
|
| 305 |
'-f', 'rawvideo',
|
| 306 |
'-pix_fmt', 'rgb24',
|
| 307 |
'-s', f'{VIDEO_WIDTH}x{VIDEO_HEIGHT}',
|
| 308 |
+
'-r', '30',
|
| 309 |
'-i', '-',
|
| 310 |
+
'-c:v', 'h264_nvenc', # NVIDIA's GPU encoder
|
| 311 |
+
'-preset', 'p4', # p1-p7, p4 is good balance
|
| 312 |
+
'-tune', 'll', # Low latency tuning
|
| 313 |
'-b:v', '2M',
|
| 314 |
+
'-bufsize', '4M',
|
| 315 |
'-f', 'mp4',
|
| 316 |
'-movflags', 'frag_keyframe+empty_moov',
|
| 317 |
'-'
|
| 318 |
]
|
| 319 |
|
| 320 |
+
|
| 321 |
process = subprocess.Popen(
|
| 322 |
cmd,
|
| 323 |
stdin=subprocess.PIPE,
|