From 0708521a0f8c6c8b4db6bd97ba29a9d686edb235 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 9 Feb 2018 18:07:30 +0100 Subject: [PATCH] print warning if clips are to short --- edit.py | 31 ++++++++----------------------- ffmpeg.py | 7 ++++--- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/edit.py b/edit.py index b43a22e..fcf32f6 100755 --- a/edit.py +++ b/edit.py @@ -147,6 +147,7 @@ if __name__ == '__main__': credentials = ox.web.auth.get(site) except: credentials = {} + print('Please provide your username and password for %s:' % site) credentials['username'] = input('Username: ') credentials['password'] = getpass.getpass('Password: ') ox.web.auth.update(site, credentials) @@ -157,7 +158,8 @@ if __name__ == '__main__': for kv in r['data']['errors'].items(): print('%s: %s' % kv) sys.exit(1) - print('Edit:', edit_id, 'Sort:', sort_by) + print('Edit:', edit_id) + print('Sort:', sort_by) r = api.getEdit(id=edit_id) if 'data' not in r: print(r) @@ -182,16 +184,19 @@ if __name__ == '__main__': part_pos = 0 for i, duration in enumerate(clip['durations']): + stream_out = stream_in = None if part_pos + duration < clip['in']: part_pos += duration elif part_pos <= clip['in']: stream_in = clip['in'] - part_pos stream_out = min(clip['out'] - part_pos, duration) + elif clip['out'] > part_pos: + stream_in = 0 + stream_out = min(clip['out'] - part_pos, duration) + if stream_in is not None and stream_out is not None: stream_in = math.ceil(stream_in / (1/25)) * 1/25 stream_out = math.ceil(stream_out / (1/25)) * 1/25 - - part_pos += duration info = get_info(api, clip['streams'][i], clip['item'], i+1) if stream_out > stream_in: videos.append({ @@ -207,27 +212,7 @@ if __name__ == '__main__': videos[-1]['path'] = os.path.join(prefix, info['path']) if clip_subtitles: videos[-1]['subtitles'] = '\n'.join(clip_subtitles) - elif clip['out'] > part_pos: - stream_in = 0 - stream_out = min(clip['out'] - part_pos, duration) - stream_in = math.ceil(stream_in / (1/25)) * 1/25 - stream_out = math.ceil(stream_out / (1/25)) * 1/25 part_pos += duration - info = get_info(api, clip['streams'][i], clip['item'], i+1) - if stream_out > stream_in: - videos.append({ - 'oshash': clip['streams'][i], - 'url': '%s/%s/%sp%s.mp4' % (base_url, clip['item'], stream_resolution, i), - 'resolution': info['resolution'], - 'item': clip['item'], - 'annotation': clip.get('annotation'), - 'in': stream_in, - 'out': stream_out, - }) - if 'path' in info: - videos[-1]['path'] = os.path.join(prefix, info['path']) - if clip_subtitles: - videos[-1]['subtitles'] = '\n'.join(clip_subtitles) position += clip['duration'] position = math.ceil(position / (1/25)) * 1/25 diff --git a/ffmpeg.py b/ffmpeg.py index 07a4815..2525f98 100755 --- a/ffmpeg.py +++ b/ffmpeg.py @@ -61,7 +61,7 @@ for clip in edit: files.append(out) src_duration = clip['out']-clip['in'] if abs(src_duration-duration) > 1: - print(clip.get('annotation', clip['item']), src_duration, duration) + print(clip.get('annotation', clip['item']), 'expected', src_duration, 'got', duration, out) if clip.get('subtitles'): subtitles.append({ 'in': position, @@ -128,7 +128,9 @@ for clip in edit: print('try again?:') print(' '.join(cmd).replace('-nostats -loglevel error', '')) sys.exit(1) - print(clip, duration, clip['out']-clip['in']) + src_duration = clip['out']-clip['in'] + if abs(src_duration-duration) > 1: + print(clip.get('annotation', clip['item']), 'expected', src_duration, 'got', duration, out) if clip.get('subtitles'): subtitles.append({ 'in': position, @@ -136,7 +138,6 @@ for clip in edit: 'value': clip['subtitles'] }) position += duration - print(out, duration, (clip['out'] - clip['in'])) txt = output + '.txt' with open(txt, 'w') as fd: