抽象视频输出设置
This commit is contained in:
parent
52317ca39b
commit
25d0ad097e
@ -4,6 +4,7 @@ import platform
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import traceback
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from typing import Optional, IO, Union
|
from typing import Optional, IO, Union
|
||||||
|
|
||||||
@ -292,13 +293,18 @@ class WorkerThread(QThread):
|
|||||||
return duration_str_to_float(_duration_str)
|
return duration_str_to_float(_duration_str)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self.label.start_running()
|
try:
|
||||||
job = self.label.get_job()
|
self.label.start_running()
|
||||||
if job.type == Job.DANMAKU_ENCODE:
|
job = self.label.get_job()
|
||||||
self.run_danmaku_encode(job)
|
if job.type == Job.DANMAKU_ENCODE:
|
||||||
elif job.type == Job.PURE_SPLIT:
|
self.run_danmaku_encode(job)
|
||||||
self.quick_split_video(job.video)
|
elif job.type == Job.PURE_SPLIT:
|
||||||
self.label.stop_running()
|
self.quick_split_video(job.video)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
print(traceback.format_exc())
|
||||||
|
finally:
|
||||||
|
self.label.stop_running()
|
||||||
|
|
||||||
def run_danmaku_encode(self, job: Job):
|
def run_danmaku_encode(self, job: Job):
|
||||||
base_danmaku = job.danmaku.pop(0)
|
base_danmaku = job.danmaku.pop(0)
|
||||||
@ -323,6 +329,9 @@ class WorkerThread(QThread):
|
|||||||
for _f in job.subtitles:
|
for _f in job.subtitles:
|
||||||
if os.path.isfile(_f):
|
if os.path.isfile(_f):
|
||||||
os.remove(_f)
|
os.remove(_f)
|
||||||
|
for _f in split_files:
|
||||||
|
if os.path.isfile(_f):
|
||||||
|
os.remove(_f)
|
||||||
|
|
||||||
def encode_video_with_subtitles(self, orig_filename: str, subtitles: list[str], new_filename: str):
|
def encode_video_with_subtitles(self, orig_filename: str, subtitles: list[str], new_filename: str):
|
||||||
if FFMPEG_USE_NVIDIA_GPU:
|
if FFMPEG_USE_NVIDIA_GPU:
|
||||||
@ -347,10 +356,8 @@ class WorkerThread(QThread):
|
|||||||
"-hwaccel", "qsv", "-i", orig_filename, "-vf",
|
"-hwaccel", "qsv", "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles),
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
"-c:a", "copy", "-c:v", "h264_qsv",
|
"-c:a", "copy", "-c:v", "h264_qsv",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
|
||||||
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename
|
new_filename
|
||||||
], **subprocess_args(True))
|
], **subprocess_args(True))
|
||||||
@ -361,10 +368,8 @@ class WorkerThread(QThread):
|
|||||||
"-hwaccel", "vaapi", "-i", orig_filename, "-vf",
|
"-hwaccel", "vaapi", "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload",
|
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload",
|
||||||
"-c:a", "copy", "-c:v", "h264_vaapi",
|
"-c:a", "copy", "-c:v", "h264_vaapi",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
|
||||||
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename
|
new_filename
|
||||||
], **subprocess_args(True))
|
], **subprocess_args(True))
|
||||||
@ -375,10 +380,8 @@ class WorkerThread(QThread):
|
|||||||
"-i", orig_filename, "-vf",
|
"-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles),
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
"-c:a", "copy", "-c:v", "h264",
|
"-c:a", "copy", "-c:v", "h264",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr",
|
*_common_ffmpeg_params(),
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
|
||||||
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename
|
new_filename
|
||||||
], **subprocess_args(True))
|
], **subprocess_args(True))
|
||||||
@ -392,8 +395,7 @@ class WorkerThread(QThread):
|
|||||||
print("[!]Not Enabled Both GPU")
|
print("[!]Not Enabled Both GPU")
|
||||||
self.encode_video_with_subtitles(orig_filename, subtitles, new_fullpath)
|
self.encode_video_with_subtitles(orig_filename, subtitles, new_fullpath)
|
||||||
return [new_fullpath]
|
return [new_fullpath]
|
||||||
_duration_str = self.get_video_real_duration(orig_filename)
|
duration = self.get_video_real_duration(orig_filename)
|
||||||
duration = duration_str_to_float(_duration_str)
|
|
||||||
if duration > (VIDEO_CLIP_EACH_SEC * 5):
|
if duration > (VIDEO_CLIP_EACH_SEC * 5):
|
||||||
# qsv 压制前2段,剩余交由nvenc压制
|
# qsv 压制前2段,剩余交由nvenc压制
|
||||||
_slices = int(duration / VIDEO_CLIP_EACH_SEC)
|
_slices = int(duration / VIDEO_CLIP_EACH_SEC)
|
||||||
@ -407,6 +409,7 @@ class WorkerThread(QThread):
|
|||||||
"-hwaccel", "qsv", "-ss", str((_slices - 1) * VIDEO_CLIP_EACH_SEC),
|
"-hwaccel", "qsv", "-ss", str((_slices - 1) * VIDEO_CLIP_EACH_SEC),
|
||||||
"-copyts", "-i", orig_filename, "-vf",
|
"-copyts", "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles),
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
|
"-ss", str((_slices - 1) * VIDEO_CLIP_EACH_SEC),
|
||||||
"-c:a", "copy", "-c:v", "h264_qsv",
|
"-c:a", "copy", "-c:v", "h264_qsv",
|
||||||
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
*_common_ffmpeg_params(),
|
*_common_ffmpeg_params(),
|
||||||
@ -425,6 +428,8 @@ class WorkerThread(QThread):
|
|||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_fullpath1
|
new_fullpath1
|
||||||
], **subprocess_args(True))
|
], **subprocess_args(True))
|
||||||
|
threading.Thread(target=self.handle_ffmpeg_output, args=(encode_process0.stdout, True,)).start()
|
||||||
|
threading.Thread(target=self.handle_ffmpeg_output, args=(encode_process1.stdout,)).start()
|
||||||
encode_process0.wait()
|
encode_process0.wait()
|
||||||
encode_process1.wait()
|
encode_process1.wait()
|
||||||
return [new_filename0, new_filename1]
|
return [new_filename0, new_filename1]
|
||||||
@ -441,6 +446,7 @@ class WorkerThread(QThread):
|
|||||||
"-hwaccel", "qsv", "-ss", str(_slices * VIDEO_CLIP_EACH_SEC),
|
"-hwaccel", "qsv", "-ss", str(_slices * VIDEO_CLIP_EACH_SEC),
|
||||||
"-copyts", "-i", orig_filename, "-vf",
|
"-copyts", "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles),
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
|
"-ss", str(_slices * VIDEO_CLIP_EACH_SEC),
|
||||||
"-c:a", "copy", "-c:v", "h264_qsv",
|
"-c:a", "copy", "-c:v", "h264_qsv",
|
||||||
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
*_common_ffmpeg_params(),
|
*_common_ffmpeg_params(),
|
||||||
@ -459,6 +465,8 @@ class WorkerThread(QThread):
|
|||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_fullpath1
|
new_fullpath1
|
||||||
], **subprocess_args(True))
|
], **subprocess_args(True))
|
||||||
|
threading.Thread(target=self.handle_ffmpeg_output, args=(encode_process0.stdout, True,)).start()
|
||||||
|
threading.Thread(target=self.handle_ffmpeg_output, args=(encode_process1.stdout,)).start()
|
||||||
encode_process1.wait()
|
encode_process1.wait()
|
||||||
encode_process0.wait()
|
encode_process0.wait()
|
||||||
return [new_filename1]
|
return [new_filename1]
|
||||||
@ -492,6 +500,7 @@ class WorkerThread(QThread):
|
|||||||
"{}.mp4".format(current_dt)
|
"{}.mp4".format(current_dt)
|
||||||
], **subprocess_args(True))
|
], **subprocess_args(True))
|
||||||
self.handle_ffmpeg_output(split_process.stdout)
|
self.handle_ffmpeg_output(split_process.stdout)
|
||||||
|
split_process.wait()
|
||||||
current_sec += VIDEO_CLIP_EACH_SEC
|
current_sec += VIDEO_CLIP_EACH_SEC
|
||||||
|
|
||||||
def handle_ffmpeg_output(self, stdout: Optional[IO[bytes]], second=False) -> str:
|
def handle_ffmpeg_output(self, stdout: Optional[IO[bytes]], second=False) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user