ffmpeg cmdline generation
This commit is contained in:
parent
73cb9cc53d
commit
3244793336
2 changed files with 60 additions and 4 deletions
|
@ -41,13 +41,37 @@ def get_files_and_intervals(start, end, rounder=round_timefile):
|
||||||
start = begin + timedelta(hours=1)
|
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,
|
Note that these are NOT the intervals returned by get_files_and_intervals,
|
||||||
as they do not supply a filename, but only a datetime.
|
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()
|
What we want in input is basically the same thing, but with get_timefile()
|
||||||
applied on the first element
|
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:
|
for (filename, start_cut, end_cut) in named_intervals:
|
||||||
pass
|
# this happens only one time, and only at the first iteration
|
||||||
raise NotImplementedError()
|
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
|
||||||
|
|
|
@ -3,7 +3,7 @@ from datetime import datetime, timedelta
|
||||||
from nose.tools import raises, assert_items_equal, eq_
|
from nose.tools import raises, assert_items_equal, eq_
|
||||||
|
|
||||||
from forge import get_files_and_intervals, get_timefile_exact, round_timefile,\
|
from forge import get_files_and_intervals, get_timefile_exact, round_timefile,\
|
||||||
get_timefile
|
get_timefile, mp3_join
|
||||||
|
|
||||||
eight = datetime(2014, 5, 30, 20)
|
eight = datetime(2014, 5, 30, 20)
|
||||||
nine = datetime(2014, 5, 30, 21)
|
nine = datetime(2014, 5, 30, 21)
|
||||||
|
@ -152,3 +152,35 @@ def test_intervals_left_2():
|
||||||
eq_(res[0][2], 0)
|
eq_(res[0][2], 0)
|
||||||
eq_(res[1][1], 0)
|
eq_(res[1][1], 0)
|
||||||
eq_(res[1][2], 3599)
|
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')
|
||||||
|
|
Loading…
Reference in a new issue