如何在预定义的时间将音频文件分成多个章节

时间:2019-03-29 22:32:55

标签: awk sed ffmpeg

在给定的元数据预定义时间的情况下,如何轻松拆分10章中的有声读物文件 ch0 0.000000,3472.683000秒

3472.683000,7642.058000 ch1

等等。

2列,每章的开头和结尾,

我是虚拟的,但尝试并无法通过awk左右添加列以获取命令行

    ffmpeg -i output.mp3  -acodec copy -ss  begin -to end  ch'number'.mp3.

NF位置问题,然后增加新输出文件的数量

如何使用awk或sed并计算新文件名ch01 ch02等

2 个答案:

答案 0 :(得分:0)

每个预定义章节的“开始”和“结束”时间,目的:10个ffmpeg命令行将其拆分

    ffmpeg -i audiofile.mp3  -acodec copy -ss begin to end  ch'number'.mp3

首先在开头添加带有sed的模式-i output.mp3 -acodec copy -ss

    sed  -e '1,$s/^/ -i audiofile.mp3  -acodec copy -ss' file1 > file2 #file1 :contains 2 columns of begin and end time 

结果

    -i audiofile.mp3  -acodec copy -ss begin, end  

second用g全局将','替换为'-to'

    sed s'/, / -to /g' file2 > file3

我们将拥有

    -i audiofile.mp3  -acodec copy -ss begin -to end

带有awk的第三增量计数器

    awk '{$(NF+1) = "ch"(NR-1)".mp3"} 1' file3 > file4

我们获得ch0.mp3 ch1.mp3 ..ch10.mp3

     -i audiofile.mp3 -acodec copy -ss begin -to end ch'number'.mp3 

ffmpeg从文件4读取输入

    ffmpeg $(cat file4)

您将有10章

答案 1 :(得分:0)

段多路复用器就是为此目的而设计的。

ffmpeg -i output.mp3 -c copy -f segment -segment_times 0,3472.683,7642.058 -segment_start_number 1 ch%d.mp3

我已经添加了前三章的时间。此命令将创建ch1.mp3,ch2.mp3,ch3.mp3。