树莓派-编译带omx硬件加速的ffmpeg

缘起

    最近树莓派3b上播放的视频质量越来越高,对于mkv格式来说由于本身就mp4类的封装,解码压力不是很大,但是对于rmvb、rm格式的视频,由于需要实时转码,压力就非常大了,使用cpu解码的话即使100%占用,解码也是非常的卡。

    而ffmpeg默认的apt方式安装,不自带omx硬解码的支持,因此有了此次ffmpeg源码编译的折腾。

折腾过程

1、安装x264解码库

    由于ffmpeg硬解码需要使用到x264库,因此在编译前需要先按照x264,使用下面的命令安装即可

 sudo apt install x264


2、源码编译ffmpeg

    1)首先下载ffmpeg源码,如果能fq,可以直接代理git pull ffmepg的github源码,像下面一样

        git pull https://github.com/FFmpeg/FFmpeg.git

         如果不能fq,可以在github下载release的最新源码,地址在:https://github.com/FFmpeg/FFmpeg/releases

    2)cd到ffmpeg的源码目录,就可以开始编译步骤啦,先configure一下,如果缺少什么库可以查下使用apt安装就好,其中enable-omx和enable-omx-rpi就是开启树莓派硬解码的选项


    ./configure \        
        --prefix=/usr --extra-version='loong-compile.`date "+%m-%d_%H:%M"`' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth  --enable-omx --enable-libx264 --enable-shared \
        --enable-version3 \
        --enable-nonfree \
        --enable-static \
        --enable-ffmpeg \
        --enable-libx264 \
        --enable-mmal \
        --enable-omx \
        --enable-omx-rpi \
        --enable-encoder=libx264 \
        --enable-decoder=h264 \
        --enable-encoder=aac \
        --enable-decoder=aac \
        --enable-encoder=ac3 \
        --enable-decoder=ac3 \
        --enable-encoder=rawvideo \
        --enable-decoder=rawvideo \
        --enable-muxer=flv \
        --enable-demuxer=flv \
        --enable-muxer=mp4 \
        --enable-demuxer=mpegvideo \
        --enable-muxer=matroska \
        --enable-demuxer=matroska \
        --enable-muxer=wav \
        --enable-demuxer=wav \
        --enable-muxer='pcm*' \
        --enable-demuxer='pcm*' \
        --enable-muxer=rawvideo \
        --enable-demuxer=rawvideo \
        --enable-parser=h264 \
        --enable-parser=aac \
        --enable-protocol=file \
        --enable-protocol=tcp \
        --enable-protocol=rtmp \
        --enable-protocol=cache \
        --enable-protocol=pipe \
        --enable-filter=aresample \
        --enable-filter=allyuv \
        --enable-filter=scale \
        --enable-indev=v4l2 \
        --enable-indev=alsa \
        --enable-encoder=h264_omx \
        --enable-hwaccel=h264_mmal \
        --enable-decoder=h264_mmal \
        --enable-nonfree \
        --enable-static \
        --enable-ffmpeg \
        --enable-libx264 \
        --enable-mmal \
        --enable-omx \
        --enable-omx-rpi \
        --enable-encoder=libx264 \
        --enable-decoder=h264 \
        --enable-encoder=aac \
        --enable-decoder=aac \
        --enable-encoder=ac3 \
        --enable-decoder=ac3 \
        --enable-encoder=rawvideo \
        --enable-decoder=rawvideo \
        --enable-muxer=flv \
        --enable-demuxer=flv \
        --enable-muxer=mp4 \
        --enable-demuxer=mpegvideo \
        --enable-muxer=matroska \
        --enable-demuxer=matroska \
        --enable-muxer=wav \
        --enable-demuxer=wav \
        --enable-muxer='pcm*' \
        --enable-demuxer='pcm*' \
        --enable-muxer=rawvideo \
        --enable-demuxer=rawvideo \
        --enable-parser=h264 \
        --enable-parser=aac \
        --enable-protocol=file \
        --enable-protocol=tcp \
        --enable-protocol=rtmp \
        --enable-protocol=cache \
        --enable-protocol=pipe \
        --enable-filter=aresample \
        --enable-filter=allyuv \
        --enable-filter=scale \
        --enable-indev=v4l2 \
        --enable-indev=alsa \
        --enable-encoder=h264_omx \
        --enable-hwaccel=h264_mmal \
        --enable-libfreetype \
        --enable-libfontconfig \
        --enable-libfribidi \
        --enable-decoder=h264_mmal

    

    3)配置好之后直接make 安装就好,make后的-j参数是使用多少线程编译,由于树莓派四核cpu,8线程比较合适

    make -j8
    sudo make install


至此带omx硬解码的ffmpeg就安装成功啦


3、ffmpeg使用硬解码

 ffmpeg -re -ss 0 -i ooxx.rm  -c:v h264_omx  -acodec aac -af volume=1 -r film -f flv

    如上命令中 -c:v h264_omx即是使用omx硬解码进行视频转码了。


3、参考文档

http://www.yanglajiao.com/article/sbdx/75110126

https://github.com/FFmpeg/FFmpeg



发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。