print warning if clips are to short

This commit is contained in:
j 2018-02-09 18:07:30 +01:00
parent b056c298a6
commit 0708521a0f
2 changed files with 12 additions and 26 deletions

31
edit.py
View file

@ -147,6 +147,7 @@ if __name__ == '__main__':
credentials = ox.web.auth.get(site) credentials = ox.web.auth.get(site)
except: except:
credentials = {} credentials = {}
print('Please provide your username and password for %s:' % site)
credentials['username'] = input('Username: ') credentials['username'] = input('Username: ')
credentials['password'] = getpass.getpass('Password: ') credentials['password'] = getpass.getpass('Password: ')
ox.web.auth.update(site, credentials) ox.web.auth.update(site, credentials)
@ -157,7 +158,8 @@ if __name__ == '__main__':
for kv in r['data']['errors'].items(): for kv in r['data']['errors'].items():
print('%s: %s' % kv) print('%s: %s' % kv)
sys.exit(1) sys.exit(1)
print('Edit:', edit_id, 'Sort:', sort_by) print('Edit:', edit_id)
print('Sort:', sort_by)
r = api.getEdit(id=edit_id) r = api.getEdit(id=edit_id)
if 'data' not in r: if 'data' not in r:
print(r) print(r)
@ -182,16 +184,19 @@ if __name__ == '__main__':
part_pos = 0 part_pos = 0
for i, duration in enumerate(clip['durations']): for i, duration in enumerate(clip['durations']):
stream_out = stream_in = None
if part_pos + duration < clip['in']: if part_pos + duration < clip['in']:
part_pos += duration part_pos += duration
elif part_pos <= clip['in']: elif part_pos <= clip['in']:
stream_in = clip['in'] - part_pos stream_in = clip['in'] - part_pos
stream_out = min(clip['out'] - part_pos, duration) 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_in = math.ceil(stream_in / (1/25)) * 1/25
stream_out = math.ceil(stream_out / (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) info = get_info(api, clip['streams'][i], clip['item'], i+1)
if stream_out > stream_in: if stream_out > stream_in:
videos.append({ videos.append({
@ -207,27 +212,7 @@ if __name__ == '__main__':
videos[-1]['path'] = os.path.join(prefix, info['path']) videos[-1]['path'] = os.path.join(prefix, info['path'])
if clip_subtitles: if clip_subtitles:
videos[-1]['subtitles'] = '\n'.join(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 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 += clip['duration']
position = math.ceil(position / (1/25)) * 1/25 position = math.ceil(position / (1/25)) * 1/25

View file

@ -61,7 +61,7 @@ for clip in edit:
files.append(out) files.append(out)
src_duration = clip['out']-clip['in'] src_duration = clip['out']-clip['in']
if abs(src_duration-duration) > 1: 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'): if clip.get('subtitles'):
subtitles.append({ subtitles.append({
'in': position, 'in': position,
@ -128,7 +128,9 @@ for clip in edit:
print('try again?:') print('try again?:')
print(' '.join(cmd).replace('-nostats -loglevel error', '')) print(' '.join(cmd).replace('-nostats -loglevel error', ''))
sys.exit(1) 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'): if clip.get('subtitles'):
subtitles.append({ subtitles.append({
'in': position, 'in': position,
@ -136,7 +138,6 @@ for clip in edit:
'value': clip['subtitles'] 'value': clip['subtitles']
}) })
position += duration position += duration
print(out, duration, (clip['out'] - clip['in']))
txt = output + '.txt' txt = output + '.txt'
with open(txt, 'w') as fd: with open(txt, 'w') as fd: