Skip to content

Commit

Permalink
Add --profile-container opt.
Browse files Browse the repository at this point in the history
Allows overriding of profile container.

Fixes #34
  • Loading branch information
JuniorIsAJitterbug committed Jan 24, 2024
1 parent cebefc3 commit bc253c4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/tbc_video_export/common/file_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,19 @@ def tbc_luma(self) -> str:

raise exceptions.TBCError("Unable to find luma TBC.")

@cached_property
def output_container(self) -> str:
"""Return container used for output video file."""
return (
self._opts.profile_container
if self._opts.profile_container is not None
else self._profile.video_profile.container
)

@cached_property
def output_video_file(self) -> Path:
"""Return absolute path to the output video file."""
return self.get_output_file_from_ext(f"{self._profile.video_profile.container}")
return self.get_output_file_from_ext(self.output_container)

@cached_property
def output_video_file_luma(self) -> Path:
Expand Down
1 change: 1 addition & 0 deletions src/tbc_video_export/opts/opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Opts(argparse.Namespace):
# ffmpeg
profile: str
profile_luma: str
profile_container: str | None
audio_track: list[AudioTrackOpt]
metadata: list[list[str]]
metadata_file: list[Path]
Expand Down
9 changes: 9 additions & 0 deletions src/tbc_video_export/opts/opts_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ def add_ffmpeg_opts(config: Config, parent: argparse.ArgumentParser) -> None:
"\n\n",
)

ffmpeg_opts.add_argument(
"--profile-container",
type=str,
metavar="profile_container",
help="Override an FFmpeg profile to use a specific container. Compatibility \n"
"with profile is not guaranteed."
"\n\n",
)

ffmpeg_opts.add_argument(
"--list-profiles",
action=_ActionListProfiles,
Expand Down
4 changes: 2 additions & 2 deletions src/tbc_video_export/process/wrapper/wrapper_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,13 @@ def _is_two_step_merge_mode(self) -> bool:

def _get_supports_attachments(self) -> bool:
"""Return True if attachments are supported by the profile container."""
return self._get_profile().video_profile.container.lower() == "mkv"
return self._state.file_helper.output_container.lower() == "mkv"

def _get_subtitle_format(self) -> str:
"""Return subtitle format based on the profile container."""
return (
"srt"
if self._get_profile().video_profile.container.lower() != "mov"
if self._state.file_helper.output_container.lower() != "mov"
else "mov_text"
)

Expand Down
28 changes: 28 additions & 0 deletions tests/test_wrappers_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,34 @@ def test_ffmpeg_field_order_invalid_opt(self, mock_stderr: StringIO) -> None: #
r"error: argument --field-order: invalid FieldOrder value: 'invalid'",
)

def test_ffmpeg_override_container_opt(self) -> None: # noqa: D102
_, opts = self.parse_opts(
[
str(self.path),
"pal_svideo",
"--profile",
"prores_hq",
"--profile-container",
"mxf",
]
)
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("pal_svideo.mxf" in cmds for cmds in cmd))


if __name__ == "__main__":
unittest.main()

0 comments on commit bc253c4

Please sign in to comment.