From c7a381c4b932c9d583f094fae602174b4bc7f0a4 Mon Sep 17 00:00:00 2001 From: Esa Kataja Date: Thu, 17 Apr 2025 12:42:44 +0300 Subject: [PATCH] Add film grain parameter to video encoding with configurable amount --- src/app.py | 4 +++- src/models/streams.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app.py b/src/app.py index ab40ee7..ca1e043 100644 --- a/src/app.py +++ b/src/app.py @@ -30,7 +30,8 @@ def main( nosubtitles: bool = typer.Option(False, "-ns", "--nosubtitles", help="Remove subtitles"), preset: int = typer.Option(2, "-p", "--preset", help="Encoding preset"), crf: int = typer.Option(30, "-c", "--crf", help="CRF value"), - original_media_type: str = typer.Option("DVD", "-o", "--original-media-type", help="Set the ORIGINAL_MEDIA_TYPE metadata") + original_media_type: str = typer.Option("DVD", "-o", "--original-media-type", help="Set the ORIGINAL_MEDIA_TYPE metadata"), + film_grain: int = typer.Option(20, "-fg", "--film-grain", help="Film grain amount (default: 20)") ): video_details = VideoFile( imdb=imdb, video_path=filename, allow_subtitle=not nosubtitles @@ -53,6 +54,7 @@ def main( stream.preset = preset stream.crf = crf stream.original_media_type = original_media_type + stream.film_grain = film_grain export_data = " ".join(data.cmd()) export_path = Path(filename).parent / "encode.sh" write_shell_script(export_data, export_path) diff --git a/src/models/streams.py b/src/models/streams.py index 46d876a..b45ccff 100644 --- a/src/models/streams.py +++ b/src/models/streams.py @@ -28,6 +28,7 @@ class VideoStream(BaseModel): preset: int = Field(2) crf: int = Field(30) original_media_type: str = Field(None) + film_grain: int = Field(20) @cached_property def fps(self) -> float: @@ -45,7 +46,7 @@ class VideoStream(BaseModel): "-preset", str(self.preset), "-svtav1-params", - "tune=0:film-grain=20:scd=1", + f"tune=0:film-grain={self.film_grain}:scd=1", "-vf", "'scale=iw*sar:ih,setsar=1,scale=-2:ih:lanczos'", "-g",