当前位置:网站首页>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
边栏推荐
- Lone brave man
- Spark DF adds a column
- Hundreds of lines of code to implement a JSON parser
- Opencv classic 100 questions
- Ubantu check cudnn and CUDA versions
- MYSQL GROUP_ The concat function realizes the content merging of the same ID
- RAID disk redundancy queue
- Finding the nearest common ancestor of binary tree by recursion
- Cf:d. insert a progression [about the insert in the array + the nature of absolute value + greedy top-down]
- Cannot resolve symbol error
猜你喜欢
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
Introduction of motor
MYSQL GROUP_ The concat function realizes the content merging of the same ID
Folding and sinking sand -- weekly record of ETF
vSphere实现虚拟机迁移
Common API classes and exception systems
Spark SQL null value, Nan judgment and processing
BiShe - College Student Association Management System Based on SSM
Spark AQE
随机推荐
Four commonly used techniques for anti aliasing
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]
STM32按键消抖——入门状态机思维
Recursive method converts ordered array into binary search tree
China Taiwan strategy - Chapter 8: digital marketing assisted by China Taiwan
Recursive method to realize the insertion operation in binary search tree
Programmer growth Chapter 9: precautions in real projects
FFT 学习笔记(自认为详细)
CTF daily question day44 rot
Introduction of motor
Ffmpeg captures RTSP images for image analysis
[groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
Cannot resolve symbol error
NLP generation model 2017: Why are those in transformer
curlpost-php
Novice entry depth learning | 3-6: optimizer optimizers
C language programming (Chapter 6 functions)
Live broadcast system code, custom soft keyboard style: three kinds of switching: letters, numbers and punctuation