Update app.py
Browse files
app.py
CHANGED
|
@@ -445,10 +445,56 @@ def ffmpeg_resize_video(input_path, output_path, target_ratio):
|
|
| 445 |
else:
|
| 446 |
filter_complex = "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black"
|
| 447 |
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
print(f"执行FFmpeg调整命令: {' '.join(command)}") # 调试输出
|
| 454 |
|
|
@@ -467,9 +513,18 @@ def ffmpeg_resize_video(input_path, output_path, target_ratio):
|
|
| 467 |
HARDWARE_ACCEL['encoder'] = 'libx264'
|
| 468 |
|
| 469 |
# 重新构建命令,使用软件编码
|
| 470 |
-
command =
|
| 471 |
-
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
|
| 474 |
print(f"重试FFmpeg调整命令(软件编码): {' '.join(command)}")
|
| 475 |
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
|
|
| 445 |
else:
|
| 446 |
filter_complex = "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:black"
|
| 447 |
|
| 448 |
+
# 重新构建命令,确保参数顺序正确
|
| 449 |
+
command = [
|
| 450 |
+
'ffmpeg', '-threads', str(get_optimal_threads()),
|
| 451 |
+
'-i', input_path,
|
| 452 |
+
'-vf', filter_complex
|
| 453 |
+
]
|
| 454 |
+
|
| 455 |
+
# 添加编码参数
|
| 456 |
+
if HARDWARE_ACCEL['working']:
|
| 457 |
+
# 硬件编码参数
|
| 458 |
+
if HARDWARE_ACCEL['encoder'] == 'h264_nvenc':
|
| 459 |
+
command.extend([
|
| 460 |
+
'-c:v', 'h264_nvenc',
|
| 461 |
+
'-preset', 'fast',
|
| 462 |
+
'-cq', '28',
|
| 463 |
+
'-c:a', 'copy',
|
| 464 |
+
'-movflags', '+faststart',
|
| 465 |
+
'-y', output_path
|
| 466 |
+
])
|
| 467 |
+
elif HARDWARE_ACCEL['encoder'] == 'h264_amf':
|
| 468 |
+
command.extend([
|
| 469 |
+
'-c:v', 'h264_amf',
|
| 470 |
+
'-quality', 'speed',
|
| 471 |
+
'-rc', 'cqp',
|
| 472 |
+
'-cqp_i', '28',
|
| 473 |
+
'-cqp_p', '28',
|
| 474 |
+
'-c:a', 'copy',
|
| 475 |
+
'-movflags', '+faststart',
|
| 476 |
+
'-y', output_path
|
| 477 |
+
])
|
| 478 |
+
elif HARDWARE_ACCEL['encoder'] == 'h264_qsv':
|
| 479 |
+
command.extend([
|
| 480 |
+
'-c:v', 'h264_qsv',
|
| 481 |
+
'-preset', 'veryfast',
|
| 482 |
+
'-global_quality', '28',
|
| 483 |
+
'-c:a', 'copy',
|
| 484 |
+
'-movflags', '+faststart',
|
| 485 |
+
'-y', output_path
|
| 486 |
+
])
|
| 487 |
+
else:
|
| 488 |
+
# 软件编码参数
|
| 489 |
+
command.extend([
|
| 490 |
+
'-c:v', 'libx264',
|
| 491 |
+
'-preset', 'ultrafast',
|
| 492 |
+
'-crf', '28',
|
| 493 |
+
'-tune', 'fastdecode',
|
| 494 |
+
'-c:a', 'copy',
|
| 495 |
+
'-movflags', '+faststart',
|
| 496 |
+
'-y', output_path
|
| 497 |
+
])
|
| 498 |
|
| 499 |
print(f"执行FFmpeg调整命令: {' '.join(command)}") # 调试输出
|
| 500 |
|
|
|
|
| 513 |
HARDWARE_ACCEL['encoder'] = 'libx264'
|
| 514 |
|
| 515 |
# 重新构建命令,使用软件编码
|
| 516 |
+
command = [
|
| 517 |
+
'ffmpeg', '-threads', str(get_optimal_threads()),
|
| 518 |
+
'-i', input_path,
|
| 519 |
+
'-vf', filter_complex,
|
| 520 |
+
'-c:v', 'libx264',
|
| 521 |
+
'-preset', 'ultrafast',
|
| 522 |
+
'-crf', '28',
|
| 523 |
+
'-tune', 'fastdecode',
|
| 524 |
+
'-c:a', 'copy',
|
| 525 |
+
'-movflags', '+faststart',
|
| 526 |
+
'-y', output_path
|
| 527 |
+
]
|
| 528 |
|
| 529 |
print(f"重试FFmpeg调整命令(软件编码): {' '.join(command)}")
|
| 530 |
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|