搭建视频点播(VOD)服务(live555 + ffmpeg)

来源:互联网 发布:中体产业 网络彩票 编辑:程序博客网 时间:2024/06/04 18:58

前段时间做人脸识别考勤系统,大体上分实时视频和点播两大块,实时视频使用的是ffserver流媒体服务器,负责从海康威视摄像头接收实时视频流,转而可实时查看原始视频流,同时进行人脸检测识别,最后可将原始视频流或经ai处理的视频流通过ffmpeg录制。将ffmpeg录制的视频后缀修改为live555规定的格式后即可通过rtsp流就行点播。

linux 下编译x264

  • 1.安装 Yasm

    yum install -y yasm

    如果yum源不包含,则可采用源码安装方式。首先下载yasm最新源码,yasm下载地址:http://yasm.tortall.net/Download.html,下载最新的Source .tar.gz源码(我这里使用的是这个版本yasm-1.2.0.tar.gz)。

  • 2.将源码拷贝到Linux系统中,做如下操作编译yasm:(可选)

    解压yasm-1.2.0.tar.gz命令:

    # tar -zxvf yasm-1.2.0.tar.gz

    进入解压后文件目录:

    # cd yasm-1.2.0# ./configure# make# make install

    编译安装yasm完成。

  • 3.下载最新的x264源码,x264源码

    # git clone --depth 1 git://git.videolan.org/x264
  • 4.将源码解压并拷贝到linux系统中,做如下操作编译x264:

    进入到解压后的源码目录:

    # cd x264# ./configure --enable-shared

    如果有提示:

    [root@onegpu x264]# ./configure --enable-sharedFound no assemblerMinimum version is nasm-2.13If you really want to compile without asm, configure with --disable-asm.

    可以添加上 --disable-asm

    # ./configure --enable-shared --disable-asm

    然后make,编译需要一段时间。

    等待编译完成后,执行make install

    OK,到这里x264就已经的编译完成生成相应的库文件。

ffmpeg-3.3.3 安装

1.下载 ffmpeg-3.3.3.tar.gz

到ffmpeg 官网 https://ffmpeg.org/download.html 挑选你要升级到的版本。此次下载的是 ffmpeg-3.3.3.tar.gz。

2.编译安装

tar -zxvf ffmpeg-3.3.3.tar.gzcd ffmpeg-3.3.3./configure --enable-shared --enable-libx264 --enable-gpl --prefix=/usr/local/ffmpegmakemake install

需要依赖 gcc 库 ,直接用 yum install -y gcc 安装,还依赖 yasm 库, 可通过 yum install -y yasm 安装, 如果没有yasm的源,一种可以添加数据源,还有种偷懒的办法就是在configure后加上参数 --disable-yasm, 如下:

./configure --disable-yasm --enable-shared --enable-libx264 --enable-gpl --prefix=/usr/local/ffmpeg  

3.动态链接库 (目的是让系统找到ffmpeg的lib,以下可用软链接到/lib64/目录的方式代替)

vi /etc/ld.so.conf

新起一行加入:/usr/local/ffmpeg/lib, 执行

ldconfig

4.添加ffmpeg到环境变量

vi /etc/profile

加入以下内容:

FFMPEG=/usr/local/ffmpegPATH加入:$FFMPEG/bin

5.使修改立即生效

source /etc/profile

执行

ffmpeg -version

打印结果

[root@master bin]#  ffmpeg -versionffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developersbuilt with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-11)configuration: --enable-shared --prefix=/usr/local/ffmpeglibavutil      55. 58.100 / 55. 58.100libavcodec     57. 89.100 / 57. 89.100libavformat    57. 71.100 / 57. 71.100libavdevice    57.  6.100 / 57.  6.100libavfilter     6. 82.100 /  6. 82.100libswscale      4.  6.100 /  4.  6.100libswresample   2.  7.100 /  2.  7.100

证明已升级成功。如果遇到 ffmpeg: error while loading shared libraries: libavdevice.so.55: cannot open shared object file: No such file or directory 之类的错误,请检查第三步是否做好。

LIVE555 Streaming Media服务搭建

安装

How to configure and build the code on Unix (including Linux, Mac OS X, QNX, and other Posix-compliant systems)

The source code package can be found (as a “.tar.gz” file) here. Use “tar -x” and “gunzip” (or “tar -xz”, if available) to extract the package; then cd to the “live” directory. Then run:

./genMakefiles <os-platform>

where is your target platform - e.g., “linux” or “solaris” - defined by a “config.” file. This will generate a Makefile in the “live” directory and each subdirectory. Then run “make”.

  • If the “make” fails, you may need to make small modifications to the appropriate “config.” file, and then re-run “genMakefiles ”. (E.g., you may need to add another “-I\” flag to the COMPILE_OPTS definition.)
  • Some people (in particular, FreeBSD users) have reported that the GNU version of “make” - often called “gmake” - works better than their default, pre-installed version of “make”. (In particular, you should try using “gmake” if you encounter linking problems with the “ar” command.)
  • If you’re using “gcc” version 3.0 or greater: You may also wish to add the -Wno-deprecated flag to CPLUSPLUS_FLAGS.
  • If no “config.” file exists for your target platform, then try using one of the existing files as a template.

注意事项

1.如果点播的视频是720p以上的视频,需要改下OutPacketBuffer::maxSize大小(默认为100000), 在编译之前,修改 ./live/mediaServer/DynamicRTSPServer.cpp 文件,将OutPacketBuffer::maxSize设置大一些,比如说 500000,然后再执行 make

2.点播的视频文件的根目录为执行./live/mediaServer/live555MediaServer命令所在目录。

参考:

  • https://www.itengli.com/ffmpeg/

  • http://www.live555.com/liveMedia/#config-unix

  • https://ffmpeg.org/documentation.html