Per dividere un file audio di grandi dimensioni in una serie di tracce con lunghezze variabili, è possibile utilizzare il comando seguente:
# -to is the end time of the sub-file
ffmpeg -i BIG_FILE -acodec copy -ss START_TIME -to END_TIME LITTLE_FILE
Ad esempio, ho suddiviso un singolo file .opus della colonna sonora originale di Inception in sotto-file usando questo file di testo contenente inizio, fine, nome:
00:00:00 00:01:11 01_half_remembered_dream
00:01:11 00:03:07 02_we_built_our_own_world
00:03:07 00:05:31 03_dream_is_collapsing
00:05:31 00:09:14 04_radical_notion
00:09:14 00:16:58 05_old_souls
00:16:58 00:19:22 06
00:19:22 00:24:16 07_mombasa
00:24:16 00:26:44 08_one_simple_idea
00:26:44 00:31:49 09_dream_within_a_dream
00:31:49 00:41:19 10_waiting_for_a_train
00:41:19 00:44:44 11_paradox
00:44:44 00:49:20 12_time
Ho scritto questo breve awkprogramma per leggere il file di testo e creare ffmpegcomandi da ogni riga:
{
# make ffmpeg command string using sprintf
cmd = sprintf("ffmpeg -i inception_ost.opus -acodec copy -ss %s -to %s %s.opus", $1, $2, $3)
# execute ffmpeg command with awk's system function
system(cmd)
}
Ecco una pythonversione più dettagliata del programma chiamato split.py, in cui ora sia il file di traccia originale che il file di testo che specifica le sottotracce vengono letti dalla riga di comando:
import subprocess
import sys
def main():
"""split a music track into specified sub-tracks by calling ffmpeg from the shell"""
# check command line for original file and track list file
if len(sys.argv) != 3:
print 'usage: split <original_track> <track_list>'
exit(1)
# record command line args
original_track = sys.argv[1]
track_list = sys.argv[2]
# create a template of the ffmpeg call in advance
cmd_string = 'ffmpeg -i {tr} -acodec copy -ss {st} -to {en} {nm}.opus'
# read each line of the track list and split into start, end, name
with open(track_list, 'r') as f:
for line in f:
# skip comment and empty lines
if line.startswith('#') or len(line) <= 1:
continue
# create command string for a given track
start, end, name = line.strip().split()
command = cmd_string.format(tr=original_track, st=start, en=end, nm=name)
# use subprocess to execute the command in the shell
subprocess.call(command, shell=True)
return None
if __name__ == '__main__':
main()
È possibile creare facilmente ffmpegchiamate sempre più complicate modificando il modello di comando e / o aggiungendo più campi a ciascuna riga del file track_list.