Para dividir un gran archivo de audio en un conjunto de pistas con diferentes longitudes, puede usar el siguiente comando:
# -to is the end time of the sub-file
ffmpeg -i BIG_FILE -acodec copy -ss START_TIME -to END_TIME LITTLE_FILE
Por ejemplo, dividí un solo archivo .opus de la banda sonora original de inicio en subarchivos usando este archivo de texto que contiene inicio, fin y nombre:
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
Escribí este breve awkprograma para leer el archivo de texto y crear ffmpegcomandos desde cada línea:
{
# 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)
}
Aquí hay una pythonversión más detallada del programa llamado split.py, donde ahora tanto el archivo de pista original como el archivo de texto que especifica subpistas se leen desde la línea de comandos:
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()
Puede crear fácilmente ffmpegllamadas cada vez más complicadas modificando la plantilla de comando y / o agregando más campos a cada línea del archivo track_list.