Created
June 17, 2019 11:00
-
-
Save NazmusShakib/08a9835701bb3d723e9da8a6725d3b28 to your computer and use it in GitHub Desktop.
Merge multiple audio files along with silence using ffmpeg.
This file contains hidden or 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
import subprocess | |
import json | |
def main(): | |
jsonfilename = 'source_list.json' | |
with open(jsonfilename) as f: | |
data = json.load(f) | |
inFiles = data["read_info"]["files"] | |
outFile = data["write_info"]["file"] | |
ffmpeg_args = data["ffmpeg_args"] | |
# prepare the ffmpeg_args | |
for i in range(len(inFiles) + 1): | |
replace_str = '%' + str(i) + '%' | |
if replace_str in ffmpeg_args: | |
ffmpeg_args = ffmpeg_args.replace(replace_str, inFiles[i - 1]) | |
# replace the output file name | |
if '%OUTFILE%' in ffmpeg_args: | |
ffmpeg_args = ffmpeg_args.replace('%OUTFILE%', outFile) | |
# print(ffmpeg_args) | |
# subprocess.check_output(cmd, shell=True) | |
subprocess.call('ffmpeg ' + ffmpeg_args, shell=True) | |
main() |
This file contains hidden or 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
{ | |
"read_info": {"bucket":"lentil2-dev", | |
"files": [ | |
"audio1.aac", | |
"audio2.aac", | |
"audio3.aac" | |
] | |
}, | |
"write_info": { | |
"bucket":"lentil2-dev", | |
"file":"merged_audio" | |
}, | |
"ffmpeg_args": "-f lavfi -t 0.731 -i anullsrc=channel_layout=mono:sample_rate=48000 -i %1% -f lavfi -t 7.949 -i anullsrc=channel_layout=mono:sample_rate=48000 -i %2% -f lavfi -t 13.049 -i anullsrc=channel_layout=mono:sample_rate=48000 -i %3% -filter_complex concat=n=6:v=0:a=1[audio] -map [audio] -y -t 120.207 %OUTFILE%.mp4" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment