Skip to content

Instantly share code, notes, and snippets.

@dougboutwell
Created December 7, 2021 22:06
Show Gist options
  • Save dougboutwell/56a0f123aea2118f96e38bcdb3aee58f to your computer and use it in GitHub Desktop.
Save dougboutwell/56a0f123aea2118f96e38bcdb3aee58f to your computer and use it in GitHub Desktop.
Extract audio from typical YouTube video files with ffmpeg
#!/usr/bin/python
import os
import sys
import subprocess
import argparse
parser = argparse.ArgumentParser(description="Extract audio from video files")
parser.add_argument("files", metavar="file", nargs="+")
parser.add_argument("-w", "--wav", dest="codec", action="store_const", const="pcm_s16le", default="copy")
args = parser.parse_args()
for a in args.files:
print a
ext = ".m4a" if args.codec is "copy" else ".wav"
outfile = os.path.splitext(a)[0] + ext
cmd = ['ffmpeg',
'-i', a,
'-vn', '-acodec', args.codec,
outfile]
subprocess.check_call(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment