How to convert from MP4 to MP3 for free: Script to achieve it easily in Python.

Introduction: Inconveniences and Challenges of Conversion Free Software

MP4 can be played on many platforms and devices and is a standard on video sites such as YouTube. There are many situations in which you may want to “convert MP4 to MP3. For example, there may be the following cases

You want to extract only the audio files from a recording of an interview or meeting minutes
After recording a meeting or interview on Zoom, Teams, etc., you want to extract only the audio and run it through a transcription tool, as you do not need the video.

You want to make efficient use of language learning and audio content.
Record a YouTube or online lecture, convert it to MP3 format, and play it back on your smartphone while learning.

When you want to use podcasts or music as material for editing.
When you want to use video content as audio material. For example, when you want to extract and re-edit only the background music or talk parts.

However, when using many free sites, you may face the following problems

Claiming to be “free” but leading you to a paid plan
In many cases, even if the conversion appears to be free at first, there is a capacity limit or a limit on the number of times the conversion can be performed, and “billing required” is indicated in the middle of the conversion.

Multiple files cannot be converted in batches and must be uploaded manually one file at a time.
Many free online tools allow only one file at a time to be uploaded, so when multiple files are to be converted, the process of uploading, converting, and downloading must be repeated.

To solve these problems, I will show you how to quickly convert MP4 to MP3 on your own computer using a simple script in Python.

MP4 to MP3 conversion script using Python

This script uses a Python library called Pydub to convert MP4 files to MP3 format. Multiple files can be converted at once, and conversion speed and quality can be freely adjusted.

Required Preparation

First, install Pydub, the required library. Execute the following command

pip install pydub

Pydub also requires ffmpeg, an audio processing library. Install ffmpeg with the following command (example using Homebrew).

Mac:.

brew install ffmpeg

Windows: Windows

Download the installer from the official ffmpeg website and pass it through.

MP4 to MP3 conversion script example

The following script allows you to batch convert MP4 files in a specified directory to MP3. The paths are set up in a generic way so that anyone can easily modify them to suit their own environment.

from pydub import AudioSegment
import os

# MP4ファイルが保存されているディレクトリ
mp4_directory = "./input_mp4"

# MP3ファイルを保存するディレクトリ
mp3_directory = "./output_mp3"

# 出力ディレクトリが存在しない場合は作成
os.makedirs(mp3_directory, exist_ok=True)

# 指定ディレクトリ内のすべてのMP4ファイルを取得
mp4_files = [f for f in os.listdir(mp4_directory) if f.endswith('.mp4')]

for mp4_file in mp4_files:
    # MP4ファイルを読み込み
    audio = AudioSegment.from_file(os.path.join(mp4_directory, mp4_file), format="mp4")

    # サンプルレートを20KHzに変更(必要に応じて調整可能)
    audio = audio.set_frame_rate(20000)

    # MP3として保存
    audio.export(os.path.join(mp3_directory, mp4_file.replace('.mp4', '.mp3')), format="mp3")

print("変換が完了しました!")

How to use Python scripts

  1. Save the MP4 file you wish to convert in the MP4 file directory: mp4_directory (e.g. ./input_mp4 ).
  2. Save the converted MP3 file to: mp3_directory (e.g. ./output_mp3 ).
  3. Run the script: Running the above code in Python will convert all the specified MP4 files to MP3 and save them in the specified folder.

Advantages of Using Python Scripts

  1. Free of charge: In this way, you do not have to worry about being directed to a paid site.
  2. Batch conversion of multiple files is possible: all MP4 files in a folder are automatically converted to MP3.
  3. Quality can also be adjusted: Sample rate and bit rate can be freely changed to control audio quality.
  4. Can be executed offline: No Internet environment is required, so work can be performed with peace of mind.

Click here for an article on “How to compress for free: a script to easily achieve this in Python “.

If you want to transcribe audio files, “Interview AI” is recommended.

If, after converting to MP3 audio files, you would like to further transcribe them, Interview AI is recommended.

With Interview AI, an hour-long audio file can be transcribed in just 15 seconds and automatically corrected to a natural conversational format.

If you need to transcribe a long audio file, we encourage you to try Interview AI for free.

summary

Relying on online free sites often has unexpected limitations and hassles, but Python scripts allow you to complete conversions quickly on your own computer. This saves you time and money, as batch conversions can be accomplished free of charge.

Please take advantage of this Python script and free yourself from the tedious conversion process!

Copied title and URL