|
1 | 1 | import functools |
2 | 2 | import math |
3 | | -import shutil |
4 | | -import subprocess |
5 | 3 | from collections import Counter |
6 | 4 | from pathlib import Path |
7 | 5 | from typing import List, Optional, Tuple |
@@ -34,8 +32,8 @@ def __init__(self, file: str, verbose=False): |
34 | 32 | "Required plugin d2v for namespace 'd2v' not found. " |
35 | 33 | "See https://github.com/dwbuiten/d2vsource" |
36 | 34 | ) |
37 | | - self.file = self._get_d2v(Path(file)) |
38 | | - self.d2v = D2V.load(self.file) |
| 35 | + self.d2v = D2V.load(Path(file)) |
| 36 | + self.file = self.d2v.path |
39 | 37 | self.flags = self._get_flags(self.d2v) |
40 | 38 | self.pulldown, self.pulldown_str = self._get_pulldown(self.flags) |
41 | 39 | self.vfr = any(f["progressive_frame"] and f["rff"] and f["tff"] for f in self.flags) and any( |
@@ -237,72 +235,6 @@ def floor(self, cycle: int = None, offsets: List[int] = None): |
237 | 235 | self.vfr = False |
238 | 236 | return self |
239 | 237 |
|
240 | | - @staticmethod |
241 | | - def _get_d2v(file_path: Path) -> Path: |
242 | | - """Demux video track and generate a D2V file for it if needed.""" |
243 | | - is_vob = file_path.suffix.lower() == ".vob" |
244 | | - d2v_path = file_path.with_suffix(".d2v") |
245 | | - if d2v_path.is_file(): |
246 | | - print("Skipping generation as a D2V file already exists") |
247 | | - return d2v_path |
248 | | - # demux the mpeg stream if not a .VOB or .MPEG file |
249 | | - demuxed_ext = [".mpeg", ".mpg", ".m2v", ".vob"] |
250 | | - vid_path = file_path |
251 | | - if file_path.suffix.lower() in demuxed_ext: |
252 | | - print("Skipping demuxing of raw MPEG stream as it already exists or is unnecessary") |
253 | | - else: |
254 | | - vid_path = next((x for x in map(file_path.with_suffix, demuxed_ext) if x.exists()), None) |
255 | | - if not vid_path: |
256 | | - vid_path = file_path.with_suffix(demuxed_ext[0]) |
257 | | - mkvextract_path = shutil.which("mkvextract") |
258 | | - if not mkvextract_path: |
259 | | - raise RuntimeError( |
260 | | - "Executable 'mkvextract' not found, but is needed for the provided file.\n" |
261 | | - "Install MKVToolNix and make sure it's binaries are in the environment path." |
262 | | - ) |
263 | | - subprocess.run([ |
264 | | - mkvextract_path, |
265 | | - file_path.name, |
266 | | - # todo ; this assumes the track with track-id of 0 is the video, not ideal |
267 | | - "tracks", f"0:{vid_path.name}" |
268 | | - ], cwd=file_path.parent, check=True) |
269 | | - # use dgindex to create a d2v file for the demuxed track |
270 | | - dgindex_path = shutil.which("DGIndex") or shutil.which("dgindex") |
271 | | - if not dgindex_path: |
272 | | - raise RuntimeError( |
273 | | - "Executable 'DGIndex' not found, but is needed for the provided file.\n" |
274 | | - "Add DGIndex.exe to your environment path. Ensure the executable is named `DGIndex.exe`." |
275 | | - ) |
276 | | - is_unix = dgindex_path.startswith("/") |
277 | | - if is_unix: |
278 | | - # required to do it this way for whatever reason. Directly calling it sometimes fails. |
279 | | - args = ["wine", "start", "/wait", "Z:" + dgindex_path] |
280 | | - else: |
281 | | - args = [dgindex_path] |
282 | | - args.extend([ |
283 | | - # all the following D2V settings are VERY important |
284 | | - # please do not change these unless there's a good verifiable reason |
285 | | - "-ai" if is_vob else "-i", vid_path.name, |
286 | | - "-ia", "5", # iDCT Algorithm, 5=IEEE-1180 Reference |
287 | | - "-fo", "2", # Field Operation, 2=Ignore Pulldown Flags |
288 | | - "-yr", "1", # YUV->RGB, 1=PC Scale |
289 | | - "-om", "0", # Output Method, 0=None (just d2v) |
290 | | - "-hide", "-exit", # start hidden and exit when saved |
291 | | - "-o", file_path.stem |
292 | | - ]) |
293 | | - subprocess.run(args, cwd=file_path.parent, check=True) |
294 | | - # Replace the Z:\bla\bla paths to /bla/bla unix paths, if on a unix system. |
295 | | - # This is needed simply due to how d2vsource loads the video files. On linux it doesn't use wine, |
296 | | - # so Z:\ paths obviously won't exist. |
297 | | - if is_unix: |
298 | | - with open(d2v_path, "rt", encoding="utf8") as f: |
299 | | - d2v_content = f.read().splitlines() |
300 | | - d2v_content = [(x[2:].replace("\\", "/") if x.startswith("Z:\\") else x) for x in d2v_content] |
301 | | - with open(d2v_path, "wt", encoding="utf8") as f: |
302 | | - f.write("\n".join(d2v_content)) |
303 | | - # return file path of the new d2v file |
304 | | - return d2v_path |
305 | | - |
306 | 238 | @staticmethod |
307 | 239 | def _stamp_frames(clip: vs.VideoNode, flags: List[dict]) -> vs.VideoNode: |
308 | 240 | """Stamp frames with prop data that may be needed.""" |
|
0 commit comments