From 8a8c09dc0714743541a5e49d39fc3b6cace7c3e8 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 15 Nov 2018 11:56:03 +0000 Subject: [PATCH 1/3] use source aspect ratio --- ffmpeg.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ffmpeg.py b/ffmpeg.py index 2e47217..6ae4415 100755 --- a/ffmpeg.py +++ b/ffmpeg.py @@ -72,6 +72,10 @@ for clip in edit: continue src_info = ox.avinfo(clip['path']) clip_aspect = src_info['video'][0]['width'] / src_info['video'][0]['height'] + if 'display_aspect_ratio' in src_info['video'][0]: + ratio = [int(p) for p in src_info['video'][0]['display_aspect_ratio'].split(':')] + clip_aspect = ratio[0] / ratio[1] + print(ratio, clip_aspect) if clip_aspect < aspect: x = width y = int(x / clip_aspect) From 09e1f2833c24397583309c0ec79c2976d36f1dee Mon Sep 17 00:00:00 2001 From: j Date: Thu, 15 Nov 2018 11:57:26 +0000 Subject: [PATCH 2/3] add render mode on pandora server --- edit.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/edit.py b/edit.py index 83ad2dd..301760d 100755 --- a/edit.py +++ b/edit.py @@ -7,6 +7,7 @@ import os import sys import urllib.parse import urllib.request +from glob import glob import ox import ox.web.auth @@ -100,24 +101,37 @@ def sort_clips(edit, sort): s = sorted(clips, key=lambda c: ids.index(c['id']) if c['id'] in ids else -1) return s -def cache_clips(api, videos, use_source=False): +def get_pandora_media_path(oshash): + h = oshash + path = '/srv/pandora/data/media/' + '/'.join([h[:2], h[2:4], h[4:6], h[6:]]) + path = glob('%s/data.*' % path) + if path: + path = path[0] + else: + path = ox.sorted_strings(glob('%s/*.mp4' % path))[-1] + return path + +def cache_clips(api, videos, use_source=False, use_pandora=False): for clip in videos: out = '%s/%s.mp4' % (render, clip['oshash']) if 'path' in clip: clip['src'] = clip['path'] clip['path'] = out if not os.path.exists(out): - url = clip['url'] - if use_source: - name = url.split('/')[-1].split('.')[0] - resolution, part = name.split('p') - if part and part.isdigit(): - part = int(part) - else: - part = 1 - url = '/'.join(url.split('/')[:-1] + ['download', 'source', str(part)]) - print(url, out) - api.save_url(url, out) + if use_pandora: + os.symlink(get_pandora_media_path(clip['oshash']), out) + else: + url = clip['url'] + if use_source: + name = url.split('/')[-1].split('.')[0] + resolution, part = name.split('p') + if part and part.isdigit(): + part = int(part) + else: + part = 1 + url = '/'.join(url.split('/')[:-1] + ['download', 'source', str(part)]) + print(url, out) + api.save_url(url, out) if __name__ == '__main__': @@ -138,6 +152,7 @@ if __name__ == '__main__': edit_url = opts.url use_local = opts.source == 'local' use_source = opts.source == 'source' + use_pandora = opts.source == 'pandora' prefix = opts.prefix parts = edit_url.split('/') site = parts[2] @@ -238,7 +253,7 @@ if __name__ == '__main__': position = math.ceil(position / (1/25)) * 1/25 if not use_local: - cache_clips(api, videos, use_source) + cache_clips(api, videos, use_source, use_pandora) name = normalize(edit_id) if sort_by != 'year': From 60786749ec3c3ba12ad116f4f71fcda58fa1dc18 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 15 Nov 2018 12:10:59 +0000 Subject: [PATCH 3/3] pass output filename --- edit.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/edit.py b/edit.py index 301760d..f4ccfdf 100755 --- a/edit.py +++ b/edit.py @@ -146,6 +146,9 @@ if __name__ == '__main__': parser.add_argument('-c', '--config', dest='config', help='config.json containing config', default='~/.ox/client.json') + parser.add_argument('-o', '--output', dest='output', + help='json output', + default='') parser.add_argument('url', metavar='url', type=str, help='edit url') opts = parser.parse_args() @@ -255,9 +258,12 @@ if __name__ == '__main__': if not use_local: cache_clips(api, videos, use_source, use_pandora) - name = normalize(edit_id) - if sort_by != 'year': - name += '_' + sort_by + if opts.output: + name = opts.output.replace('.json', '') + else: + name = normalize(edit_id) + if sort_by != 'year': + name += '_' + sort_by if subtitles: with open('%s.srt' % name, 'wb') as fd: fd.write(ox.srt.encode(subtitles))