Skip to content

Instantly share code, notes, and snippets.

@kashefy
Last active May 26, 2016 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kashefy/9ec6204356583e42a11398d7300be2ed to your computer and use it in GitHub Desktop.
Save kashefy/9ec6204356583e42a11398d7300be2ed to your computer and use it in GitHub Desktop.
downsample sound files using ffmpeg
def is_wav(p):
return os.path.splitext(p)[-1] == '.wav'
def lower_samplerate_cmds(dir_src, samplerate, dir_dst, fpath_exec_script):
paths = fs.gen_paths(dir_src, is_wav)
commands = []
for fpath in paths:
path_dst = os.path.join(dir_dst, os.path.basename(fpath))
cmd = ['ffmpeg', '-i', fpath, '-ac', '2', '-ar', "%d" % (samplerate,), path_dst]
commands.append(cmd)
commands = [list2cmdline(cmd) for cmd in commands]
with open(fpath_exec_script, 'w') as f:
for cmd in commands:
f.write('%s\n' % (cmd,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment