Skip to content

Commit

Permalink
Use correct SAR with --force-anamorphic and --letterbox
Browse files Browse the repository at this point in the history
Fixes #48
  • Loading branch information
JuniorIsAJitterbug committed Feb 8, 2024
1 parent 4546e4b commit 9ff0f31
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 49 deletions.
21 changes: 10 additions & 11 deletions src/tbc_video_export/process/wrapper/wrapper_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def command(self) -> FlatList: # noqa: D102
self._get_map_opts(),
self._get_timecode_opt(),
self._get_framerate_opt(),
self._get_aspect_ratio_opt(),
self._get_color_range_opt(),
self._get_color_opts(),
self._get_format_opts(),
Expand Down Expand Up @@ -228,6 +227,9 @@ def _get_filter_complex_opts(self) -> FlatList:
else ""
)

if self._state.opts.force_anamorphic or self._state.opts.letterbox:
common_filters.append(self._get_widescreen_aspect_ratio_filter())

# override profile colorlevels if set with opt
if self._state.opts.force_black_level is not None:
common_filters.append(
Expand Down Expand Up @@ -363,17 +365,14 @@ def _get_framerate_opt(self) -> FlatList:
)
)

def _get_aspect_ratio_opt(self) -> FlatList | None:
"""Return opts for aspect ratio."""
# do not add AR flag to file, as it must match the rawvideo from chroma on merge
if self._is_two_step_luma_mode():
return None
def _get_widescreen_aspect_ratio_filter(self) -> str:
"""Return filter for widescreen aspect ratio."""
match self._state.video_system:
case VideoSystem.PAL:
return "setsar=512/461:max=1000"

return (
FlatList(("-aspect", "16:9"))
if (self._state.opts.force_anamorphic or self._state.opts.letterbox)
else None
)
case VideoSystem.NTSC | VideoSystem.PAL_M:
return "setsar=194/171:max=1000"

def _get_color_opts(self) -> FlatList | None:
"""Return opts for color settings."""
Expand Down
38 changes: 0 additions & 38 deletions tests/test_wrappers_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,44 +247,6 @@ def test_ffmpeg_add_filter_profile_opt(self) -> None: # noqa: D102

self.assertTrue(any(",bwdif" in cmds for cmds in cmd))

def test_ffmpeg_letterbox_opt(self) -> None: # noqa: D102
_, opts = self.parse_opts([str(self.path), "pal_svideo", "--letterbox"])
self.files = FileHelper(opts, self.config)
state = ProgramState(opts, self.config, self.files)

ffmpeg_wrapper = WrapperFFmpeg(
state,
WrapperConfig[tuple[Pipe], None](
state.current_export_mode,
TBCType.CHROMA,
input_pipes=(self.pipe, self.pipe),
output_pipes=None,
),
)

cmd = ffmpeg_wrapper.command.data

self.assertTrue({"-aspect", "16:9"}.issubset(cmd))

def test_ffmpeg_anamorphic_opt(self) -> None: # noqa: D102
_, opts = self.parse_opts([str(self.path), "pal_svideo", "--force-anamorphic"])
self.files = FileHelper(opts, self.config)
state = ProgramState(opts, self.config, self.files)

ffmpeg_wrapper = WrapperFFmpeg(
state,
WrapperConfig[tuple[Pipe], None](
state.current_export_mode,
TBCType.CHROMA,
input_pipes=(self.pipe, self.pipe),
output_pipes=None,
),
)

cmd = ffmpeg_wrapper.command.data

self.assertTrue({"-aspect", "16:9"}.issubset(cmd))

def test_ffmpeg_add_invalid_filter_profile_opt(self) -> None: # noqa: D102
with self.assertRaises(InvalidFilterProfileError):
_, __ = self.parse_opts(
Expand Down
38 changes: 38 additions & 0 deletions tests/test_wrappers_ntsc_svideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,44 @@ def test_decoder_default_luma_decoder_ntsc_svideo(self) -> None: # noqa: D102
f"PIPE_OUT",
)

def test_ffmpeg_letterbox_ntsc_opt(self) -> None: # noqa: D102
_, opts = self.parse_opts([str(self.path), "ntsc_svideo", "--letterbox"])
self.files = FileHelper(opts, self.config)
state = ProgramState(opts, self.config, self.files)

ffmpeg_wrapper = WrapperFFmpeg(
state,
WrapperConfig[tuple[Pipe], None](
state.current_export_mode,
TBCType.CHROMA,
input_pipes=(self.pipe, self.pipe),
output_pipes=None,
),
)

cmd = ffmpeg_wrapper.command.data

self.assertTrue(any("setsar=194/171:max=1000" in cmds for cmds in cmd))

def test_ffmpeg_anamorphic_ntsc_opt(self) -> None: # noqa: D102
_, opts = self.parse_opts([str(self.path), "ntsc_svideo", "--force-anamorphic"])
self.files = FileHelper(opts, self.config)
state = ProgramState(opts, self.config, self.files)

ffmpeg_wrapper = WrapperFFmpeg(
state,
WrapperConfig[tuple[Pipe], None](
state.current_export_mode,
TBCType.CHROMA,
input_pipes=(self.pipe, self.pipe),
output_pipes=None,
),
)

cmd = ffmpeg_wrapper.command.data

self.assertTrue(any("setsar=194/171:max=1000" in cmds for cmds in cmd))

def test_decoder_default_chroma_decoder_ntsc_svideo(self) -> None: # noqa: D102
_, opts = self.parse_opts([str(self.path), "ntsc_svideo", "--threads", "4"])
self.files = FileHelper(opts, self.config)
Expand Down
38 changes: 38 additions & 0 deletions tests/test_wrappers_pal_svideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,44 @@ def test_decoder_default_luma_decoder_pal_svideo(self) -> None: # noqa: D102
f"PIPE_OUT",
)

def test_ffmpeg_letterbox_pal_opt(self) -> None: # noqa: D102
_, opts = self.parse_opts([str(self.path), "pal_svideo", "--letterbox"])
self.files = FileHelper(opts, self.config)
state = ProgramState(opts, self.config, self.files)

ffmpeg_wrapper = WrapperFFmpeg(
state,
WrapperConfig[tuple[Pipe], None](
state.current_export_mode,
TBCType.CHROMA,
input_pipes=(self.pipe, self.pipe),
output_pipes=None,
),
)

cmd = ffmpeg_wrapper.command.data

self.assertTrue(any("setsar=512/461:max=1000" in cmds for cmds in cmd))

def test_ffmpeg_anamorphic_pal_opt(self) -> None: # noqa: D102
_, opts = self.parse_opts([str(self.path), "pal_svideo", "--force-anamorphic"])
self.files = FileHelper(opts, self.config)
state = ProgramState(opts, self.config, self.files)

ffmpeg_wrapper = WrapperFFmpeg(
state,
WrapperConfig[tuple[Pipe], None](
state.current_export_mode,
TBCType.CHROMA,
input_pipes=(self.pipe, self.pipe),
output_pipes=None,
),
)

cmd = ffmpeg_wrapper.command.data

self.assertTrue(any("setsar=512/461:max=1000" in cmds for cmds in cmd))

def test_decoder_default_chroma_decoder_pal_svideo(self) -> None: # noqa: D102
_, opts = self.parse_opts([str(self.path), "pal_svideo", "--threads", "4"])
self.files = FileHelper(opts, self.config)
Expand Down

0 comments on commit 9ff0f31

Please sign in to comment.