Created
August 22, 2018 12:58
-
-
Save khuangaf/3aaa7100764a5ce23c509c77a6d97490 to your computer and use it in GitHub Desktop.
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
def extract_audio(video_id,videos_dir, audios_dir): | |
""" | |
Download the videos | |
Parameters | |
---------- | |
video_id : str | |
A Youtube video id. | |
videos_dir: str | |
The directory which stores videos. | |
audios_dir: str | |
The directory which stores audios. | |
""" | |
video_path = f'{videos_dir}/{video_id}.mp4' | |
audio_path = f'{audios_dir}/{video_id}.mp3' | |
#-i: it is the path to the input file. The second option -f mp3 tells ffmpeg that the ouput is in mp3 format. | |
#-ab 192000: we want the output to be encoded at 192Kbps | |
#-vn :we dont want video. | |
# execute the command | |
cmd = f'ffmpeg -i {video_path} -f mp3 -ab 192000 -vn -y {audio_path}'.split(" ") | |
subprocess.call(cmd, shell=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment