Reputation: 21
I'm working on a YouTube-Downloader project and I'm having issues with my audio files. My code uses pytube to download the audio from a video.
The problem is that the downloaded audio file is either a .webm or a .mp4 file, which I'd like to convert to a .mp3 file. Is there a way to read the filetype (webm/mp4) first and then run a code that converts it to a mp3 file?
I'd like to run it as a script in pycharm. Not as a command in the console.
Thanks for your answers.
Das Typ
Upvotes: 2
Views: 16708
Reputation: 21
Make sure you have installed ffmpeg correctly,and set the environment path for it.
For windows;
Install ffmpeg from here
Extract it under the root directory C:\
Set the environment path variable by typing this command in your cmd
setx /m PATH "C:\ffmpeg\bin;%PATH%"
Be sure that the extracted folder name is ffmpeg
(You can test if it is installed by typing this into cmd:)
ffmpeg -version
Now you can use ffmpeg from cmd by running subprocess module:
import subprocess
path = '[yourmp4fileaddress]'
subprocess.run('ffmpeg -i "path/filename".mp4 "filename".mp3',shell=True)
just in case in you want to print the output of the above command in your compiler:
import subprocess
path = '[yourpathaddress]'
print(subprocess.run('ffmpeg -i "path/filename".mp4 "filename".mp3',shell=True,capture_output=True))
Upvotes: 2