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.option("-i", "--imdb", type=str, help="IMDB ID")
|
||||
@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."""
|
||||
video_details = VideoFile(
|
||||
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)
|
||||
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_path = Path(filename).parent / "encode.sh"
|
||||
write_shell_script(export_data, export_path)
|
||||
|
||||
@@ -24,7 +24,9 @@ class VideoStream(BaseModel):
|
||||
avg_frame_rate: str = Field(None, alias="avg_frame_rate")
|
||||
codec_name: str = Field(None)
|
||||
disposition: Disposition
|
||||
tags: Tags
|
||||
tags: Tags | None = Field(None)
|
||||
preset: int = Field(2)
|
||||
crf: int = Field(30)
|
||||
|
||||
@cached_property
|
||||
def fps(self) -> float:
|
||||
@@ -38,9 +40,9 @@ class VideoStream(BaseModel):
|
||||
"-c:v",
|
||||
"libsvtav1",
|
||||
"-crf",
|
||||
"30",
|
||||
str(self.crf),
|
||||
"-preset",
|
||||
"6",
|
||||
str(self.preset),
|
||||
"-svtav1-params",
|
||||
"tune=0:film-grain=20:scd=1",
|
||||
"-vf",
|
||||
@@ -56,7 +58,7 @@ class AudioStream(BaseModel):
|
||||
sample_fmt: str
|
||||
channel_layout: str
|
||||
disposition: Disposition
|
||||
tags: Tags
|
||||
tags: Tags | None = Field(None)
|
||||
|
||||
def cmd_flags(self, index: int) -> list[str]:
|
||||
side_loaded = []
|
||||
@@ -81,7 +83,7 @@ class SubtitleStream(BaseModel):
|
||||
index: int
|
||||
codec_name: str
|
||||
disposition: Disposition
|
||||
tags: Tags
|
||||
tags: Tags | None = Field(None)
|
||||
|
||||
def cmd_flags(self, index: int) -> list[str]:
|
||||
return ["-map", f"0:s:{index}", f"-c:s:{index}", "copy"] + [
|
||||
|
||||
Reference in New Issue
Block a user