python video vocal removal

a

Need to install python, ffmpeg, spleeter, the operating system I use is window10

python installation

You can refer to this , which may be the most detailed python installation tutorial on the entire network (windows) , today I will take you to complete the python installation and configuration, follow me step by step, it is very simple, you can definitely complete it. Part 1: python installation (1) Preparation 1. Download and install python (look for the official website) (2) Start the installation. For Windows operating system, you can download "executable installer". It should be noted that if you install Python 3 in the Windows 7 environment, you need to install the ServicePack 1 patch package first. You can enter winv in the "Run" of Windows https://blog.csdn.net/weixin_58753619/article/details/ 123014634

ffmpeg install

You can refer to Windows installation ffmpeg_Invisible corner blog-CSDN blog_ffmpeg windows installation process of installing ffmpeg under windows, you can directly call the ffmpeg program to perform operations such as streaming, transcoding https://blog.csdn.net/qq_21996127/ article/details/125477873

spleeter installation

You can try the function of spleeter on colab https://colab.research.google.com/github/deezer/spleeter/blob/master/spleeter.ipynb https://colab.research.google.com/github/deezer/spleeter /blob/master/spleeter.ipynb

可参考GitHub - deezer/spleeter: Deezer source separation library including pretrained models.Deezer source separation library including pretrained models. - GitHub - deezer/spleeter: Deezer source separation library including pretrained models.https://github.com/deezer/spleeter

The README.md file contains a detailed installation tutorial, but the author stuck and did not respond when I followed the pip install spleeter. If you encounter this situation, you can try

conda install -c "conda-forge/label/cf202003" spleeter

or

conda install -c conda-forge spleeter

These two instructions will be displayed when searching for spleeter on the official website of anaconda (address: Search :: Anaconda.org ), but you need to install anaconda first to use the conda instruction.

Implementation ideas

First use ffmpeg to extract the video sound, then use spleeter to separate the background sound and human voice in the audio, and finally merge the background sound with the original video, and finally get the video with the human voice removed.

Implementation

 First of all, the following instructions are executed in cmd

Extract video sound

ffmpeg -i audio.mp4 -vn -codec copy sound.m4a

"audio.mp4" is the video whose sound is to be extracted. It can be not only a file in mp4 format, but also a video in a format such as flv. "sound.m4a" is the file name to save the audio to be extracted. Next, convert the m4a audio to mp3 format.

ffmpeg -i "sound.m4a" -y -acodec libmp3lame -aq 0 "sound.mp3"

Why convert it to mp3 format, because when colab tried it out, the example I saw was mp3 file O(∩_∩)O. You can convert the m4a format to another format for the next operation to try.

vocal separation

spleeter separate -p spleeter:2stems -o output sound.mp3

The sound.mp3 here is the audio to remove the human voice. When this command is executed for the first time, the pretrained_models\2stems folder will be created in the current opening path of cmd to save the downloaded model files, so it is recommended to run this command in the same folder to avoid downloading model files multiple times.

After entering the command and pressing Enter, wait for a while, and the output\sound folder will appear under the current open path of cmd. If the file name is xyz.mp3, the output\xyz folder will appear. There are two files in the folder, accompaniment .wav is the background sound, and vocals.wav is the human voice.

Combine background sound and video

First, you need to delete the sound of the original video. The file name here needs to add English quotation marks, if not, it will prompt No such file or directory.

ffmpeg -i "audio.mp4" -y -f mp4 -an -codec copy -q:v 1 "audio-无声.mp4"

Then merge the silent video and audio

ffmpeg -i audio-无声.mp4 -i accompaniment.wav -c:v copy -c:a aac -strict experimental audio-消音.mp4

A video with human voice removed can be obtained. But the author's spoken English is not good, and I feel that the speech speed of the original video is a bit fast, so I adjusted the video speed to 0.8 times.

ffmpeg -i test.mp4 -filter_complex "[0:v]setpts=10/8*PTS[v];[0:a]atempo=0.8[a]" -map "[v]" -map "[a]" test-2.mp4

This command adjusts the video speed and audio speed at the same time, setpts=(reciprocal of double speed)*PTS[v], atempo=(double speed)[a]

Guess you like

Origin blog.csdn.net/qq_43536827/article/details/127483076