Skip to content

Instantly share code, notes, and snippets.

@nngogol
Created February 8, 2019 14:27
Show Gist options
  • Save nngogol/b2194bc2523c5f473b7bb64b127e4747 to your computer and use it in GitHub Desktop.
Save nngogol/b2194bc2523c5f473b7bb64b127e4747 to your computer and use it in GitHub Desktop.
get audio
import os
import ffmpeg
import click
@click.command()
@click.option('-f', '--output_format', default='', help='format of output file')
@click.argument('fname', type=click.Path(exists=True))
def cli(output_format, fname):
'''
Вытягивает аудио дорожку из файла.
Использование:
1.
py get_a.py 1.webm
->>> 1.ogg
2.
py get_a.py 1.mp4
->>> 1.mp4
'''
file, ext = os.path.splitext(fname)
if output_format:
output_file = f'{file}{output_format}'
else:
if 'mp4' in ext:
output_file = f'{file}.acc'
if 'webm' in ext:
output_file = f'{file}.ogg'
ffmpeg.output(ffmpeg.input(fname)['a'], output_file, acodec='copy').run()
# os.system(f'ffmpeg -i "{fname}" -vn -c copy "{output_file}" ')
if __name__ == '__main__':
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment