From a169bafdd82ec2f7e80ca8017a4eadaa2a676606 Mon Sep 17 00:00:00 2001 From: Joachim Tingvold Date: Tue, 2 Jun 2015 23:13:26 +0200 Subject: [PATCH] Fix args passed to videotool. Fixed video. Encodes at 4Mbps with multiple cores. --- scanner/PhotoAlbum.py | 24 ++++++++++++------------ scanner/VideoToolWrapper.py | 13 +++++++++++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/scanner/PhotoAlbum.py b/scanner/PhotoAlbum.py index 6004d71..52ae647 100644 --- a/scanner/PhotoAlbum.py +++ b/scanner/PhotoAlbum.py @@ -256,16 +256,16 @@ class Photo(object): def _video_metadata(self, path, original=True): - p = VideoProbeWrapper().call('-show_format', '-show_streams', '-of', 'json', '-loglevel', '0', path) - if p == False: - self.is_valid = False - return - info = json.loads(p) - for s in info["streams"]: - if 'codec_type' in s and s['codec_type'] == 'video': - self._attributes["mediaType"] = "video" - self._attributes["size"] = (int(s["width"]), int(s["height"])) - if "duration" in s: + p = VideoProbeWrapper().call('-show_format', '-show_streams', '-of', 'json', '-loglevel', '0', path) + if p == False: + self.is_valid = False + return + info = json.loads(p) + for s in info["streams"]: + if 'codec_type' in s and s['codec_type'] == 'video': + self._attributes["mediaType"] = "video" + self._attributes["size"] = (int(s["width"]), int(s["height"])) + if "duration" in s: self._attributes["duration"] = s["duration"] if "tags" in s and "rotate" in s["tags"]: self._attributes["rotate"] = s["tags"]["rotate"] @@ -403,7 +403,7 @@ class Photo(object): transcode_path = os.path.join(transcode_path, video_cache(self._path)) # get number of cores on the system, and use all minus one num_of_cores = os.sysconf('SC_NPROCESSORS_ONLN') - 1 - transcode_cmd = ['-i', original_path, '-c:v', 'libvpx', '-crf', '10', '-b:v', '800k', '-c:a', 'libvorbis', '-f', 'webm', '-threads', num_of_cores, '-loglevel', '0', '-y'] + transcode_cmd = ['-i', original_path, '-c:v', 'libvpx', '-crf', '10', '-b:v', '4M', '-c:a', 'libvorbis', '-f', 'webm', '-threads', str(num_of_cores), '-loglevel', '0', '-y'] filters = [] info_string = "%s -> webm" % (os.path.basename(original_path)) message("transcoding", info_string) @@ -411,7 +411,7 @@ class Photo(object): self._video_metadata(transcode_path, False) return if "originalSize" in self._attributes and self._attributes["originalSize"][1] > 720: - filters.append("scale=trunc(oh*a/2)*2:min(720\,iw)") + filters.append("scale='trunc(oh*a/2)*2:min(720\,iw)'") if "rotate" in self._attributes: if self._attributes["rotate"] == "90": filters.append('transpose=1') diff --git a/scanner/VideoToolWrapper.py b/scanner/VideoToolWrapper.py index 0e8518e..5f63c92 100644 --- a/scanner/VideoToolWrapper.py +++ b/scanner/VideoToolWrapper.py @@ -6,8 +6,15 @@ class VideoToolWrapper(object): def call(self, *args): path = args[-1] for tool in self.wrappers: - try: - p = subprocess.check_output((tool,) + args) + try: + if self.check_output: + p = subprocess.check_output((tool,) + args) + else: + p = subprocess.call((tool,) + args) + if p > 0: + return False + else: + return "SUCCESS" except KeyboardInterrupt: if self.cleanup: self.remove(path) @@ -30,9 +37,11 @@ class VideoToolWrapper(object): class VideoTranscodeWrapper(VideoToolWrapper): def __init__(self): self.wrappers = ['avconv', 'ffmpeg'] + self.check_output = False self.cleanup = True class VideoProbeWrapper(VideoToolWrapper): def __init__(self): self.wrappers = ['avprobe', 'ffprobe'] + self.check_output = True self.cleanup = False