ADD Cli options to change defaults
now support changing crf, preset and original media type
This commit is contained in:
+8
-1
@@ -27,7 +27,10 @@ def parse_streams(stream_data: dict, VideoFile: VideoFile) -> VideoFile:
|
|||||||
@click.argument("filename", type=click.Path(exists=True))
|
@click.argument("filename", type=click.Path(exists=True))
|
||||||
@click.option("-i", "--imdb", type=str, help="IMDB ID")
|
@click.option("-i", "--imdb", type=str, help="IMDB ID")
|
||||||
@click.option("-ns", "--nosubtitles", is_flag=True, help="No subtitles")
|
@click.option("-ns", "--nosubtitles", is_flag=True, help="No subtitles")
|
||||||
def main(filename: Path, imdb: str, nosubtitles: bool):
|
@click.option("-p", "--preset", type=int, default=2, help="Encoding preset (default: 2)")
|
||||||
|
@click.option("-c", "--crf", type=int, default=30, help="CRF value (default: 30)")
|
||||||
|
@click.option('-o', '--original-media-type', default='DVD', help='Set the ORIGINAL_MEDIA_TYPE metadata')
|
||||||
|
def main(filename: Path, imdb: str, nosubtitles: bool, preset: int, crf: int, original_media_type: str):
|
||||||
"""Run ffprobe on a file and print the output in JSON format."""
|
"""Run ffprobe on a file and print the output in JSON format."""
|
||||||
video_details = VideoFile(
|
video_details = VideoFile(
|
||||||
imdb=imdb, video_path=filename, allow_subtitle=not nosubtitles
|
imdb=imdb, video_path=filename, allow_subtitle=not nosubtitles
|
||||||
@@ -46,6 +49,10 @@ def main(filename: Path, imdb: str, nosubtitles: bool):
|
|||||||
]
|
]
|
||||||
result = subprocess.run(cmd, capture_output=True, check=True)
|
result = subprocess.run(cmd, capture_output=True, check=True)
|
||||||
data = parse_streams(json.loads(result.stdout), video_details)
|
data = parse_streams(json.loads(result.stdout), video_details)
|
||||||
|
for stream in data.video_streams:
|
||||||
|
stream.preset = preset
|
||||||
|
stream.crf = crf
|
||||||
|
stream.original_media_type = original_media_type
|
||||||
export_data = " ".join(data.cmd())
|
export_data = " ".join(data.cmd())
|
||||||
export_path = Path(filename).parent / "encode.sh"
|
export_path = Path(filename).parent / "encode.sh"
|
||||||
write_shell_script(export_data, export_path)
|
write_shell_script(export_data, export_path)
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ class VideoStream(BaseModel):
|
|||||||
avg_frame_rate: str = Field(None, alias="avg_frame_rate")
|
avg_frame_rate: str = Field(None, alias="avg_frame_rate")
|
||||||
codec_name: str = Field(None)
|
codec_name: str = Field(None)
|
||||||
disposition: Disposition
|
disposition: Disposition
|
||||||
tags: Tags
|
tags: Tags | None = Field(None)
|
||||||
|
preset: int = Field(2)
|
||||||
|
crf: int = Field(30)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def fps(self) -> float:
|
def fps(self) -> float:
|
||||||
@@ -38,9 +40,9 @@ class VideoStream(BaseModel):
|
|||||||
"-c:v",
|
"-c:v",
|
||||||
"libsvtav1",
|
"libsvtav1",
|
||||||
"-crf",
|
"-crf",
|
||||||
"30",
|
str(self.crf),
|
||||||
"-preset",
|
"-preset",
|
||||||
"6",
|
str(self.preset),
|
||||||
"-svtav1-params",
|
"-svtav1-params",
|
||||||
"tune=0:film-grain=20:scd=1",
|
"tune=0:film-grain=20:scd=1",
|
||||||
"-vf",
|
"-vf",
|
||||||
@@ -56,7 +58,7 @@ class AudioStream(BaseModel):
|
|||||||
sample_fmt: str
|
sample_fmt: str
|
||||||
channel_layout: str
|
channel_layout: str
|
||||||
disposition: Disposition
|
disposition: Disposition
|
||||||
tags: Tags
|
tags: Tags | None = Field(None)
|
||||||
|
|
||||||
def cmd_flags(self, index: int) -> list[str]:
|
def cmd_flags(self, index: int) -> list[str]:
|
||||||
side_loaded = []
|
side_loaded = []
|
||||||
@@ -81,7 +83,7 @@ class SubtitleStream(BaseModel):
|
|||||||
index: int
|
index: int
|
||||||
codec_name: str
|
codec_name: str
|
||||||
disposition: Disposition
|
disposition: Disposition
|
||||||
tags: Tags
|
tags: Tags | None = Field(None)
|
||||||
|
|
||||||
def cmd_flags(self, index: int) -> list[str]:
|
def cmd_flags(self, index: int) -> list[str]:
|
||||||
return ["-map", f"0:s:{index}", f"-c:s:{index}", "copy"] + [
|
return ["-map", f"0:s:{index}", f"-c:s:{index}", "copy"] + [
|
||||||
|
|||||||
Reference in New Issue
Block a user