| You can use ffmpeg to convert a video file to an MP3 audio file with a simple command. Here’s a straightforward example: ffmpeg -i input_video.mp4 -vn -acodec libmp3lame -q:a 2 output_audio.mp3
Explanation of Options -i input_video.mp4: Specifies the input video file.-vn: Tells ffmpeg to ignore the video stream (extract only audio).-acodec libmp3lame: Sets the audio codec to libmp3lame, which is a common codec for MP3 encoding.-q:a 2: Controls the audio quality. Lower values give better quality (2 is typically very good; you can adjust from 0–9, with 0 being the best).output_audio.mp3: Specifies the output file name in MP3 format.
Example in Python You can also use ffmpeg in Python via the subprocess module or with the ffmpeg-python library. Here’s an example using ffmpeg-python: import ffmpeg
# Convert video to mp3
ffmpeg.input('input_video.mp4').output('output_audio.mp3', **{'vn': None, 'q:a': 2}).run()
This script will read input_video.mp4 and output output_audio.mp3 with the specified quality. |