Perfect solution for Python using ffmpeg

Recently, there is a small task that needs audio transcoding, which needs to be used ffmpeg, There are many problems encountered in the process of installation and use, and there is no way to solve them , It’s hard to find all kinds of tutorials from the Internet , The second brother of this article will sort out from 0 To 1 stay Mac Upper use ffmpeg.

One 、 Install… In the system ffmpeg

The first step is to install… In the system ffmpeg, Many people have given the use of brew Command to download , Let’s talk about it here , The majority of people brew I have to wait after n minute , Finally, it ended up reporting an error , This kind of external website is unstable , Therefore, this method is strongly not recommended .

Stable installation method
First step : Go to the official website to download the installation package :ffmpeg Official website
 Insert picture description here
The second step : Choose your own system , Click the place in the picture :
 Insert picture description here
The third step : Find a version to download (ffprobe etc. ) Empathy
 Insert picture description here
Step four : Decompress the downloaded compressed package to get FFmpeg( Just get the following )
 Insert picture description here

Two 、 Configure environment variables

  • After decompression ffmpeg The program will be left directly in the directory at the time of download , At this time, we find the specified location and create the parent folder ffmpeg, A folder bin, And then ffmpeg The program moves to bin in .
    The example path is as follows ( final ffmpeg It’s the program ! Anywhere ):
     Insert picture description here
  • Next, remember this path , Configure environment variables , Open the terminal , Input :
vim ~/.bash_profile

Then put the following code inside ( Change the path to your own )

export PATH=$PATH:/Users/seven/opt/ffmpeg/bin

The effect of placing is as follows :
 Insert picture description here
Save the file, exit and execute the following code on the terminal ( Used to activate the profile ):

source ~/.bash_profile

After execution , Input :

ffmpeg -version

The following results can be obtained :
 Insert picture description here

Now your terminal can be used ffmpeg 了 .

3、 … and 、 stay Python Install in ffmpeg

Don’t be reckless when installing ! Don’t directly pip install ffmpeg
To use the package correctly, we need to install ffmpeg-python
The correct command is :

pip install ffmpeg-python

Four 、 Configuration files let Python Able to use

Once installed , Some simple function calls have been successful , But most people will encounter ffmpeg.run() Problems that cannot be used , This is a core function , So we need to modify the configuration file .

  • find site-package Under folder ffmpeg( The approximate path is as follows )
     Insert picture description here
  • open ffmpeg Under the _run.py File and open .
  • Pull down , In about 292 That’s ok , Modify your path according to the style in the figure below and save it .
     Insert picture description here

Other functions that cannot be used ( Tools ) You can also follow this operation .
So far, we have finished , Happily in Python Use it in , If you encounter other errors, you can leave a message below , If you solve your problem, just praise it !!

Read more here: Source link