当前位置:网站首页>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 detailed page returns to the list and retains the original position of the scroll bar
- KDD 2022 | EEG AI helps diagnose epilepsy
- 几百行代码实现一个 JSON 解析器
- Five challenges of ads-npu chip architecture design
- China Taiwan strategy - Chapter 8: digital marketing assisted by China Taiwan
- 在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
- Spark SQL null value, Nan judgment and processing
- Overview of Zhuhai purification laboratory construction details
- Starting from 1.5, build a micro Service Framework - call chain tracking traceid
猜你喜欢
Four commonly used techniques for anti aliasing
Model analysis of establishment time and holding time
MySQL storage engine
测试/开发程序员的成长路线,全局思考问题的问题......
如何制作自己的機器人
看抖音直播Beyond演唱会有感
KDD 2022 | EEG AI helps diagnose epilepsy
[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte
cf:C. The Third Problem【关于排列这件事】
可恢复保险丝特性测试
随机推荐
Logstash clear sincedb_ Path upload records and retransmit log data
Programmer growth Chapter 9: precautions in real projects
程序员成长第九篇:真实项目中的注意事项
Spark DF adds a column
Browser reflow and redraw
毕设-基于SSM高校学生社团管理系统
Synchronized and reentrantlock
Building core knowledge points
关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
KDD 2022 | 脑电AI助力癫痫疾病诊断
How spark gets columns in dataframe --column, $, column, apply
curlpost-php
Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
I'm interested in watching Tiktok live beyond concert
Promise
Dynamic programming -- linear DP
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
Study diary: February 13, 2022