Created
December 16, 2018 15:17
-
-
Save thienandangthanh/2573ed7ec8d6d202605155ba792ca5d3 to your computer and use it in GitHub Desktop.
Spliting mp3 file in to multiple files with different lenghts defined in CSV file with ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from argparse import ArgumentParser | |
import csv, sys, subprocess, os.path | |
def main(argv): | |
parser = ArgumentParser(description='A tool spliting mp3 file in to multiple files with different lenghts defined in CSV file', | |
epilog="Example: multi-split.py 00:00:25.500,00:00:27.500 test.mp3") | |
parser.add_argument('input_audio', help='source file to split') | |
parser.add_argument('CSV_file', help='file contains: start, stop time, ouput file name') | |
args = parser.parse_args() | |
input_file = str(args.input_audio); | |
output_folder = str(str(args.CSV_file) + '_output'); | |
with open(str(args.CSV_file), 'r') as f: | |
reader = csv.reader(f) | |
your_list = list(reader) | |
if(not os.path.isdir(output_folder)): | |
subprocess.call(['mkdir', output_folder]); | |
for info in your_list: | |
subprocess.call('ffmpeg -i \''+ input_file +'\' -vn -acodec copy -ss \''+ str(info[0]) +'\' -to '+ info[1] +' '+ | |
output_folder + '/' + str(args.CSV_file) + '-' + str(info[2]) + '.mp3', shell=True); | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment