当前位置:网站首页>How to extract MP3 audio from MP4 video files?
How to extract MP3 audio from MP4 video files?
2022-07-06 00:54:00 【Zhuoqing】

Jane Medium : In order to be able to process audio in video , Two methods of extracting audio from video are tested . One is to use format engineering software, the other is to use ffmpeg Software .
key word: Video file , Audio file ,mp4,mp3
§01 carry Take audio
1.1 Video source
Today, in wechat, my friend sent me an interesting video . This video demonstrates that the fresh and elegant plucking music comes from the nine rubber bands on the lunch box , People can't help feeling Flying flowers and picking leaves can hurt people , Grass, wood, bamboo and stone are all swords , I will not deceive you .

▲ chart 1 Lunch box 、 chopsticks 、 elastic Now leave a question :
- What is the frequency of each note in this piece of music ?
- Under certain assumptions , Whether the vibration frequency corresponding to each rubber band meets the requirements of musical syllables ?
1.2 Audio extraction
To answer the above questions , The first step is to start from MP4 Extract the video and audio from the file . have access to Format Factory (Format Factory) Complete the extraction of audio data .
1.2.1 Use format factory to extract audio
(1) Download format engineering software
from Format Factory (Format Factory) Download and install the latest version of software .

▲ chart 1.2.1 install Format Factory Software (2) Separate the audio in the video file
Use the “ ->MP3” take MP4 Separate the audio in the file .

▲ chart 1.2.2 utilize Format Factory Separate MP3(3) Audio preprocessing
utilize Audacity Software is separate MP3 Audio file preprocessing .
Use the Special effects in growth Amplify the original audio waveform . The following is the amplified audio waveform .

▲ chart 1.2.3 utilize Audacity Preprocess audio files 1.2.2 utilize moviepy Extract audio
stay bing In the use of “python extract MP4 sounds” Search for , You can get the following blog post :
Applications are given in the blog moviepy To extract audio data from video .
(1) Processing software
from headm import * # =
from moviepy.editor import *
def mp4tomp3(mp4file, mp3file):
videoclip = VideoFileClip(mp4file)
audioclip = videoclip.audio
audioclip.write_audiofile(mp4file)
audioclip.close()
videoclip.close()
mp4filename = r'D:\Temp\WeChat_20220213170345.mp4'
mp3filename = mp4filename.split('.')[0] + '.mp3'
printt(mp4filename|, mp3filename:)
mp4tomp3(mp4filename, mp3filename)
(2) Running error
An error occurred after running :
---------- [PYTHON INFOR] ----------
MoviePy - Writing audio in D:\Temp\WeChat_20220213170345.mp4
chunk: 0%| | 0/507 [00:00<?, ?it/s, now=None]
chunk: 0%| | 0/507 [00:00<?, ?it/s, now=None]chunk: 4%|▉ | 21/507 [00:00<00:02, 209.99it/s, now=None]Traceback (most recent call last):
File "C:\Users\zhuoqing\Anaconda3\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 74, in write_frames
self.proc.stdin.write(frames_array.tobytes())
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Temp\TEMP0001\test1.PY", line 25, in <module>
mp4tomp3(mp4filename, mp3filename)
File "D:\Temp\TEMP0001\test1.PY", line 15, in mp4tomp3
audioclip.write_audiofile(mp4file)
File "<C:\Users\zhuoqing\Anaconda3\lib\site-packages\decorator.py:decorator-gen-45>", line 2, in write_audiofile
File "C:\Users\zhuoqing\Anaconda3\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Users\zhuoqing\Anaconda3\lib\site-packages\moviepy\audio\AudioClip.py", line 210, in write_audiofile
logger=logger)
File "<C:\Users\zhuoqing\Anaconda3\lib\site-packages\decorator.py:decorator-gen-9>", line 2, in ffmpeg_audiowrite
File "C:\Users\zhuoqing\Anaconda3\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Users\zhuoqing\Anaconda3\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 170, in ffmpeg_audiowrite
writer.write_frames(chunk)
File "C:\Users\zhuoqing\Anaconda3\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 117, in write_frames
raise IOError(error)
OSError: [Errno 32] Broken pipe
MoviePy error: FFMPEG encountered the following error while writing file D:\Temp\WeChat_20220213170345.mp4:
b"Invalid encoder type 'libx264'\r\n"
In case it helps, make sure you are using a recent version of FFMPEG (the versions in the Ubuntu/Debian repos are deprecated).
Exception ignored in: <function FFMPEG_AudioWriter.__del__ at 0x0000000017880268>
Traceback (most recent call last):
File "C:\Users\zhuoqing\Anaconda3\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 132, in __del__
self.close()
File "C:\Users\zhuoqing\Anaconda3\lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py", line 121, in close
self.proc.stdin.close()
OSError: [Errno 22] Invalid argument
This shows a problem , It needs to be installed correctly in the software FFMPEG Software .
The question is Python extract wav from video file Also mentioned by netizens , How to avoid using ffmpeg.
My question is how could I extract wav audio track from video file, say video.avi? I read many articles and everywhere people suggest to use (from Python) ffmpeg as a subprocess (because there are no reliable python bindings to ffmpeg - the only hope was PyFFmpeg but i found it is unmaintaned now). I don’t know if it is right solution and i am looking for good one.
I looked to gstreamer and found it nice but unable to satisfy my needs – the only way I found to accomplish this from command line looks like、
This situation has been found by netizens in the process of use that it must be installed FFMPEGA, such as For a while mp4 Extract and save the audio in the original directory python Script .

