ffmpeg-python安装
迪丽瓦拉
2025-06-01 16:45:15
0

centos-ffmpeg-python安装

安装ffmpeg

一:下载并解压

wget http://www.ffmpeg.org/releases/ffmpeg-4.2.tar.gz
tar -zxvf ffmpeg-4.2.tar.gz

若linux服务器没网,可以在windows上直接访问http://www.ffmpeg.org/releases/ffmpeg-4.2.tar.gz就可下载,然后上传至服务器

二:安装

cd ffmpeg-4.2./configure --prefix=/usr/local/ffmpeg

报错

(base) [hhhhh@master ffmpeg-4.2]$ ./configure --prefix=/usr/local/ffmpeg
nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

安装yasm,新建ssh终端,若已安装跳过

wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install

最后一步报错

/usr/bin/install: cannot remove ‘/usr/local/bin/yasm’: Permission denied
/usr/bin/install: cannot remove ‘/usr/local/bin/ytasm’: Permission denied
/usr/bin/install: cannot remove ‘/usr/local/bin/vsyasm’: Permission denied

在root下进行

tar -zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure prefix=/usr/local/yasm
make && make install临时添加或者按照下面ffmpeg的方法添加yasm到/etc/profile文件
export PATH=$PATH:/usr/local/yasm/bin
yasm --version

出现下面代码说明yasm安装成功

yasm 1.3.0
Compiled on Mar 21 2023.
Copyright (c) 2001-2014 Peter Johnson and other Yasm developers.
Run yasm --license for licensing overview and summary.

继续安装ffmpeg

(base) [hhhhhh@master ffmpeg-4.2]$  export PATH=$PATH:/usr/local/yasm/bin
(base) [hhhhhh@master ffmpeg-4.2]$ ./configure --prefix=/usr/local/ffmpeg
(base) [hhhhhh@master ffmpeg-4.2]$ ./configure --prefix=/usr/local/ffmpeg --enable-openssl --disable-x86asm
(base) [hhhhhh@master ffmpeg-4.2]$ make && make install

报错

install: cannot remove ‘/usr/local/ffmpeg/share/man/man1/ffmpeg-formats.1’: Permission denied
install: cannot remove ‘/usr/local/ffmpeg/share/man/man1/ffmpeg-protocols.1’: Permission denied
install: cannot remove ‘/usr/local/ffmpeg/share/man/man1/ffmpeg-devices.1’: Permission denied
install: cannot remove ‘/usr/local/ffmpeg/share/man/man1/ffmpeg-filters.1’: Permission denied

切换root

su
make install

完成后配置环境变量

编辑
vim /etc/profile在文件结尾处添加,默认格式按u可撤销上一步操作
export PATH=$PATH:/usr/local/ffmpeg/bin保存退出后刷新
source /etc/profile

验证,出现说明成功

[root@master ffmpeg-4.2]# ffmpeg -version
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
configuration: --prefix=/usr/local/ffmpeg --enable-openssl --disable-x86asm
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100

在Python中安装ffmpeg

安装ffmpeg-python

pip install python_ffmpeg-2.0.3-py3-none-any.whl

报错

ERROR: Could not find a version that satisfies the requirement typing-extensions (from python-ffmpeg==2.0.3) (from versions: none)
ERROR: No matching distribution found for typing-extensions (from python-ffmpeg==2.0.3)

激活环境

source activate /home/hhhhhh/anaconda3/envs/GFP-GAN
pip install python_ffmpeg-2.0.3-py3-none-any.whl

报错

ERROR: Could not find a version that satisfies the requirement pyee (from python-ffmpeg) (from versions: none)
ERROR: No matching distribution found for pyee

以上安装错了,在pypi中搜索的应该是ffmpeg_python而不是python_ffmpeg

(GFP-GAN) [hhhhhh@node05 library]$ pip install ffmpeg_python-0.2.0-py3-none-any.whl
Processing ./ffmpeg_python-0.2.0-py3-none-any.whl
Requirement already satisfied: future in /home/hhhhhh/anaconda3/envs/GFP-GAN/lib/python3.7/site-packages (from ffmpeg-python==0.2.0) (0.18.2)
Installing collected packages: ffmpeg-python
Successfully installed ffmpeg-python-0.2.0

安装好之后,发现real-esrgan推理视频可执行了

如果修改了/etc/ffmpeg则不会出现下面问题【不推荐以下方式】

如果遇到ffmpeg.run()不能用,需要修改配置文件

/home/hhhhh/anaconda3/envs/GFP-GAN/lib/python3.7/site-packages/ffmpeg/_run.py

@output_operator()
def run(stream_spec,cmd='ffmpeg',capture_stdout=False,capture_stderr=False,input=None,quiet=False,overwrite_output=False,
):

把cmd改成ffmpeg的二进制文件路径/usr/local/ffmpeg/bin/ffmpeg

nasm安装(可选)

下载安装包,注意版本
wget https://www.nasm.us/pub/nasm/releasebuilds/2.13rc23/nasm-2.13rc23.tar.xz --no-check-certificate解压
tar xf nasm-2.13rc23.tar.gz进入目录
cd nasm-2.13rc23指定目录
./configure prefix=/usr/local/nasm-2.13编译and安装
make && make install设置环境变量
export PATH=$PATH:/usr/local/nasm-2.13/bin
或者加入/etc/profile验证
nasm --version
NASM version 2.13rc23 compiled on Oct 11 2022

相关内容