Created
December 7, 2021 22:06
-
-
Save dougboutwell/56a0f123aea2118f96e38bcdb3aee58f to your computer and use it in GitHub Desktop.
Extract audio from typical YouTube video files with 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
#!/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