Skip to content

Commit 8bc78a0

Browse files
committed
Update pyd2v to 1.3.0, remove PD2V._get_d2v
The code in PD2V._get_d2v() was moved and refactored into pyd2v, and also implemented into pyd2v.load, so the function is no longer required.
1 parent e85960f commit 8bc78a0

File tree

3 files changed

+7
-75
lines changed

3 files changed

+7
-75
lines changed

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pvsfunc/pd2v.py

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import functools
22
import math
3-
import shutil
4-
import subprocess
53
from collections import Counter
64
from pathlib import Path
75
from typing import List, Optional, Tuple
@@ -34,8 +32,8 @@ def __init__(self, file: str, verbose=False):
3432
"Required plugin d2v for namespace 'd2v' not found. "
3533
"See https://github.com/dwbuiten/d2vsource"
3634
)
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
3937
self.flags = self._get_flags(self.d2v)
4038
self.pulldown, self.pulldown_str = self._get_pulldown(self.flags)
4139
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):
237235
self.vfr = False
238236
return self
239237

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-
306238
@staticmethod
307239
def _stamp_frames(clip: vs.VideoNode, flags: List[dict]) -> vs.VideoNode:
308240
"""Stamp frames with prop data that may be needed."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ include = ["LICENSE", "README.md"]
3030
python = ">=3.6,<4.0"
3131
vapoursynth = "^51"
3232
pymediainfo = "^5.1.0"
33-
pyd2v = "^1.2.0"
33+
pyd2v = "^1.3.0"
3434
more-itertools = "^8.8.0"

0 commit comments

Comments
 (0)