切记编译opencv使用ffmpeg的话先编译安装完ffmpeg再进行编译安装opencv
av_packet_unref@LIBAVCODEC_58'
您看到的错误消息/usr/local/lib/libopencv_videoio.so.4.6.0: undefined reference to 'av_packet_unref@LIBAVCODEC_58'
表示您的系统上的 OpenCV 和 FFmpeg(或 libav)库版本不匹配。具体来说,OpenCV 正在尝试使用不可用的 FFmpeg 版本中的函数。
要解决此问题,您可以尝试以下步骤:
-
检查已安装的版本:确保 OpenCV 和 FFmpeg 的版本兼容。您可以使用以下命令检查版本
复制代码pkg-config --modversion opencv4
ffmpeg -version
-
安装兼容版本:如果不匹配,您可能需要安装兼容版本的 FFmpeg。例如,您可以从官方存储库安装 FFmpeg:
复制代码sudo apt-get update sudo apt-get install ffmpeg
-
重建 OpenCV:如果您已从源代码构建 OpenCV,请确保它链接到正确版本的 FFmpeg。您可能需要使用正确的 FFmpeg 库重建 OpenCV。请按照以下步骤操作:
- 删除现有的 OpenCV 构建目录:
复制代码
rm -rf <opencv-build-directory>
- 使用 CMake 配置构建,确保它选择正确的 FFmpeg 库:
复制代码
cd <opencv-source-directory> mkdir build cd build cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. make -j$(nproc) sudo make install
具体的命令还是复制下面完整的编译命令
- 删除现有的 OpenCV 构建目录:
-
更新库缓存:有时需要更新库路径。运行以下命令来更新库缓存:
复制代码sudo ldconfig
-
检查其他依赖项:确保 OpenCV 和 FFmpeg 所需的所有其他依赖项都已正确安装且是最新的。
通过遵循这些步骤,您应该能够解决undefined reference to 'av_packet_unref@LIBAVCODEC_58'
错误并获得与正确版本的 FFmpeg 链接的 OpenCV 的工作安装。
源码去官方下载即可,本次遇到的问题是
在cmake中添加对应的路径一起编译即可。
firefly@kylinos:~/opencv-4.6.0/build$ sudo cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_ENABLE_NONFREE=True -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python3=ON -D PYTHON3_EXECUTABLE=/usr/bin/python3.8 -D BUILD_opencv_python2=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D ENABLE_NEON=ON -D WITH_OPENMP=ON -D WITH_OPENCL=OFF -D BUILD_TIFF=ON -D WITH_FFMPEG=ON -D WITH_TBB=ON -D BUILD_TBB=ON -D WITH_GSTREAMER=ON -D BUILD_TESTS=OFF -D WITH_EIGEN=OFF -D WITH_V4L=ON -D WITH_LIBV4L=ON D OPENCV_ENABLE_NONFREE=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK=1 -D PYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages -D PYTHON3_EXECUTABLE=/usr/bin/python3 -D PYTHON_LIBRARIES=/usr/lib/aarch64-linux-gnu/libpython3.8.so -D PYTHON3_NUMPY_INCLUDE_DIRS=/home/firefly/.local/lib/python3.8/site-packages/numpy/core/include -D OPENCV_EXTRA_MODULES=../../opencv_contrib/modules ..
sudo make -j12
sudo make install
fmpeg源码实现H264推流时,出现错误提醒:配置编码器失败
[vp8_v4l2m2m @ 0x56195db9f9f0] Could not find a valid device
[vp8_v4l2m2m @ 0x56195db9f9f0] can't configure encoder
1
2
解决办法:
下载x264源码编译生成libx264.so库,重新编译FFmpeg并将x264添加进去
编译方法:
git clone https://code.videolan.org/videolan/x264.git
cd x264 //进入x264源码文件目录下
./configure --enable-shared
make
sudo make install
sudo cp /usr/local/lib/libx264.so.164 /lib //生成文件的默认路径为:/usr/local/lib
cd ffmpeg //进入ffmpeg源码文件目录下
./configure --enable-shared --disable-yasm --enable-libx264 --enable-gpl --prefix=/home/jiajia/ffmpeg-x64
make
make install
安装libdrm
wget https://dri.freedesktop.org/libdrm/libdrm-2.4.89.tar.bz2
tar -jxvf libdrm-2.4.89.tar.bz2
./configure --prefix=/usr/local/ --host=aarch64-linux-gnu
make -j8
sudo make install
libtool: error: error: cannot install 'libkms.la' to a directory not ending in /usr/local/libdrm/lib
./configure --prefix=/usr/local/ && make clean && make -j12 && sudo make install
Cannot read RTMP handshake response
rtmp://192.168.1.4:1935/live/test: Connection reset by peer
464 ls
465 cd ffmpeg-4.2.9/
466 ls
467 ./configure --prefix=/usr/local/my/ffmpeg --enable-version3 --enable-libdrm --enable-rkmpp --enable-libx264 --enable-nonfree --enable-gpl
468 make -j12
469 sudo make install
470 ls
471 cd /usr/local/my/ffmpeg/
472 ls
473 cd bin/
474 ./ffmpeg
475 sudo vim .bashrc
476 sudo vim ~/.bashrc
477 source ~/.bashrc
478 ffmpeg configure -codecs | grep h264
479 cd
480 history
参考文章 :rk3588 ffmpeg使用硬件解码_ffmpeg rkmpp-优快云博客
511 ffmpeg -re -stream_loop -1 -i 1.mp4 -f flv "rtmp://192.168.1.4:1935/live/test"
512 ffmpeg
513 cd
514 cd 下载/ffmpeg-4.2.9/
515 ls
516 make clean
517 ./configure --prefix=/usr/local/my/ffmpeg --enable-version3 --enable-rkmpp --enable-libx264 --enable-libdrm --enable-nonfree --enable-gpl
518 make -j8
519 sudo make install
520 cd
521 sudo ldconfig
522 ffmpeg -re -stream_loop -1 -i 1.mp4 -f flv "rtmp://192.168.1.4:1935/live/test"
错误ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
重新make clean 编译ffmpeg
错误:Sample rate must be 11025, 22050 or 44100
Error initializing output stream 0:1 -- Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
警告:libavcodec/libavcodec.so 所需的 libx264.so.155 可能与 libx264.so.164 冲突(切记卸载掉之前的h264版本)
This warning typically arises when there are multiple versions of the libx264 library installed on your system, which can cause conflicts when software tries to use these libraries.
Here are some steps to resolve this issue:
1. **Check Installed Versions**:
- Use the command `ldconfig -p | grep libx264` to see the installed versions of libx264 on your system.
2. **Remove Conflicting Versions**:
- If you have multiple versions installed, you may need to remove the older version (libx264.so.155). Use your package manager to remove the conflicting version. For example, on a Debian-based system:
```bash
sudo apt-get remove libx264-155
```
3. **Update Your Package**:
- Ensure that your software is using the latest version of libx264. Update your package using:
```bash
sudo apt-get update
sudo apt-get upgrade
```
4. **Recompile Software**:
- If you are compiling software from source, make sure to clean your build environment and recompile it against the correct version of the library. For example:
```bash
make clean
./configure
make
sudo make install
```
5. **Symbolic Links**:
- Ensure that the symbolic links for libx264 point to the correct version. You can update these links manually if necessary. For example:
```bash
sudo ln -sf /usr/lib/libx264.so.164 /usr/lib/libx264.so
```
By following these steps, you should be able to resolve the conflict between the different versions of the libx264 library.
Nginx(engine x)是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP/RTMP等服务。它是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的。Nginx以类BSD许可证的形式发布其源代码,并因其稳定性、丰富的功能集、简单的配置文件和低系统资源的消耗而闻名。
在功能方面,Nginx可以支持高达50,000个并发连接数的响应,并且可以作为负载均衡服务,既可以在内部直接支持Rails和PHP程序对外进行服务,也可以支持作为HTTP代理服务对外进行服务。此外,Nginx还提供了模块化的结构,包括gzipping、byte ranges、chunked responses以及SSI-filter等filter。
在安装和配置方面,Nginx的安装相对简单,可以通过各种包管理器如apt、yum等进行安装。配置文件通常位于/etc/nginx/nginx.conf,可以使用任何文本编辑器进行配置。在配置文件中,可以修改监听端口、添加虚拟主机配置等。
1.2 Nginx下载安装
下载地址:Index of /download/ (ecsds.eu)
使用说明:nginx for Windows - documentation.pdf (ecsds.eu)
这个版本是带rtmp且编译过的nginx版本,下载也很快,所以就不分享网盘了,大家自行下载!
2、RTMP服务器下载
2.1 nginx-rtmp-module下载
nginx-rtmp-module是一个用于Nginx的第三方模块,它使Nginx能够支持实时多媒体流的传输和处理。
下载地址:GitHub - arut/nginx-rtmp-module: NGINX-based Media Streaming Server
3、搭建步骤
3.1 文件预处理
解压下载的nginx文件nginx 1.7.11.3 Gryphon.zip,并重命名文件夹为nginx_1.7.11.3。
解压下载的rtmp服务器源码nginx-rtmp-module-master.zip,重命名文件夹为nginx-rtmp-module。
将nginx-rtmp-module文件夹移动到第1步的nginx_1.7.11.3目录下
3.2 配置文件修改
将nginx_1.7.11.3文件夹下的conf目录中nginx-win.conf文件以记事本的形式打开,将下面的代码替换进去。
worker_processes 2;
events {
worker_connections 8192;
# max value 32768, nginx recycling connections+registry optimization =
# this.value * 20 = max concurrent connections currently tested with one worker
# C1000K should be possible depending there is enough ram/cpu power
# multi_accept on;
}
#RTMP服务
rtmp {
server {
listen 1935;#监听端口,若被占用,可以更改
chunk_size 4000;#上传flv文件块儿的大小
application live { #创建名为"live"的应用
live on;#开启live的应用
allow publish 127.0.0.1;#
allow play all;
}
}
}
#HTTP服务,可以通过浏览器访问http://localhost/stat查看状态
http {
#include /nginx/conf/naxsi_core.rules;
include mime.types;
default_type application/octet-stream;
sendfile off;
#tcp_nopush on;
server_names_hash_bucket_size 128;
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 30;
send_timeout 10;
keepalive_requests 10;
server {
listen 80;
server_name localhost;
# For Naxsi remove the single # line for learn mode, or the ## lines for full WAF mode
location / {
#include /nginx/conf/mysite.rules; # see also http block naxsi include line
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3.3 启动RTMP服务
按住win+R,输入cmd进入命令行,跳转至nginx_1.7.11.3目录,输入nginx.exe -c conf\nginx-win.conf即可。
3.4 RTMP服务常用命令
nginx.exe -s stop //快速停止服务器,可能不保存相关信息
nginx.exe -s quit //完全停止服务器,保存相关信息
nginx.exe -s reload //重新载入Nginx/配置信息修改时使用此命令
4、OBS推流
4.1 OBS下载
Open Broadcaster Software是一个免费的开源的视频录制和视频实时交流软件。其有多种功能并广泛使用在视频采集,直播等领域。
官网下载:Open Broadcaster Software | OBS (obsproject.com)
用OBS Studio拉流直播的方法
推流即可
搭建好nginx(虚拟机ubuntu或者windows下都可以网上教程百度一下就行安装几个包就行),编译好ffmpeg(rk3588开发板)之后,可以使用如下指令测试在rk3588板子上是否能够正常运行。
ffmpeg -re -stream_loop -1 -i 1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://192.168.1.102:1935/live/test
其中,1.mp4是测试视频,使用h264编码(用到了libx264),192.168.1.100是笔者局域网的服务器ip,1935是端口号。使用obs studio等带拉流的软件,输入
rtmp://192.168.1.100:1935/live/test,正常情况下可以看到音视频流。