Add video stream copy remuxing
This commit is contained in:
+14
-19
@@ -175,12 +175,12 @@ def ask_video_codec_options() -> VideoCodecOptions:
|
||||
extension = _prompt_container_extension()
|
||||
if codec is None:
|
||||
codec = _prompt_codec()
|
||||
if crf is None:
|
||||
if codec != "copy" and crf is None:
|
||||
default_crf = 16 if codec == "libx264" else 21
|
||||
crf = _prompt_int(f"CRF [{default_crf}]: ", default=default_crf)
|
||||
if not preset:
|
||||
if codec != "copy" and not preset:
|
||||
preset = _prompt_preset(default="slow")
|
||||
if "MBT_VIDEO_THREADS" not in os.environ:
|
||||
if codec != "copy" and "MBT_VIDEO_THREADS" not in os.environ:
|
||||
threads = _prompt_threads(default=None)
|
||||
else:
|
||||
extension = extension or ".mp4"
|
||||
@@ -190,8 +190,8 @@ def ask_video_codec_options() -> VideoCodecOptions:
|
||||
|
||||
return VideoCodecOptions(
|
||||
codec=codec,
|
||||
crf=crf,
|
||||
preset=preset,
|
||||
crf=crf if crf is not None else 21,
|
||||
preset=preset or "slow",
|
||||
extension=extension,
|
||||
profile=profile,
|
||||
level=level,
|
||||
@@ -249,7 +249,6 @@ def ask_audio_options(
|
||||
preserve_pitch = ask_audio_pitch_option(has_speed_changes=has_speed_changes)
|
||||
if env_mode:
|
||||
mode = _normalize_audio_mode(env_mode)
|
||||
_validate_audio_container(mode, container_extension)
|
||||
return AudioEncodeOptions(
|
||||
mode=mode,
|
||||
bitrate=env_bitrate or default_audio_bitrate(mode),
|
||||
@@ -260,10 +259,9 @@ def ask_audio_options(
|
||||
return AudioEncodeOptions(mode="none", preserve_pitch=preserve_pitch)
|
||||
|
||||
while True:
|
||||
if container_extension == ".mkv":
|
||||
prompt = "Audio: Enter=Opus, a=AAC, f=FLAC, c=copy/trim audio, n=no audio: "
|
||||
else:
|
||||
prompt = "Audio: Enter=AAC re-encode, c=copy/trim audio, n=no audio: "
|
||||
prompt = "Audio: Enter=" + (
|
||||
"Opus" if container_extension == ".mkv" else "AAC"
|
||||
) + ", a=AAC, o=Opus, f=FLAC, c=copy/trim audio, n=no audio: "
|
||||
answer = prompt_input(prompt).strip().lower()
|
||||
if not answer:
|
||||
mode = "opus" if container_extension == ".mkv" else "aac"
|
||||
@@ -271,10 +269,10 @@ def ask_audio_options(
|
||||
if answer in {"a", "aac"}:
|
||||
mode = "aac"
|
||||
break
|
||||
if container_extension == ".mkv" and answer in {"o", "opus"}:
|
||||
if answer in {"o", "opus"}:
|
||||
mode = "opus"
|
||||
break
|
||||
if container_extension == ".mkv" and answer in {"f", "flac"}:
|
||||
if answer in {"f", "flac"}:
|
||||
mode = "flac"
|
||||
break
|
||||
if answer in {"c", "copy"}:
|
||||
@@ -329,11 +327,6 @@ def _normalize_audio_mode(value: str) -> str:
|
||||
raise RuntimeError("MBT_VIDEO_AUDIO must be aac, opus, flac, copy, or none")
|
||||
|
||||
|
||||
def _validate_audio_container(mode: str, container_extension: str) -> None:
|
||||
if container_extension == ".mp4" and mode in {"opus", "flac"}:
|
||||
raise RuntimeError("MP4 output supports aac, copy, or none audio in this tool")
|
||||
|
||||
|
||||
def _container_extension_from_env() -> str | None:
|
||||
raw = os.environ.get("MBT_VIDEO_CONTAINER", "").strip().lower()
|
||||
if not raw:
|
||||
@@ -369,7 +362,7 @@ def _codec_from_env() -> str | None:
|
||||
|
||||
def _prompt_codec() -> str:
|
||||
while True:
|
||||
answer = prompt_input("Video codec: x264, Enter=x265: ").strip().lower()
|
||||
answer = prompt_input("Video codec: x264, Enter=x265, c=copy: ").strip().lower()
|
||||
if not answer:
|
||||
return "libx265"
|
||||
try:
|
||||
@@ -383,7 +376,9 @@ def _normalize_codec(value: str) -> str:
|
||||
return "libx264"
|
||||
if value in {"x265", "h265", "hevc", "libx265"}:
|
||||
return "libx265"
|
||||
raise ValueError("codec must be x264 or x265")
|
||||
if value in {"c", "copy", "streamcopy", "stream-copy"}:
|
||||
return "copy"
|
||||
raise ValueError("codec must be x264, x265, or copy")
|
||||
|
||||
|
||||
def _int_from_env(name: str) -> int | None:
|
||||
|
||||
Reference in New Issue
Block a user