AUDIO > couper un morceau sans reconversion

ffmpeg -i monGrosFichier -acodec copy -ss DEB_TEMPS -to FIN_TEMPS monPetitFichier

Exemple, couper en plusieurs fichier, un gros fichier avec les références temps (début, fin, titre) :

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

Avec awk, on lit le fichier texte, et on appelle ffmpeg pour chaque ligne:

{
    # rendre la commande ffmpeg chainable avec sprintf
    cmd = sprintf("ffmpeg -i inception_ost.opus -acodec copy -ss %s -to %s %s.opus", $1, $2, $3)

    # executer ffmpeg avec la fonction system de awk
    system(cmd)
}

Version python du script :

import subprocess
import sys

def main():
    # vérifie si le fichier original ainsi que le fichier texte sont passés en argument
    if len(sys.argv) != 3:
        print 'usage: split <original_track> <track_list>'
        exit(1)

    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()

subprocess.call(command) équivaut à system(command) dans awk.

Voici un version compacte en bash. Modifier le temps par ceux nécessaires :

source="source audio file.m4a"
i=0
t1=0:00
for end_time in 1:24 5:40 14:48 19:33 35:11 40:00 46:08 51:58 '' ; do
   i=$((i+1))
   t0=$t1 t1=$end_time
   ffmpeg -i "$source" -acodec copy -ss $t0 ${t1:+-to} $t1 $(printf "track%02d.%s" $i ${source##*.})
done

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *