def _open_source(self, force_lsmas: bool = False, **index_kwargs: Dict[str, Any]) -> vs.VideoNode: if is_extension(self.path, ".m2ts") or is_extension(self.path, ".mts"): force_lsmas = True if is_extension(self.path, ".d2v"): has_plugin_or_raise("d2v") return core.d2v.Source(self.path, **index_kwargs) elif is_extension(self.path, ".dgi"): has_plugin_or_raise("dgdecodenv") return core.dgdecodenv.DGSource(self.path, **index_kwargs) elif is_extension(self.path, ".mpls"): has_plugin_or_raise(["lsmas", "mpls"]) pl_index = cast(int, index_kwargs.pop("playlist", 0)) angle_index = cast(int, index_kwargs.pop("angle", 0)) mpls_in = core.mpls.Read(self.path, pl_index, angle_index) clips: List[vs.VideoNode] = [] for idx in range(mpls_in["count"]): # type: ignore clips.append(core.lsmas.LWLibavSource(mpls_in["clip"][idx], **index_kwargs)) # type: ignore return core.std.Splice(clips) elif is_extension(self.path, ".avi"): has_plugin_or_raise("avisource") return core.avisource.AVISource(self.path, **index_kwargs) elif is_image(self.path): has_plugin_or_raise("imwri") return core.imwri.Read(self.path, **index_kwargs) if force_lsmas: has_plugin_or_raise("lsmas") return core.lsmas.LWLibavSource(self.path, **index_kwargs) has_plugin_or_raise("ffms2") return core.ffms2.Source(self.path, **index_kwargs)
def main(): files = glob.glob('**', recursive=True) num_threads = 12 pool = ThreadPool(num_threads) for file in files: if is_image(file): pool.apply_async(conversion, ((file),)) pool.close() pool.join()
def source(file: str, ref: Optional[vs.VideoNode] = None, force_lsmas: bool = False, mpls: bool = False, mpls_playlist: int = 0, mpls_angle: int = 0, **index_args: Any) -> vs.VideoNode: """ Generic clip import function. Automatically determines if ffms2 or L-SMASH should be used to import a clip, but L-SMASH can be forced. It also automatically determines if an image has been imported. You can set its fps using 'fpsnum' and 'fpsden', or using a reference clip with 'ref'. Alias for this function is `lvsfunc.src`. Dependencies: * ffms2 * L-SMASH (optional: m2ts sources or when forcing lsmas) * d2vsource (optional: d2v sources) * dgdecodenv (optional: dgi sources) * mvsfunc (optional: reference clip mode) * vapoursynth-readmpls (optional: mpls sources) :param file: Input file :param ref: Use another clip as reference for the clip's format, resolution, and framerate (Default: None) :param force_lsmas: Force files to be imported with L-SMASH (Default: False) :param mpls: Load in a mpls file (Default: False) :param mpls_playlist: Playlist number, which is the number in mpls file name (Default: 0) :param mpls_angle: Angle number to select in the mpls playlist (Default: 0) :param kwargs: Arguments passed to the indexing filter :return: Vapoursynth clip representing input file """ # TODO: Consider adding kwargs for additional options, # find a way to NOT have to rely on a million elif's if file.startswith('file:///'): file = file[8::] # Error handling for some file types if file.endswith('.mpls') and mpls is False: raise ValueError( "source: 'Please set \"mpls = True\" and give a path to the base Blu-ray directory when trying to load in mpls files'" ) # noqa: E501 if os.path.splitext(file)[1].lower() in annoying_formats: raise ValueError( "source: 'Please use an external indexer like d2vwitch or DGIndexNV for this file and import that'" ) # noqa: E501 if force_lsmas: clip = core.lsmas.LWLibavSource(file, **index_args) elif mpls: mpls_in = core.mpls.Read(file, mpls_playlist, mpls_angle) clip = core.std.Splice([ core.lsmas.LWLibavSource(mpls_in['clip'][i], **index_args) for i in range(mpls_in['count']) ]) elif file.endswith('.d2v'): clip = core.d2v.Source(file, **index_args) elif file.endswith('.dgi'): clip = core.dgdecodenv.DGSource(file, **index_args) elif is_image(file): clip = core.imwri.Read(file, **index_args) else: if file.endswith('.m2ts'): clip = core.lsmas.LWLibavSource(file, **index_args) else: clip = core.ffms2.Source(file, **index_args) if ref: try: from mvsfunc import GetMatrix except ModuleNotFoundError: raise ModuleNotFoundError("source: missing dependency 'mvsfunc'") if ref.format is None: raise ValueError("source: 'Variable-format clips not supported.'") clip = core.std.AssumeFPS(clip, fpsnum=ref.fps.numerator, fpsden=ref.fps.denominator) clip = core.resize.Bicubic(clip, width=ref.width, height=ref.height, format=ref.format.id, matrix_s=str(GetMatrix(ref))) if is_image(file): clip = clip * (ref.num_frames - 1) return clip
def test_is_image(self): """These are basically tests for the mime types, but I want the coverage. rooDerp""" self.assertEqual(vsutil.is_image('something.png'), True) self.assertEqual(vsutil.is_image('something.m2ts'), False)
def source(file: str, ref: Optional[vs.VideoNode] = None, force_lsmas: bool = False, mpls: bool = False, mpls_playlist: int = 0, mpls_angle: int = 0) -> vs.VideoNode: """ Generic clip import function. Automatically determines if ffms2 or L-SMASH should be used to import a clip, but L-SMASH can be forced. It also automatically determines if an image has been imported. You can set its fps using 'fpsnum' and 'fpsden', or using a reference clip with 'ref'. Dependencies: * d2vsource (optional: d2v sources) * dgdecodenv (optional: dgi sources) * mvsfunc (optional: reference clip mode) * vapoursynth-readmpls (optional: mpls sources) :param file: Input file :param ref: Use another clip as reference for the clip's format, resolution, and framerate (Default: None) :param force_lsmas: Force files to be imported with L-SMASH (Default: False) :param mpls: Load in a mpls file (Default: False) :param mpls_playlist: Playlist number, which is the number in mpls file name (Default: 0) :param mpls_angle: Angle number to select in the mpls playlist (Default: 0) :return: Vapoursynth clip representing input file """ # TODO: Consider adding kwargs for additional options, # find a way to NOT have to rely on a million elif's if file.startswith('file:///'): file = file[8::] # Error handling for some file types if file.endswith('.mpls') and mpls is False: raise ValueError( f"source: 'Please set \"mpls = True\" and give a path to the base Blu-ray directory when trying to load in mpls files'" ) if file.endswith('.vob') or file.endswith('.ts'): raise ValueError( f"source: 'Please index VOB and TS files with d2v before importing them'" ) if force_lsmas: return core.lsmas.LWLibavSource(file) elif mpls: mpls = core.mpls.Read(file, mpls_playlist) clip = core.std.Splice([ core.lsmas.LWLibavSource(mpls['clip'][i]) for i in range(mpls['count']) ]) elif file.endswith('.d2v'): clip = core.d2v.Source(file) elif file.endswith('.dgi'): clip = core.dgdecodenv.DGSource(file) elif is_image(file): clip = core.imwri.Read(file) else: if file.endswith('.m2ts'): clip = core.lsmas.LWLibavSource(file) else: clip = core.ffms2.Source(file) if ref: try: import mvsfunc as mvf except ModuleNotFoundError: raise ModuleNotFoundError("source: missing dependency 'mvsfunc'") clip = core.std.AssumeFPS(clip, fpsnum=ref.fps.numerator, fpsden=ref.fps.denominator) clip = core.resize.Bicubic(clip, width=ref.width, height=ref.height, format=ref.format, matrix_s=mvf.GetMatrix(ref)) if is_image(file): clip = clip * (ref.num_frames - 1) return clip