ffmpeg推流时报错 Unknown encoder 'libx264'

问题

执行以下ffmpeg推流命令时报错

ffmpeg -re -i "/home/lee000/Videos/00001.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://192.168.100.158:1935/rtmplive/test1
[root@localhost Videos]# ffmpeg -re -i "/home/lee000/Videos/00001.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://192.168.100.158:1935/rtmplive/test1
ffmpeg version N-95767-gcda3e8c Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  configuration: --prefix=/usr/softinstall/ffmpeg
  libavutil      56. 36.100 / 56. 36.100
  libavcodec     58. 62.100 / 58. 62.100
  libavformat    58. 35.100 / 58. 35.100
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 66.100 /  7. 66.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/lee000/Videos/00001.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2019-10-16T06:58:33.000000Z
  Duration: 00:11:12.83, start: 0.000000, bitrate: 1251 kb/s
    Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 791 kb/s, 29.82 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
    Stream #0:1(und): Audio: pcm_mulaw (ulaw / 0x77616C75), 8000 Hz, mono, s16, 64 kb/s (default)
Unknown encoder 'libx264'

解决方案

这是在安装ffmpeg时没有安装libx264库导致

安装libx264

1)下载libx264(官网)

git clone https://code.videolan.org/videolan/x264.git

2)切到x264根目录

cd x264

3)生成 Makefile

./configure --prefix=/usr/softinstall/x264/ --includedir=/usr/local/include --libdir=/usr/local/lib --enable-shared

  如果不将include和lib安装在/usr/local目录,之后运行ffmpeg推流命令时可能仍然报ERROR:libx264 not found错误。如果已经安装x264了发现报错,则需要将x264.h这个文件要放在/usr/local/include下,libx264的库文件拷贝到/usr/local/lib下,而不是指定其它目录安装存放。推荐安装时直接运行以上命令。

可能报如下错误:
[root@localhost x264]# ./configure --prefix=/usr/softinstall/x264/ --enable-static --enable-shared
Unknown option --enable-share, ignored Found no assembler Minimum > version is nasm-2.13
If you really want to compile without asm, configure with --disable-asm.
解决方案:
下载更新安装nasm新版本(nasm官网):
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz

4)编译

make

5)安装

sudo make install
重新编译安装ffmpeg(已安装先卸载)

1)生成 Makefile时,加上x264

./configure --prefix=/usr/softinstall/ffmpeg --enable-gpl --enable-shared --enable-libx264

2)清理

make clean

2)编译

make

3)安装

sudo make install

4)配置环境变量(参考:安装linux下tar.gz包)

vim /etc/profile
export FFMPEG_PATH=/usr/softinstall/ffmpeg
export CLASSPATH=$FFMPEG_PATH/lib:$CLASSPATH
PATH=$FFMPEG_PATH/bin:$PATH
source /etc/profile

5)测试

ffmpeg -version

在这里插入图片描述

问题一:

重新执行以下ffmpeg推流命令时报错:

[root@localhost ffmpeg]# ffmpeg -re -i "/home/lee000/Videos/00001.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://server:1935/rtmplive/test1
ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
解决方案:

修改ld.so.conf文件

sudo vim /etc/ld.so.conf

配置文件追加ffmpeg安装目录下的lib文件夹(以下是我本机的):

/usr/softinstall/ffmpeg/lib

使修改生效:

sudo ldconfig
问题二:

重新执行以下ffmpeg推流命令时报错:

[root@localhost lib]# ffmpeg -re -i "/home/lee000/Videos/00001.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://server:1935/rtmplive/test1
ffmpeg: error while loading shared libraries: libx264.so.158: cannot open shared object file: No such file or directory
解决方案(同问题一):

修改ld.so.conf文件

sudo vim /etc/ld.so.conf

配置文件追加x264安装目录下的lib文件夹(以下是我本机的):

/usr/local/lib

使修改生效:

sudo ldconfig
问题三:
[root@localhost lib]# ffmpeg -re -i "/home/lee000/Videos/00001.mp4" -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://192.168.100.158:1935/rtmplive/test1
ffmpeg version N-95767-gcda3e8c Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  configuration: --prefix=/usr/softinstall/ffmpeg --enable-gpl --enable-shared --enable-libx264
  libavutil      56. 36.100 / 56. 36.100
  libavcodec     58. 62.100 / 58. 62.100
  libavformat    58. 35.100 / 58. 35.100
  libavdevice    58.  9.100 / 58.  9.100
  libavfilter     7. 66.100 /  7. 66.100
  libswscale      5.  6.100 /  5.  6.100
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/lee000/Videos/00001.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    creation_time   : 2019-10-16T06:58:33.000000Z
  Duration: 00:11:12.83, start: 0.000000, bitrate: 1251 kb/s
    Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 791 kb/s, 29.82 fps, 29.92 tbr, 90k tbn, 180k tbc (default)
    Stream #0:1(und): Audio: pcm_mulaw (ulaw / 0x77616C75), 8000 Hz, mono, s16, 64 kb/s (default)
[tcp @ 0x1377ec0] Connection to tcp://192.168.100.158:1935 failed: Connection refused
[rtmp @ 0x1409b40] Cannot open connection tcp://192.168.100.158:1935
rtmp://192.168.100.158:1935/rtmplive/test1: Connection refused
解决方案:

配置nginx时,只修改了nginx.conf,但未修改nginx.conf.default默认配置文件,把nginx.conf.default修改和nginx.conf内容一致即可
ffmpeg推流时报错 Unknown encoder 'libx264'_第1张图片

你可能感兴趣的:(FFmpeg,FFmpeg)