In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to extract audio from video by Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First, extract audio
Need to use python's moviepy library
Github address of moviepy: https://github.com/Zulko/moviepy
Just install moviepy on the command line pip!
Pip install moviepy-I http://pypi.douban.com/simple-- trusted-host pypi.douban.com
Extract audio: suppose there is a mp4 file path of "D:pythonpycharm2020my_programvideo_process est_01.mp4", and we want to extract the audio from it and save it to "D:pythonpycharm2020my_programvideo_processvst01.mp3". The three lines of Python code are implemented as follows:
Import moviepy.editor as mpy# intercepts background music audio_background = mpy.AudioFileClip (r'D:pythonpycharm2020my_programvideo_process est_01.mp4'). Subclip (1,60) audio_background.write_audiofile
Execute the above three lines of code, you will find that the audio file has been successfully extracted to the specified folder ~ ~ the video format and audio format here support other formats, such as reading mp4 format video, extracting the background music and saving it as MP3 format audio.
Second, gravitational wave drawing
Data sources:
Http://python123.io/dv/grawave.html
Http://python123.io/dv/H1_Strain.wav
Http://python123.io/dv/L1_Strain.wav
Http://python123.io/dv/wf_template.txt
Read time-related data from the configuration document
Import numpy as np # numpy library for scientific computing import matplotlib.pyplot as plt # library for drawing matplotlibfrom scipy.io import wavfile # library for reading waveform files rate_h, hstrain = wavfile.read (r "H1_Strain.wav", "rb") # read audio file rate_l, lstrain = wavfile.read (r "L1_Strain.wav", "rb") # reftime Ref_H1 = np.genfromtxt ('GW150914_4_NR_waveform_template.txt'). Transpose () reftime, ref_H1 = np.genfromtxt (' wf_template.txt'). Transpose () # download the txt file using python123.io
Tectonic strain data
Htime_interval = 1 / rate_hltime_interval = 1 / rate_lfig = plt.figure (figsize= (12, 6)) # create a drawing space of 12'6 # loss signal starting point htime_len = hstrain.shape [0] / rate_h # read the length of the first dimension of the data, get the total length of the function on the axis htime = np.arange (- htime_len / 2, htime_len / 2, htime_interval) # (starting point, end point Time interval)
Mapping using data from the "H1" detector
Plth = fig.add_subplot (221) # set drawing area plth.plot (htime, hstrain,'r') # draw an image with time as x axis and strain data as y axis.'y'is yellow plth.set_xlabel ('Time (seconds)') plth.set_ylabel ('H1 Strain') plth.set_title ('H1 Strain')
Draw L1 Strain and Template
Ltime_len = lstrain.shape [0] / rate_lltime = np.arange (- ltime_len / 2, ltime_len / 2, ltime_interval) pltl = fig.add_subplot (222) pltl.plot (ltime, lstrain,'k') pltl.set_xlabel ('Time (seconds)') pltl.set_ylabel ('L1 Strain') pltl.set_title ('L1 Strain') pltref = fig.add_subplot (reftime, ref_H1) 'purple') pltref.set_xlabel (' Time (seconds)') pltref.set_ylabel ('Template Strain') pltref.set_title (' Template') fig.tight_layout () # automatically adjust the outer edge of the image
Save and display the image
Plt.savefig ("Gravitational_Waves_Original.png") # saves the image in png format plt.show () plt.close (fig) "how to extract audio from video by Python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.