From 54f47ecd06922d9c875bad403bbbe9968a5b4a3e Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Sun, 5 May 2019 20:41:25 +0200 Subject: [PATCH] prosopopee: add ratio property for videos To prepare for an alignment fix that requires to know the ratio of the video screenshot, let's add a ratio property. This property is calling `ffprobe` or `avprobe` depending on whether ffmpeg or libav-tools was installed. It is not adding a new dependency. The output of this particular `ffprobe` or `avprobe` returns the width and height of the video, separated by a comma. Signed-off-by: Quentin Schulz --- prosopopee/prosopopee.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index dfc474e..93899be 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -140,6 +140,17 @@ class Video(object): return thumbnail_name + @property + def ratio(self): + if self.options["binary"] == "ffmpeg": + binary = "ffprobe" + else: + binary = "avprobe" + command = binary + " -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 " + self.base_dir.joinpath(self.name) + out = subprocess.check_output(command.split()) + width,height = out.split(',') + return float(width) / int(height) + def __repr__(self): return self.name