profile level指定及修复

This commit is contained in:
Jerry Yan 2025-02-27 15:36:53 +08:00
parent 67696739f9
commit fff20610a5
2 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,9 @@
import time
import uuid
ENCODER_ARGS = ("-c:v", "h264_qsv", "-global_quality", "28", "-look_ahead", "1",)
PROFILE_LEVEL_ARGS = ("-profile:v", "high", "-level:v", "4")
class FfmpegTask(object):
@ -136,13 +139,14 @@ class FfmpegTask(object):
def get_ffmpeg_args(self):
args = ['-y', '-hide_banner']
if self.task_type == 'encode':
# args += ('-hwaccel', 'qsv', '-hwaccel_output_format', 'qsv')
input_args = []
filter_args = []
output_args = ["-shortest", "-c:v", "h264_qsv", "-global_quality", "28", "-look_ahead", "1"]
output_args = ["-profile", "high", "-level", "4","-shortest", *ENCODER_ARGS]
if self.annexb:
output_args.append("-bsf:v")
output_args.append("h264_mp4toannexb")
output_args.append("-reset_timestamps")
output_args.append("1")
video_output_str = "[0:v]"
audio_output_str = "[0:v]"
audio_input_count = 0
@ -219,7 +223,7 @@ class FfmpegTask(object):
output_args.append("-f")
output_args.append("mp4")
return args + input_args + output_args + [self.get_output_file()]
output_args += ("-c:v", "h264_qsv", "-r", "25", "-global_quality", "28", "-look_ahead", "1")
output_args += ["-r", f"{self.frame_rate}", *PROFILE_LEVEL_ARGS, *ENCODER_ARGS]
filter_args = []
video_output_str = "[0:v]"
audio_output_str = "[0:a]"

View File

@ -4,7 +4,7 @@ import subprocess
from datetime import datetime
from typing import Optional, IO
from entity.ffmpeg import FfmpegTask
from entity.ffmpeg import FfmpegTask, ENCODER_ARGS, PROFILE_LEVEL_ARGS
logger = logging.getLogger(__name__)
@ -25,7 +25,7 @@ def re_encode_and_annexb(file):
if not os.path.exists(file):
return file
logger.info("ReEncodeAndAnnexb: %s", file)
ffmpeg_process = subprocess.run(["ffmpeg", "-y", "-hide_banner", "-i", file, "-c:v", "h264_qsv", "-global_quality", "28", "-look_ahead", "1", "-bsf:v", "h264_mp4toannexb",
ffmpeg_process = subprocess.run(["ffmpeg", "-y", "-hide_banner", "-i", file, *PROFILE_LEVEL_ARGS, *ENCODER_ARGS, "-bsf:v", "h264_mp4toannexb",
"-f", "mpegts", file +".ts"])
logger.info("ReEncodeAndAnnexb: %s, returned: %s", file, ffmpeg_process.returncode)
if ffmpeg_process.returncode == 0: