from __future__ import annotations from pathlib import Path import sys import unittest SRC_ROOT = Path(__file__).resolve().parents[2] / "src" if str(SRC_ROOT) not in sys.path: sys.path.insert(0, str(SRC_ROOT)) from ffx.attachment_format import AttachmentFormat # noqa: E402 from ffx.media_descriptor import MediaDescriptor # noqa: E402 from ffx.track_codec import TrackCodec # noqa: E402 from ffx.track_descriptor import TrackDescriptor # noqa: E402 from ffx.track_type import TrackType # noqa: E402 class MediaDescriptorMappingTests(unittest.TestCase): def make_target_descriptor(self) -> MediaDescriptor: return MediaDescriptor( track_descriptors=[ TrackDescriptor( index=0, source_index=0, sub_index=0, track_type=TrackType.VIDEO, codec_name=TrackCodec.H264, ), TrackDescriptor( index=1, source_index=7, sub_index=0, track_type=TrackType.SUBTITLE, codec_name=TrackCodec.ASS, ), TrackDescriptor( index=2, source_index=8, sub_index=1, track_type=TrackType.SUBTITLE, codec_name=TrackCodec.ASS, ), TrackDescriptor( index=3, source_index=9, sub_index=0, track_type=TrackType.ATTACHMENT, attachment_format=AttachmentFormat.TTF, ), ] ) def make_source_descriptor(self) -> MediaDescriptor: return MediaDescriptor( track_descriptors=[ TrackDescriptor( index=0, source_index=0, sub_index=0, track_type=TrackType.VIDEO, codec_name=TrackCodec.H264, ), TrackDescriptor( index=3, source_index=3, sub_index=0, track_type=TrackType.SUBTITLE, codec_name=TrackCodec.VOBSUB, ), TrackDescriptor( index=4, source_index=4, sub_index=1, track_type=TrackType.SUBTITLE, codec_name=TrackCodec.VOBSUB, ), TrackDescriptor( index=5, source_index=5, sub_index=2, track_type=TrackType.SUBTITLE, codec_name=TrackCodec.PGS, ), TrackDescriptor( index=6, source_index=6, sub_index=3, track_type=TrackType.SUBTITLE, codec_name=TrackCodec.PGS, ), TrackDescriptor( index=7, source_index=7, sub_index=4, track_type=TrackType.SUBTITLE, codec_name=TrackCodec.ASS, ), TrackDescriptor( index=8, source_index=8, sub_index=5, track_type=TrackType.SUBTITLE, codec_name=TrackCodec.ASS, ), TrackDescriptor( index=9, source_index=9, sub_index=0, track_type=TrackType.ATTACHMENT, attachment_format=AttachmentFormat.TTF, ), ] ) def test_source_aware_mapping_uses_original_subtitle_and_attachment_indices(self): tokens = self.make_target_descriptor().getInputMappingTokens( sourceMediaDescriptor=self.make_source_descriptor() ) self.assertEqual( [ "-map", "0:v:0", "-map", "0:s:4", "-map", "0:s:5", "-map", "0:9", ], tokens, ) def test_video_only_mapping_does_not_map_font_attachments(self): tokens = self.make_target_descriptor().getInputMappingTokens( only_video=True ) self.assertEqual(["-map", "0:v:0"], tokens) if __name__ == "__main__": unittest.main()