▲ chart 1.2.4 You can't get around it ffmpeg Software Even in Extract MP3 audio from Videos using a Python script take ffmpeg Repackaged as a function called to get MP4 Audio data in .
1.2.3 install ffmpeg
Since I can't get around , Then install ffmpeg Software . stay How to Install FFmpeg on Windows The installation is given ffmpeg Methods .
(1) download ffmpeg
stay ffmpeg Official website : https://ffmpeg.org/download.html Download the required software version .

▲ chart 1.2.5 FFMPEG Official download software Here are two Windows EXE files Download link :
- Windows builds from gyan.dev
- Windows builds by btbN
I don't know the difference between the two versions , Now choose the first :builds from gyan.dev.

▲ chart 1.2.6 choice Windows EXE edition 
▲ chart 1.2.7 Choose to download the distribution After downloading is a ZIP Compressed files :
- D:\Temp\ffmpeg-5.0-essentials_build.zip
(2) Unzip the file
utilize Windows Version of Bandizip Compress it .
Decompression produces ffmpeg Catalog , It includes bin Catalog , It includes ffmpeg.exe Executable file .
└─ffmpeg-5.0-essentials_build
│ LICENSE
│ README.txt
├─bin
│ ffmpeg.exe
│ ffplay.exe
│ ffprobe.exe
├─doc
│ bootstrap.min.css
│ default.css
│ developer.html
│ faq.html
│ fate.html
│ ffmpeg-all.html
│ ffmpeg-bitstream-filters.html
│ ffmpeg-codecs.html
│ ffmpeg-devices.html
│ ffmpeg-filters.html
│ ffmpeg-formats.html
│ ffmpeg-protocols.html
│ ffmpeg-resampler.html
│ ffmpeg-scaler.html
│ ffmpeg-utils.html
│ ffmpeg.html
│ ffplay-all.html
│ ffplay.html
│ ffprobe-all.html
│ ffprobe.html
│ general.html
│ git-howto.html
│ libavcodec.html
│ libavdevice.html
│ libavfilter.html
│ libavformat.html
│ libavutil.html
│ libswresample.html
│ libswscale.html
│ mailing-list-faq.html
│ nut.html
│ platform.html
│ style.min.css
└─presets
libvpx-1080p.ffpreset
libvpx-1080p50_60.ffpreset
libvpx-360p.ffpreset
libvpx-720p.ffpreset
libvpx-720p50_60.ffpreset
(3) Add environment variables
take ffmpeg Of bin Add in System settings Medium path variable . adopt edit Can be bin The catalog is pasted on path Last . Use a semicolon in the middle “;” separate .

▲ chart 1.2.8 Set environment variables of the system (4) test FFMPEG
Use the following command to extract the audio in the video :
ffmpeg -i music.mp4 music.wav
ffmpeg -i music.mp4 music.mp3
The above two commands can be generated separately music.wav, music.mp3 file .
※ carry Take a summary ※
by It can process audio in video , Two methods of extracting audio from video are tested . One is to use format engineering software, the other is to use ffmpeg Software .
■ Links to related literature :
- Format Factory (Format Factory)
- How to Extract Audio from Video files (Mp3 From Mp4)
- Python extract wav from video file
- For a while mp4 Extract and save the audio in the original directory python Script
- Extract MP3 audio from Videos using a Python script
- How to Install FFmpeg on Windows
- ffmpeg Official website
- Windows Version of Bandizip
● Related chart Links :
- chart 1 Lunch box 、 chopsticks 、 elastic
- chart 1.2.1 install Format Factory Software
- chart 1.2.2 utilize Format Factory Separate MP3
- chart 1.2.3 utilize Audacity Preprocess audio files
- chart 1.2.4 You can't get around it ffmpeg Software
- chart 1.2.5 FFMPEG Official download software
- chart 1.2.6 choice Windows EXE edition
- chart 1.2.7 Choose to download the distribution
- chart 1.2.8 Set environment variables of the system
边栏推荐
- The population logic of the request to read product data on the sap Spartacus home page
- Programmer growth Chapter 9: precautions in real projects
- Ffmpeg captures RTSP images for image analysis
- golang mqtt/stomp/nats/amqp
- 2020.2.13
- BiShe - College Student Association Management System Based on SSM
- Arduino hexapod robot
- NLP basic task word segmentation third party Library: ICTCLAS [the third party library with the highest accuracy of Chinese word segmentation] [Chinese Academy of Sciences] [charge]
- Idea remotely submits spark tasks to the yarn cluster
- 【文件IO的简单实现】
猜你喜欢

2020.2.13

Analysis of the combination of small program technology advantages and industrial Internet
![[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte](/img/61/73becfc3b46669d31b0cf334aa54f2.jpg)
[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte

Fibonacci number

Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates

BiShe - College Student Association Management System Based on SSM

View class diagram in idea

ubantu 查看cudnn和cuda的版本
![[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)](/img/dd/bffe27b04d830d70f30df95a82b3d2.jpg)
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)

Recoverable fuse characteristic test
随机推荐
Beginner redis
Idea remotely submits spark tasks to the yarn cluster
Differences between standard library functions and operators
KDD 2022 | 脑电AI助力癫痫疾病诊断
【文件IO的简单实现】
Leetcode Fibonacci sequence
Study diary: February 13, 2022
MCU通过UART实现OTA在线升级流程
Cf:c. the third problem
KDD 2022 | EEG AI helps diagnose epilepsy
看抖音直播Beyond演唱会有感
Dynamic programming -- linear DP
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
After Luke zettlemoyer, head of meta AI Seattle research | trillion parameters, will the large model continue to grow?
Data analysis thinking analysis methods and business knowledge -- analysis methods (II)
devkit入门
Set data real-time update during MDK debug
Problems and solutions of converting date into specified string in date class
How to use the flutter framework to develop and run small programs
View class diagram in idea