Fix args passed to videotool. Fixed video.

Encodes at 4Mbps with multiple cores.
This commit is contained in:
Joachim Tingvold 2015-06-02 23:13:26 +02:00
parent 3bdcd1cc66
commit a169bafdd8
2 changed files with 23 additions and 14 deletions

View File

@ -256,16 +256,16 @@ class Photo(object):
def _video_metadata(self, path, original=True): def _video_metadata(self, path, original=True):
p = VideoProbeWrapper().call('-show_format', '-show_streams', '-of', 'json', '-loglevel', '0', path) p = VideoProbeWrapper().call('-show_format', '-show_streams', '-of', 'json', '-loglevel', '0', path)
if p == False: if p == False:
self.is_valid = False self.is_valid = False
return return
info = json.loads(p) info = json.loads(p)
for s in info["streams"]: for s in info["streams"]:
if 'codec_type' in s and s['codec_type'] == 'video': if 'codec_type' in s and s['codec_type'] == 'video':
self._attributes["mediaType"] = "video" self._attributes["mediaType"] = "video"
self._attributes["size"] = (int(s["width"]), int(s["height"])) self._attributes["size"] = (int(s["width"]), int(s["height"]))
if "duration" in s: if "duration" in s:
self._attributes["duration"] = s["duration"] self._attributes["duration"] = s["duration"]
if "tags" in s and "rotate" in s["tags"]: if "tags" in s and "rotate" in s["tags"]:
self._attributes["rotate"] = s["tags"]["rotate"] self._attributes["rotate"] = s["tags"]["rotate"]
@ -403,7 +403,7 @@ class Photo(object):
transcode_path = os.path.join(transcode_path, video_cache(self._path)) transcode_path = os.path.join(transcode_path, video_cache(self._path))
# get number of cores on the system, and use all minus one # get number of cores on the system, and use all minus one
num_of_cores = os.sysconf('SC_NPROCESSORS_ONLN') - 1 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 = [] filters = []
info_string = "%s -> webm" % (os.path.basename(original_path)) info_string = "%s -> webm" % (os.path.basename(original_path))
message("transcoding", info_string) message("transcoding", info_string)
@ -411,7 +411,7 @@ class Photo(object):
self._video_metadata(transcode_path, False) self._video_metadata(transcode_path, False)
return return
if "originalSize" in self._attributes and self._attributes["originalSize"][1] > 720: 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 "rotate" in self._attributes:
if self._attributes["rotate"] == "90": if self._attributes["rotate"] == "90":
filters.append('transpose=1') filters.append('transpose=1')

View File

@ -7,7 +7,14 @@ class VideoToolWrapper(object):
path = args[-1] path = args[-1]
for tool in self.wrappers: for tool in self.wrappers:
try: try:
p = subprocess.check_output((tool,) + args) 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: except KeyboardInterrupt:
if self.cleanup: if self.cleanup:
self.remove(path) self.remove(path)
@ -30,9 +37,11 @@ class VideoToolWrapper(object):
class VideoTranscodeWrapper(VideoToolWrapper): class VideoTranscodeWrapper(VideoToolWrapper):
def __init__(self): def __init__(self):
self.wrappers = ['avconv', 'ffmpeg'] self.wrappers = ['avconv', 'ffmpeg']
self.check_output = False
self.cleanup = True self.cleanup = True
class VideoProbeWrapper(VideoToolWrapper): class VideoProbeWrapper(VideoToolWrapper):
def __init__(self): def __init__(self):
self.wrappers = ['avprobe', 'ffprobe'] self.wrappers = ['avprobe', 'ffprobe']
self.check_output = True
self.cleanup = False self.cleanup = False