Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV2 to remove enzyme and mediainfo #8750

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 12 additions & 36 deletions sickchill/helper/media_info.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import binascii

from enzyme import MKV
import cv2

from sickchill.helper.common import is_media_file

try:
from pymediainfo import MediaInfo as mediainfo
except (ModuleNotFoundError, RuntimeError):
mediainfo = None


def _avi_screen_size(filename):
"""
Expand Down Expand Up @@ -37,38 +32,20 @@ def _avi_screen_size(filename):
return None, None


def _mkv_screen_size(filename):
"""
Parses mkv file for width and height
:param filename: full path and filename to a video file
:type: str
:returns tuple: (width, height)
"""
try:
if filename.endswith(".mkv"):
with open(filename, "rb") as f:
mkv = MKV(f)

return mkv.video_tracks[0].width, mkv.video_tracks[0].height
except Exception:
pass

return None, None


def _mediainfo_screen_size(filename):
def _opencv2_screen_size(filename):
"""
Attempts to read the width and height of a video file, using mediainfo
:param filename: full path and filename to a video file
:type: str
:returns tuple: (width, height)
"""
try:
if mediainfo:
_media_info = mediainfo.parse(filename)
for track in _media_info.tracks:
if track.track_type == "Video":
return track.width, track.height
cv2_video = cv2.VideoCapture(filename)
if cv2_video:
cv2_width = int(cv2_video.get(cv2.CAP_PROP_FRAME_WIDTH))
cv2_height = int(cv2_video.get(cv2.CAP_PROP_FRAME_HEIGHT))
cv2_video.release()
return cv2_width, cv2_height
except (OSError, TypeError):
pass

Expand All @@ -82,7 +59,7 @@ def _mediainfo_screen_size(filename):
def video_screen_size(filename):
"""
Attempts to read the width and height of a video file,
first using mediainfo and then enzyme, and then a custom avi reader
first using opencv and then a custom avi reader

:param filename: full path and filename to a video file
:type: str
Expand All @@ -92,10 +69,9 @@ def video_screen_size(filename):
if filename in bad_files or not is_media_file(filename):
return None, None

# Need to implement mediainfo another way, pymediainfo 2.0 causes segfaults
# It's at pymedia 5 and this was never switched back
for method in [_mediainfo_screen_size, _mkv_screen_size, _avi_screen_size]:
# for method in [_mkv_screen_size, _avi_screen_size]:
# Switch to OpenCV2 as no externals required such as mediainfo
for method in [_opencv2_screen_size, _avi_screen_size]:
# for method in [_opencv2_screen_size, _avi_screen_size]:

screen_size = method(filename)
if screen_size != (None, None):
Expand Down
Loading