Skip to content

Commit

Permalink
Use extractplanes+mergeplanes for all merge exports
Browse files Browse the repository at this point in the history
Fixes issue when merging 16-bit formats
  • Loading branch information
JuniorIsAJitterbug committed Mar 26, 2024
1 parent 297376a commit 30e834f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 38 deletions.
53 changes: 18 additions & 35 deletions src/tbc_video_export/process/wrapper/wrapper_ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,41 +262,24 @@ def _get_filter_complex_opts(self) -> FlatList: # noqa: C901, PLR0912
case ExportMode.CHROMA_MERGE:
# merge Y/C from separate Y+C inputs

if self._state.opts.two_step:
# luma file, chroma decoder input

mergeplanes = (
"0x001020"
if consts.FFMPEG_USE_OLD_MERGEPLANES
else "map1s=1:map2s=2"
)

complex_filter = (
f"[0:v]format={self._get_profile().video_format},"
f"extractplanes=y[y];"
f"[1:v]format={self._get_profile().video_format},"
f"extractplanes=u+v[u][v];"
f"[y][u][v]mergeplanes={mergeplanes}:"
f"format={self._get_profile().video_format}{filters_opts}"
f"[v_output]"
f"{other_filters_opts}"
)
else:
# both decoder inputs piped in

mergeplanes = (
"0x001112"
if consts.FFMPEG_USE_OLD_MERGEPLANES
else "map1s=1:map1p=1:map2s=1:map2p=2"
)
# using mergeplanes 0x001112 with pipe+pipe input works but there
# seems to be an issue when merging gray16le and 16-bit yuv(??) formats.
# safer to extract the 2x inputs (file+pipe/pipe+pipe) into y/u/v planes
# and merge to avoid any issues.

mergeplanes = (
"0x001020"
if consts.FFMPEG_USE_OLD_MERGEPLANES
else "map1s=1:map2s=2"
)

complex_filter = (
f"[1:v]format={self._get_profile().video_format}[chroma];"
f"[0:v][chroma]mergeplanes={mergeplanes}:"
f"format={self._get_profile().video_format}{filters_opts}"
f"[v_output]"
f"{other_filters_opts}"
)
complex_filter = (
f"[0:v]format=gray16le[luma];[1:v]format=yuv444p16le[chroma];"
f"[luma]extractplanes=y[y];[chroma]extractplanes=u+v[u][v];"
f"[y][u][v]mergeplanes={mergeplanes}:format=yuv444p16le"
f"{filters_opts}[v_output]"
f"{other_filters_opts}"
)

case ExportMode.LUMA_EXTRACTED:
# extract Y from a Y/C input
Expand All @@ -316,7 +299,7 @@ def _get_filter_complex_opts(self) -> FlatList: # noqa: C901, PLR0912

case _ as mode if mode is ExportMode.LUMA and self._state.opts.two_step:
# luma step in two-step should not use any filters
complex_filter = f"[0:v]null,{field_filter}[v_output]"
complex_filter = f"[0:v]{field_filter}[v_output]"

case _:
complex_filter = (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wrappers_ntsc_svideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_ffmpeg_opts_ntsc_svideo(self) -> None:
"-thread_queue_size 1024",
"-i PIPE_IN",
"-filter_complex",
"[1:v]format=yuv422p10le[chroma];[0:v][chroma]mergeplanes=0x001112:format=yuv422p10le,setfield=tff[v_output]",
"[0:v]format=gray16le[luma];[1:v]format=yuv444p16le[chroma];[luma]extractplanes=y[y];[chroma]extractplanes=u+v[u][v];[y][u][v]mergeplanes=0x001020:format=yuv444p16le,setfield=tff[v_output]",
"-map [v_output]",
"-timecode 00:00:00:00",
"-framerate ntsc",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wrappers_pal_svideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_ffmpeg_opts_pal_svideo(self) -> None:
"-thread_queue_size 1024",
"-i PIPE_IN",
"-filter_complex",
"[1:v]format=yuv422p10le[chroma];[0:v][chroma]mergeplanes=0x001112:format=yuv422p10le,setfield=tff[v_output]",
"[0:v]format=gray16le[luma];[1:v]format=yuv444p16le[chroma];[luma]extractplanes=y[y];[chroma]extractplanes=u+v[u][v];[y][u][v]mergeplanes=0x001020:format=yuv444p16le,setfield=tff[v_output]",
"-map [v_output]",
"-timecode 00:00:00:00",
"-framerate pal",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wrappers_palm_svideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_ffmpeg_opts_palm_svideo(self) -> None:
"-thread_queue_size 1024",
"-i PIPE_IN",
"-filter_complex",
"[1:v]format=yuv422p10le[chroma];[0:v][chroma]mergeplanes=0x001112:format=yuv422p10le,setfield=tff[v_output]",
"[0:v]format=gray16le[luma];[1:v]format=yuv444p16le[chroma];[luma]extractplanes=y[y];[chroma]extractplanes=u+v[u][v];[y][u][v]mergeplanes=0x001020:format=yuv444p16le,setfield=tff[v_output]",
"-map [v_output]",
"-timecode 00:00:00:00",
"-framerate ntsc",
Expand Down

0 comments on commit 30e834f

Please sign in to comment.