├── LICENSE ├── README.md ├── build_ffmpeg.sh ├── data ├── images │ ├── 1920_1080.jpg │ ├── 1920_1080_nv12.yuv │ ├── 360x640_snake.jpeg │ └── 720x1280_baby.jpeg └── videos │ ├── jellyfish-3-mbps-hd-h264.mkv │ └── jellyfish-3-mbps-hd-hevc.mkv ├── env.sh ├── ffmpeg ├── ffmpeg-4.2.tar.gz └── ffmpeg-4.4.tar.gz ├── ffmpeg4.2_mlu300.patch ├── ffmpeg4.4_mlu300.patch ├── requirements.sh └── tools └── clean_ffmpeg.sh /LICENSE: -------------------------------------------------------------------------------- 1 | Cambricon MLU Media Process Platform(MLU MPP) SDK 2 | Copyright (C) [2019] by Cambricon, Inc. All rights reserved 3 | 4 | This file is part of FFmpeg. 5 | 6 | FFmpeg is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | FFmpeg is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with FFmpeg; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 寒武纪® FFmpeg-MLU 3 | ==================================== 4 | 5 | 寒武纪® MLU硬件平台内置了视频、图像相关的硬件加速编码器和解码器。为了提高计算效率,同时保障产品的可用性和用户使用的便捷性,寒武纪提供了FFmpeg-MLU SDK软件解决方案。FFmpeg-MLU集成了寒武纪硬件加速卡的视频、图像硬件编解码单元和硬件AI计算单元,实现了基于Cambricon MLU硬件加速的视频编码、解码和AI计算;其中硬件视频图像编解码单元基于寒武纪CNCodec加速库开发。依靠FFmpeg音视频编解码和流媒体协议等模块,Cambricon视频、图像编解码单元及AI加速单元可以很便捷的实现高性能硬件加速的多媒体处理pipeline。 6 | 7 | ​寒武纪 FFmpeg-MLU 使用纯C接口实现硬件加速的图像、视频编解码和常见图像算法处理,完全兼容社区FFmpeg;符合社区FFmpeg代码开发及命令行使用规范,同时也符合社区FFmpeg hwaccel硬件加速框架规范( https://trac.ffmpeg.org/wiki/HWAccelIntro ),实现了硬件内存管理、硬件加速处理模块与cpu模块的流程化兼容处理等。 8 | 9 | 关于FFmpeg-MLU的更详细介绍请查阅官网或联系对接工作人员。 10 | -------------------------------------------------------------------------------- /build_ffmpeg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | WORK_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}") ) 4 | 5 | if [ -z $1 ]; then 6 | mkdir -p install 7 | INSTALL_PATH=${WORK_DIR}/install 8 | else 9 | INSTALL_PATH=$1 10 | fi 11 | 12 | if [ -z $2 ]; then 13 | FFMPEG_VERSION="4.4" 14 | else 15 | FFMPEG_VERSION=$2 16 | fi 17 | 18 | MLU_CODEC=true 19 | MLU_FILTER=true 20 | LIBRARY_TYPE=shared 21 | COMPILE_MODE=release 22 | FFMPEG_MLU_SRC_FILE="ffmpeg-${FFMPEG_VERSION}.tar.gz" 23 | 24 | # Check NEUWARE_HOME PATH 25 | if [ -z ${NEUWARE_HOME} ]; then 26 | echo "Error: please setting NEUWARE_HOME environment variable" 27 | exit 1 28 | fi 29 | 30 | # Check library type 31 | if [[ "$LIBRARY_TYPE" != "shared" && "$LIBRARY_TYPE" != "static" ]]; then 32 | echo "Unsupported library type: $LIBRARY_TYPE" 33 | exit 1 34 | fi 35 | 36 | # Check CPU architecture 37 | ARCH=$(uname -m) 38 | if [[ "$ARCH" != "x86_64" && "$ARCH" != "aarch64" && "$ARCH" != "loongarch64" ]]; then 39 | echo "Unsupported architecture: $ARCH" 40 | exit 1 41 | fi 42 | 43 | # Check whether into Docker 44 | if [ -f /.dockerenv ]; then 45 | IN_DOCKER=true 46 | else 47 | IN_DOCKER=false 48 | fi 49 | 50 | # Prepare FFmpeg source code 51 | extract_ffmpeg() { 52 | if [ -f $FFMPEG_MLU_SRC_FILE ]; then 53 | echo "Using local FFmpeg source file: $FFMPEG_MLU_SRC_FILE" 54 | else 55 | echo "Error: not fond local FFmpeg source file: $FFMPEG_MLU_SRC_FILE" 56 | exit 1 57 | fi 58 | tar -xf $FFMPEG_MLU_SRC_FILE 59 | } 60 | 61 | # Config、compile and install FFmpeg 62 | compile_ffmpeg() { 63 | # Check MLU CODEC and MLU FILTER 64 | if [ "$MLU_CODEC" == "true" ]; then 65 | if [ "$MLU_FILTER" == "true" ]; then 66 | MLU_FLAGS="--enable-mlu --enable-mlumpp --enable-mlufilter" 67 | else 68 | MLU_FLAGS="--enable-mlu --enable-mlumpp" 69 | fi 70 | else 71 | MLU_FLAGS="" 72 | fi 73 | # Check lib mode 74 | if [ "$LIBRARY_TYPE" == "shared" ]; then 75 | SHARED_FLAGS="--disable-static --enable-shared" 76 | elif [ "$LIBRARY_TYPE" == "static" ]; then 77 | SHARED_FLAGS="--enable-static --disable-shared" 78 | fi 79 | # Check yasm and nasm 80 | if ! command -v yasm &> /dev/null && ! command -v nasm &> /dev/null; then 81 | NASM_YASM_FLAGS="--disable-x86asm" 82 | else 83 | NASM_YASM_FLAGS="" 84 | fi 85 | # Check libmp3lame 86 | check_libmp3lame=$(find /usr/ -name libmp3lame*) 87 | if [ -z "$check_libmp3lame" ]; then 88 | LIBMP3LAME_FLAGS="" 89 | else 90 | LIBMP3LAME_FLAGS="--enable-libmp3lame" 91 | fi 92 | # Check release mode 93 | if [ "$COMPILE_MODE" == "debug" ]; then 94 | COMPILE_MODE_FLAGS="--enable-debug --disable-optimizations --disable-stripping" 95 | else 96 | COMPILE_MODE_FLAGS="--enable-optimizations --enable-stripping" 97 | fi 98 | 99 | patch -p1 -i ../../ffmpeg4.4_mlu300.patch 100 | rm -rf build && mkdir -pv build 101 | pushd build 102 | ../configure \ 103 | --prefix=$INSTALL_PATH \ 104 | --arch=$ARCH \ 105 | --extra-cflags="-I${NEUWARE_HOME}/include" \ 106 | --extra-ldflags="-L${NEUWARE_HOME}/lib64" \ 107 | --extra-libs="-lcnrt -lcncodec_v3 -lcndrv -lcndev" \ 108 | $MLU_FLAGS \ 109 | --enable-gpl \ 110 | --enable-version3 \ 111 | $SHARED_FLAGS \ 112 | $NASM_YASM_FLAGS $COMPILE_MODE_FLAGS \ 113 | $LIBMP3LAME_FLAGS 114 | 115 | make -j$(nproc) 116 | 117 | SUDO=sudo 118 | if [ "$IN_DOCKER" = true ]; then 119 | if [ "$(id -u)" != "0" ]; then 120 | echo "Running inside Docker as non-root user. Please ensure the necessary dependencies are installed manually." 121 | else 122 | SUDO="" 123 | fi 124 | fi 125 | # Check permission of install directory 126 | if [ -w "$INSTALL_PATH" ]; then 127 | make install 128 | else 129 | $SUDO make install 130 | fi 131 | popd 132 | } 133 | 134 | clean_ffmpeg() { 135 | pushd $WORK_DIR/ffmpeg 136 | rm -rf ffmpeg-${FFMPEG_VERSION} 137 | popd 138 | } 139 | 140 | # Main 141 | pushd ffmpeg 142 | extract_ffmpeg 143 | pushd ffmpeg-${FFMPEG_VERSION} 144 | compile_ffmpeg 145 | popd 146 | popd 147 | clean_ffmpeg 148 | 149 | echo "" 150 | echo "FFmpeg ${FFMPEG_VERSION} has been successfully installed to ${INSTALL_PATH}" 151 | -------------------------------------------------------------------------------- /data/images/1920_1080.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cambricon/ffmpeg-mlu/359416a595c76ad0fc7c033047b26e17cb10fe14/data/images/1920_1080.jpg -------------------------------------------------------------------------------- /data/images/1920_1080_nv12.yuv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cambricon/ffmpeg-mlu/359416a595c76ad0fc7c033047b26e17cb10fe14/data/images/1920_1080_nv12.yuv -------------------------------------------------------------------------------- /data/images/360x640_snake.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cambricon/ffmpeg-mlu/359416a595c76ad0fc7c033047b26e17cb10fe14/data/images/360x640_snake.jpeg -------------------------------------------------------------------------------- /data/images/720x1280_baby.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cambricon/ffmpeg-mlu/359416a595c76ad0fc7c033047b26e17cb10fe14/data/images/720x1280_baby.jpeg -------------------------------------------------------------------------------- /data/videos/jellyfish-3-mbps-hd-h264.mkv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cambricon/ffmpeg-mlu/359416a595c76ad0fc7c033047b26e17cb10fe14/data/videos/jellyfish-3-mbps-hd-h264.mkv -------------------------------------------------------------------------------- /data/videos/jellyfish-3-mbps-hd-hevc.mkv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cambricon/ffmpeg-mlu/359416a595c76ad0fc7c033047b26e17cb10fe14/data/videos/jellyfish-3-mbps-hd-hevc.mkv -------------------------------------------------------------------------------- /env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CUR_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}") ) 3 | 4 | if [ -z ${NEUWARE_HOME} ]; then 5 | echo "Error: not set NEUWARE_HOME environment variable" 6 | exit 7 | fi 8 | 9 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${CUR_DIR}/install/lib:${NEUWARE_HOME}/lib64 10 | -------------------------------------------------------------------------------- /ffmpeg/ffmpeg-4.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cambricon/ffmpeg-mlu/359416a595c76ad0fc7c033047b26e17cb10fe14/ffmpeg/ffmpeg-4.2.tar.gz -------------------------------------------------------------------------------- /ffmpeg/ffmpeg-4.4.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cambricon/ffmpeg-mlu/359416a595c76ad0fc7c033047b26e17cb10fe14/ffmpeg/ffmpeg-4.4.tar.gz -------------------------------------------------------------------------------- /requirements.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | WORK_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}") ) 4 | 5 | # Check system 6 | if [ -f /etc/os-release ]; then 7 | . /etc/os-release 8 | OS=$ID 9 | VERSION_ID=$VERSION_ID 10 | else 11 | echo "Unsupported operating system" 12 | exit 1 13 | fi 14 | if [[ "$OS" != "ubuntu" && "$OS" != "centos" && "$OS" != "kylin" && "$OS" != "debian" ]]; then 15 | echo "Unsupported operating system: $OS" 16 | exit 1 17 | fi 18 | 19 | # Check whether into Docker 20 | if [ -f /.dockerenv ]; then 21 | IN_DOCKER=true 22 | else 23 | IN_DOCKER=false 24 | fi 25 | 26 | # Install necessary dependencies 27 | install_dependencies() { 28 | if [ "$IN_DOCKER" = true ] && [ "$(id -u)" != "0" ]; then 29 | echo "Running inside Docker as non-root user. Please ensure the necessary dependencies are installed manually." 30 | fi 31 | 32 | SUDO=sudo 33 | if [ "$(id -u)" = "0" ]; then 34 | SUDO="" 35 | fi 36 | if [ "$OS" == "ubuntu" ]; then 37 | $SUDO apt-get update 38 | $SUDO apt-get install -y autoconf automake build-essential cmake git-core libtool pkg-config wget 39 | $SUDO apt-get install -y libass-dev libfreetype6-dev libsdl2-dev libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev texinfo zlib1g-dev yasm nasm libmp3lame-dev 40 | elif [ "$OS" == "debian" ]; then 41 | $SUDO apt-get update 42 | $SUDO apt-get install -y autoconf automake build-essential cmake git-core libtool pkg-config wget 43 | $SUDO apt-get install -y libass-dev libfreetype6-dev libsdl2-dev libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev texinfo zlib1g-dev yasm nasm libmp3lame-dev 44 | elif [ "$OS" == "centos" ]; then 45 | $SUDO yum install -y epel-release 46 | $SUDO yum groupinstall -y "Development Tools" 47 | $SUDO yum install -y autoconf automake cmake git libtool pkgconfig 48 | $SUDO yum install -y freetype-devel libass-devel libva-devel libvdpau-devel libvorbis-devel libxcb-devel libX11-devel libXext-devel libXfixes-devel zlib-devel yasm nasm lame lame-devel 49 | elif [ "$OS" == "kylin" ]; then 50 | $SUDO apt-get update 51 | $SUDO apt-get install -y autoconf automake build-essential cmake git libtool pkg-config wget 52 | $SUDO apt-get install -y libass-dev libfreetype6-dev libsdl2-dev libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev texinfo zlib1g-dev yasm nasm libmp3lame-dev 53 | # $SUDO yum update -y 54 | # $SUDO yum install -y autoconf automake cmake git libtool pkgconfig wget 55 | # $SUDO yum install -y freetype-devel libass-devel libva-devel libvdpau-devel libvorbis-devel libxcb-devel libX11-devel libXext-devel libXfixes-devel zlib-devel yasm nasm lame lame-devel 56 | fi 57 | } 58 | 59 | # Main 60 | install_dependencies 61 | 62 | # Check yasm and nasm 63 | if ! command -v yasm &> /dev/null && ! command -v nasm &> /dev/null; then 64 | echo "Error: yasm or nams instal failed!!!!!!" 65 | fi 66 | 67 | echo "" 68 | echo "FFmpeg dependencies has been installed successfully" 69 | -------------------------------------------------------------------------------- /tools/clean_ffmpeg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Check if the script is run with sudo privileges 6 | if [ "$(id -u)" -ne 0 ]; then 7 | echo "Please run this script with sudo privileges." 8 | exit 1 9 | fi 10 | 11 | # Detect the OS distribution 12 | if [ -f /etc/os-release ]; then 13 | . /etc/os-release 14 | OS=$ID 15 | else 16 | echo "Unable to detect the operating system." 17 | exit 1 18 | fi 19 | 20 | # Function to clean FFmpeg on Ubuntu 21 | clean_ubuntu() { 22 | echo "Detected Ubuntu system, starting cleanup..." 23 | 24 | # Remove ffmpeg binary 25 | echo "Removing ffmpeg binary..." 26 | apt-get remove --purge -y ffmpeg 27 | 28 | # Remove libav related libraries 29 | echo "Removing libav related libraries..." 30 | apt-get remove --purge -y libavcodec* libavdevice* libavfilter* libavformat* libavresample* libavutil* libswscale* libswresample* 31 | 32 | # Remove leftover configuration files and dependencies 33 | echo "Removing leftover configuration files and dependencies..." 34 | apt-get autoremove --purge -y 35 | apt-get clean 36 | 37 | # Remove potential ffmpeg files 38 | echo "Removing potential ffmpeg files..." 39 | rm -rf /usr/local/bin/ffmpeg /usr/local/bin/ffplay /usr/local/bin/ffprobe 40 | rm -rf /usr/local/lib/libav* /usr/local/lib/libsw* /usr/local/lib/libpostproc* 41 | rm -rf /usr/bin/ffmpeg /usr/bin/ffplay /usr/bin/ffprobe 42 | rm -rf /usr/lib/libav* /usr/lib/libsw* /usr/lib/libpostproc* 43 | rm -rf /usr/local/include/libav* /usr/local/include/libsw* /usr/local/include/libpostproc* 44 | rm -rf /usr/include/libav* /usr/include/libsw* /usr/include/libpostproc* 45 | rm -rf /usr/lib/x86_64-linux-gnu/libav* /usr/lib/x86_64-linux-gnu/libsw* /usr/lib/x86_64-linux-gnu/libpostproc* 46 | rm -rf /usr/share/ffmpeg 47 | } 48 | 49 | # Function to clean FFmpeg on CentOS 50 | clean_centos() { 51 | echo "Detected CentOS system, starting cleanup..." 52 | 53 | # Remove ffmpeg binary 54 | echo "Removing ffmpeg binary..." 55 | yum remove -y ffmpeg 56 | 57 | # Remove libav related libraries 58 | echo "Removing libav related libraries..." 59 | yum remove -y libavcodec libavdevice libavfilter libavformat libavresample libavutil libswscale libswresample 60 | 61 | # Remove leftover configuration files and dependencies 62 | echo "Removing leftover configuration files and dependencies..." 63 | yum autoremove -y 64 | yum clean all 65 | 66 | # Remove potential ffmpeg files 67 | echo "Removing potential ffmpeg files..." 68 | rm -rf /usr/local/bin/ffmpeg /usr/local/bin/ffplay /usr/local/bin/ffprobe 69 | rm -rf /usr/local/lib/libav* /usr/local/lib/libsw* /usr/local/lib/libpostproc* 70 | rm -rf /usr/local/include/libav* /usr/local/include/libsw* /usr/local/include/libpostproc* 71 | rm -rf /usr/bin/ffmpeg /usr/bin/ffplay /usr/bin/ffprobe 72 | rm -rf /usr/lib/libav* /usr/lib/libsw* /usr/lib/libpostproc* 73 | rm -rf /usr/include/libav* /usr/include/libsw* /usr/include/libpostproc* 74 | rm -rf /usr/share/ffmpeg 75 | } 76 | 77 | # Function to clean common files in /usr excluding /usr/local/neuware 78 | clean_common_files() { 79 | echo "Checking for any remaining ffmpeg related files in /usr, excluding /usr/local/neuware..." 80 | find /usr -path /usr/local/neuware -prune -o -name '*ffmpeg*' -exec rm -rf {} \; 81 | find /usr -path /usr/local/neuware -prune -o -name '*avconv*' -exec rm -rf {} \; 82 | echo "FFmpeg and related files in /usr have been completely removed." 83 | } 84 | 85 | # Call the appropriate clean function based on detected OS 86 | case "$OS" in 87 | ubuntu) 88 | clean_ubuntu 89 | ;; 90 | debian) 91 | clean_ubuntu 92 | ;; 93 | centos) 94 | clean_centos 95 | ;; 96 | kylin) 97 | clean_centos 98 | ;; 99 | *) 100 | echo "Unsupported operating system: $OS" 101 | exit 1 102 | ;; 103 | esac 104 | 105 | # Call the common file cleaning function 106 | clean_common_files 107 | 108 | exit 0 109 | --------------------------------------------------------------------------------