From 0b30bf82d4e75ae5300530e4e946a9c1d98e518d Mon Sep 17 00:00:00 2001 From: Fabrice Quenneville Date: Thu, 19 Nov 2020 23:09:28 -0500 Subject: [PATCH] Improved detection methods --- mediacurator/library/video.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mediacurator/library/video.py b/mediacurator/library/video.py index 325da36..025edda 100644 --- a/mediacurator/library/video.py +++ b/mediacurator/library/video.py @@ -177,20 +177,6 @@ class Video(): - @staticmethod - def detect_codec(filepath): - try: - args = ["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=codec_name", "-of", "default=noprint_wrappers=1:nokey=1", str(filepath)] - output = subprocess.check_output(args, stderr=subprocess.STDOUT) - - # decoding from binary, stripping whitespace, keep only last line - # in case ffmprobe added error messages over the requested information - output = output.decode().strip().splitlines()[-1] - except (subprocess.CalledProcessError, IndexError): - return False - return output - - @staticmethod def detect_fferror(filepath): try: @@ -205,14 +191,28 @@ class Video(): @staticmethod - def detect_resolution(filepath): + def detect_codec(filepath): try: - args = ["ffprobe","-v","error","-select_streams","v:0", "-show_entries","stream=width,height","-of","csv=s=x:p=0",str(filepath)] + args = ["ffprobe", "-v", "quiet", "-select_streams", "v:0", "-show_entries", "stream=codec_name", "-of", "default=noprint_wrappers=1:nokey=1", str(filepath)] output = subprocess.check_output(args, stderr=subprocess.STDOUT) # decoding from binary, stripping whitespace, keep only last line # in case ffmprobe added error messages over the requested information - output = output.decode().strip().splitlines()[-1] + output = output.decode().strip() + except (subprocess.CalledProcessError, IndexError): + return False + return output + + + @staticmethod + def detect_resolution(filepath): + try: + args = ["ffprobe","-v","quiet","-select_streams","v:0", "-show_entries","stream=width,height","-of","csv=s=x:p=0",str(filepath)] + output = subprocess.check_output(args, stderr=subprocess.STDOUT) + + # decoding from binary, stripping whitespace, keep only last line + # in case ffmprobe added error messages over the requested information + output = output.decode().strip() # See if we got convertable data output = [int(output.split("x")[0]), int(output.split("x")[1])]