ffmpeg cmdline generation

This commit is contained in:
boyska 2013-11-29 23:42:27 +01:00
parent 73cb9cc53d
commit 3244793336
2 changed files with 60 additions and 4 deletions

View file

@ -41,13 +41,37 @@ def get_files_and_intervals(start, end, rounder=round_timefile):
start = begin + timedelta(hours=1)
def mp3_join(named_intervals):
def mp3_join(named_intervals, target):
'''
Note that these are NOT the intervals returned by get_files_and_intervals,
as they do not supply a filename, but only a datetime.
What we want in input is basically the same thing, but with get_timefile()
applied on the first element
This function make the (quite usual) assumption that the only start_cut (if
any) is at the first file, and the last one is at the last file
'''
ffmpeg = 'ffmpeg' # binary name
startskip = None
endskip = None
files = []
for (filename, start_cut, end_cut) in named_intervals:
pass
raise NotImplementedError()
# this happens only one time, and only at the first iteration
if start_cut:
assert startskip is None
startskip = start_cut
# this happens only one time, and only at the first iteration
if end_cut:
assert endskip is None
endskip = end_cut
assert '|' not in filename
files.append(filename)
cmdline = [ffmpeg, '-i', 'concat:%s' % '|'.join(files), '-codec:a',
'copy']
if startskip is not None:
cmdline += ['-ss', str(startskip)]
if endskip is not None:
cmdline += ['-to', str(len(files)*3600 - endskip)]
cmdline += [target]
return cmdline

View file

@ -3,7 +3,7 @@ from datetime import datetime, timedelta
from nose.tools import raises, assert_items_equal, eq_
from forge import get_files_and_intervals, get_timefile_exact, round_timefile,\
get_timefile
get_timefile, mp3_join
eight = datetime(2014, 5, 30, 20)
nine = datetime(2014, 5, 30, 21)
@ -152,3 +152,35 @@ def test_intervals_left_2():
eq_(res[0][2], 0)
eq_(res[1][1], 0)
eq_(res[1][2], 3599)
# MP3 Join
def test_mp3_1():
eq_(' '.join(mp3_join((('a', 0, 0),), 'foo.mp3')),
'ffmpeg -i concat:a -codec:a copy foo.mp3')
def test_mp3_1_left():
eq_(' '.join(mp3_join((('a', 160, 0),), 'foo.mp3')),
'ffmpeg -i concat:a -codec:a copy -ss 160 foo.mp3')
def test_mp3_1_right():
eq_(' '.join(mp3_join((('a', 0, 1600),), 'foo.mp3')),
'ffmpeg -i concat:a -codec:a copy -to 2000 foo.mp3')
def test_mp3_1_leftright():
eq_(' '.join(mp3_join((('a', 160, 1600),), 'foo.mp3')),
'ffmpeg -i concat:a -codec:a copy -ss 160 -to 2000 foo.mp3')
def test_mp3_2():
eq_(' '.join(mp3_join((('a', 0, 0), ('b', 0, 0)), 'foo.mp3')),
'ffmpeg -i concat:a|b -codec:a 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 -codec:a copy -ss 1000 -to 5600 foo.mp3')