ffmpeg-python安装

文章描述了在CentOS上手动下载并安装ffmpeg的过程,包括解决yasm安装时的权限问题,以及在Python中安装ffmpeg绑定库ffmpeg-python的步骤。在安装过程中遇到了权限被拒绝的问题,通过切换到root用户或修改环境变量来解决。最后提到了如果遇到ffmpeg运行问题,可能需要修改Python的ffmpeg运行路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值