当前位置:网站首页>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
边栏推荐
- [groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte
- KDD 2022 | EEG AI helps diagnose epilepsy
- Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
- [Online gadgets] a collection of online gadgets that will be used in the development process
- Zhuhai laboratory ventilation system construction and installation instructions
- Opencv classic 100 questions
- Spark SQL null value, Nan judgment and processing
- 详细页返回列表保留原来滚动条所在位置
- 程序员成长第九篇:真实项目中的注意事项
- MYSQL GROUP_ The concat function realizes the content merging of the same ID
猜你喜欢
Set data real-time update during MDK debug
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
Spark SQL空值Null,NaN判断和处理
毕设-基于SSM高校学生社团管理系统
如何制作自己的机器人
The population logic of the request to read product data on the sap Spartacus home page
Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
Spark AQE
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
随机推荐
Curlpost PHP
Spark获取DataFrame中列的方式--col,$,column,apply
Cf:c. the third problem
Spark-SQL UDF函数
Ffmpeg captures RTSP images for image analysis
Introduction of motor
[day 30] given an integer n, find the sum of its factors
Cve-2017-11882 reappearance
面试必刷算法TOP101之回溯篇 TOP34
The detailed page returns to the list and retains the original position of the scroll bar
How to use the flutter framework to develop and run small programs
MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练
Finding the nearest common ancestor of binary search tree by recursion
Study diary: February 13, 2022
RAID disk redundancy queue
Model analysis of establishment time and holding time
The value of applet containers
Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
Overview of Zhuhai purification laboratory construction details
Four commonly used techniques for anti aliasing