forge: ffmpeg options; file existence handling(#9)

This commit is contained in:
boyska 2014-03-02 00:24:28 +01:00
parent fbf94eceba
commit 037e651d2a
3 changed files with 19 additions and 15 deletions

View file

@ -8,3 +8,4 @@ AUDIO_INPUT_FORMAT = '%Y-%m/%d/rec-%Y-%m-%d-%H-%M-%S.mp3'
AUDIO_OUTPUT_FORMAT = 'techrec-%(time)s-%(name)s.mp3'
FORGE_TIMEOUT = 20
FORGE_MAX_DURATION = 3600*5
FFMPEG_OPTIONS = ['-loglevel', 'warning', '-n', '-nostdin']

View file

@ -13,9 +13,9 @@ def get_timefile_exact(time):
that work is done in get_timefile(time)
'''
return os.path.join(
get_config()['AUDIO_INPUT'],
time.strftime(get_config()['AUDIO_INPUT_FORMAT'])
)
get_config()['AUDIO_INPUT'],
time.strftime(get_config()['AUDIO_INPUT_FORMAT'])
)
def round_timefile(exact):
@ -84,20 +84,22 @@ def mp3_join(named_intervals, target):
if endskip is not None:
cmdline += ['-t', str(len(files)*3600 - (startskip + endskip))]
cmdline += [target]
cmdline += ['-loglevel', 'warning']
return cmdline
def create_mp3(start, end, outfile, options={}, **kwargs):
p = Popen(mp3_join([(get_timefile(begin), start_cut, end_cut)
for begin, start_cut, end_cut
in get_files_and_intervals(start, end)],
outfile))
intervals = [(get_timefile(begin), start_cut, end_cut)
for begin, start_cut, end_cut
in get_files_and_intervals(start, end)]
p = Popen(mp3_join(intervals, outfile) + get_config()['FFMPEG_OPTIONS'])
if os.path.exists(outfile):
raise OSError("file '%s' already exists" % outfile)
if get_config()['FORGE_TIMEOUT'] == 0:
p.wait()
else:
start = datetime.now()
while (datetime.now() - start).total_seconds() < get_config()['FORGE_TIMEOUT']:
while (datetime.now() - start).total_seconds() \
< get_config()['FORGE_TIMEOUT']:
p.poll()
if p.returncode is None:
sleep(1)

View file

@ -13,6 +13,7 @@ ten = datetime(2014, 5, 30, 22)
get_config()['AUDIO_INPUT'] = ''
get_config()['AUDIO_INPUT_FORMAT'] = '%Y-%m/%d/%Y-%m-%d-%H-%M-%S.mp3'
def minutes(n):
return timedelta(minutes=n)
@ -161,29 +162,29 @@ def test_intervals_left_2():
def test_mp3_1():
eq_(' '.join(mp3_join((('a', 0, 0),), 'foo.mp3')),
'ffmpeg -i concat:a -acodec copy foo.mp3 -loglevel warning')
'ffmpeg -i concat:a -acodec copy foo.mp3')
def test_mp3_1_left():
eq_(' '.join(mp3_join((('a', 160, 0),), 'foo.mp3')),
'ffmpeg -i concat:a -acodec copy -ss 160 foo.mp3 -loglevel warning')
'ffmpeg -i concat:a -acodec copy -ss 160 foo.mp3')
def test_mp3_1_right():
eq_(' '.join(mp3_join((('a', 0, 1600),), 'foo.mp3')),
'ffmpeg -i concat:a -acodec copy -t 2000 foo.mp3 -loglevel warning')
'ffmpeg -i concat:a -acodec copy -t 2000 foo.mp3')
def test_mp3_1_leftright():
eq_(' '.join(mp3_join((('a', 160, 1600),), 'foo.mp3')),
'ffmpeg -i concat:a -acodec copy -ss 160 -t 1840 foo.mp3 -loglevel warning')
'ffmpeg -i concat:a -acodec copy -ss 160 -t 1840 foo.mp3')
def test_mp3_2():
eq_(' '.join(mp3_join((('a', 0, 0), ('b', 0, 0)), 'foo.mp3')),
'ffmpeg -i concat:a|b -acodec copy foo.mp3 -loglevel warning')
'ffmpeg -i concat:a|b -acodec copy foo.mp3')
def test_mp3_2_leftright():
eq_(' '.join(mp3_join((('a', 1000, 0), ('b', 0, 1600)), 'foo.mp3')),
'ffmpeg -i concat:a|b -acodec copy -ss 1000 -t 4600 foo.mp3 -loglevel warning')
'ffmpeg -i concat:a|b -acodec copy -ss 1000 -t 4600 foo.mp3')