GStreamer源码编译安装脚本化_gstreamer-plugins 交叉编译,2024年最新程序员工作2年月薪12K

287 阅读3分钟
    res=$(echo $branch\_list |grep -E "^\\* ${v}$")
    ret=$(echo $branch\_list | grep -E "fatal|error")
    if [ "${ret}" != "" ];then
        echo $branch\_list;
        return 1
    fi
    if [ "$res" = "" ];then
        git checkout $v
        check_status $?
    fi
fi

}

download gstreamer

download_gst() { # remove directory if already exists rm_dir gstreamer{gstreamer} {gst_plugins_base} gst_plugins_good{gst\_plugins\_good} {gst_plugins_ugly} gst_plugins_bad{gst\_plugins\_bad} {gstreamer_vaapi} ${orc}

#Download source code to the specified directory
# mk\_dir ${gst\_src}
cd ${gst\_src}
echo "download and uncompress ..."

git clone -b ${gst\_version} https://gitlab.freedesktop.org/gstreamer/gstreamer.git
check_status $?

git clone https://gitlab.freedesktop.org/gstreamer/orc.git
check_status $?

git clone -b ${gst\_version} https://gitlab.freedesktop.org/gstreamer/gst-plugins-base.git
check_status $?

git clone -b ${gst\_version} https://gitlab.freedesktop.org/gstreamer/gst-plugins-good.git
check_status $?

git clone -b ${gst\_version} https://gitlab.freedesktop.org/gstreamer/gst-plugins-ugly.git
check_status $?

git clone -b ${gst\_version} https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad.git
check_status $?

git clone -b ${gst\_version} https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi.git
check_status $?

}

compile and install current directory source code

install_obj() { if [ "1"!=""];thenversion=1" != "" ];then version=1 else version=${gst_version} fi

# 当CPU总核心数n大于3时开启n-1个线程编译,否则开始n个线程
total\_core=$(grep 'core id' /proc/cpuinfo |wc -l)
if [ $total\_core -gt 3 ];then
	thread=$(expr $total\_core - 1)
else
	thread=${total\_core}
fi

# checkout branch
check_version ${version}

./autogen.sh
check_status $?
make -j${thread}
check_status $?
sudo make install
check_status $?

}

install gstreamer

install_gst() { sudo apt install git autoconf autopoint libtool bison flex gtk-doc-tools libglib2.0-dev libssl-dev libva-dev libgtk2.0-dev check_status $? # apt_install git autoconf autopoint libtool bison flex gtk-doc-tools libglib2.0-dev libssl-dev libva-dev libgtk2.0-dev

# download source code if directory not exist
if [ ! -d ${gstreamer} -o ! -d ${gst\_plugins\_base} -o ! -d ${gst\_plugins\_good}  -o ! -d ${orc} \
-o ! -d ${gst\_plugins\_ugly} -o ! -d ${gst\_plugins\_bad} -o ! -d ${gstreamer\_vaapi} ];then
    download_gst
fi

echo "\n\n\n------------------------install gstreamer------------------------"
cd ${gstreamer}
install_obj

echo "\n\n\n------------------------install orc------------------------"
cd ${orc}
git checkout ${orc\_version}
# install\_obj ${orc\_version}
if [ ! -f ./configure ];then
    $(./autogen.sh && make distclean)
fi
./configure
check_status $?
make -j4
check_status $?
sudo make install
check_status $?

echo "\n\n\n------------------------install gst\_plugins\_base------------------------"
cd ${gst\_plugins\_base}
# check and switch branch
check_version ${gst\_version}
# install\_obj
if [ ! -f ./configure ];then
    $(./autogen.sh && make distclean)
fi
./configure
check_status $?
make -j4
check_status $?
sudo make install
check_status $?

echo "\n\n\n------------------------install gst\_plugins\_good------------------------"
cd ${gst\_plugins\_good}
install_obj

echo "\n\n\n------------------------install gst\_plugins\_ugly------------------------"
cd ${gst\_plugins\_ugly}
install_obj

echo "\n\n\n------------------------install gst\_plugins\_bad------------------------"
cd ${gst\_plugins\_bad}
install_obj

echo "\n\n\n------------------------install gstreamer\_vaapi------------------------"
cd ${gstreamer\_vaapi}
install_obj

}

uninstall gstreamer

uninstall_gst() { ### uninstall gstreamer ### cd ${gstreamer_vaapi} sudo make uninstall make distclean

cd ${gst\_plugins\_bad}
sudo make uninstall
make distclean

cd ${gst\_plugins\_ugly}
sudo make uninstall
make distclean

cd ${gst\_plugins\_good}
sudo make uninstall
make distclean

cd ${gst\_plugins\_base}
sudo make uninstall
make distclean

cd ${gstreamer}
sudo make uninstall
make distclean

}

help_msg() { msg=" Usage: ./${shellname} [options]

options: install - download source code and install gstreamer and gst plugins uninstall - uninstall gstreamer and gst plugins

e.g. ./shellnameinstall./{shellname} install ./{shellname} uninstall

" echo "${msg}" }

main

if [ # -eq 1 ];then exe\_type=(echo "1" | tr 'A-Z' 'a-z' ) if [ "{exe_type}" != "install" -a "exe_type"!="uninstall"];thenecho"[error]unknowoption:{exe\_type}" != "uninstall" ];then echo "[error] unknow option: 1" help_msg exit 1; fi

echo "${exe\_type} gstreamer[y/n]:"
read choose;
echo "Your Choice:${choose}"
choose=$(echo "${choose}" | tr 'A-Z' 'a-z' )
if [ "X${choose}" != "Xy" ];then
    echo "Cancel ${exe\_type}"
    exit 1;
fi

sudo pwd

if [ "Xinstall" = "X${exe\_type}" ];then
    echo "install....."
    install_gst
elif [ "Xuninstall" = "X${exe\_type}"  ];then
    echo "uninstall....."
    uninstall_gst
fi

else help_msg fi


## 2. 新版代码(支持meson)【推荐】


Note: meson/ninja的要求Python3.6以上的版本,运行安装脚本前确认系统已经安装了3.6及以上版本的Python,以Ubuntu20.04为例系统自带Python3.8但没有python这个命令,但有Python3,手动添加一个软链接到python就好。  
 ![python not found](https://p3-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/d69260b0f1ac4b5c9c2d4c03d392d5e7~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAg5py65Zmo5a2m5Lmg5LmL5b-DQUk=:q75.awebp?rk3s=f64ab15b&x-expires=1772461096&x-signature=EbwX6kX027xe6YNSDMtMoEpZeNQ%3D)  
 添加python软连接



sudo ln -s /usr/bin/python3.8 /usr/bin/python


测试过的Gstreamer源码版本




> 

> ubuntu18.04: 1.18和1.19.1  

>  ubuntu20.04: 1.19.1

> 

> 

> 



只测试两个版本的源码在不同的Ubuntu版本下的安装,过程非常顺利(经历过make编译无休止的报错,才能体会到meson的好^\_^)



#!/bin/bash

###########################################

@file: install_gst_git.sh

Author: zbc

########################################### shellname=(basename(basename 0)

configure gst_version

orc_version="master"

gst_version="master"

gst_version="1.16"

gst_version="1.18"

gst_version="1.19.1" orc_version="orc-0.4.24" gst_src="${HOME}/gst"

Number of threads = cpu core - 1

core_num=(grepcoreid/proc/cpuinfowcl)thread=(grep 'core id' /proc/cpuinfo |wc -l) thread=(expr $core_num - 1)

mkdir -p ${gst_src}

rm_dir() { for i in "@"doif["@" do if [ "{i}" = "" ];then continue fi if [ -d i];thenrmrf{i} ];then rm -rf {i} fi done }

check_status() { code=$1

if [ "X${code}" != "X0" ];then
    echo "Error Code=${code}"
    exit $code
fi

}

check_version() { v=1if["X"="X1 if [ "X" = "X{v}" ];then return 0 else branch_list=(gitbranch)checkstatus(git branch) check_status ? res=(echo(echo branch_list |grep -E "^\* v{v}") if [ "res"=""];thengitcheckoutres" = "" ];then git checkout v check_status $? fi fi }

clone_gst_pkg() { # reference gitlab.freedesktop.org/gstreamer pkg_name="1"version="1" version="2" if [ "" = "pkg_name"];thenreturn1ficd{pkg\_name}" ];then return 1 fi cd {gst_src} echo -e "\n\n\n------------------------ clone pkg_name"if[d{pkg\_name} ------------------------" if [ -d {gst_src}/pkg_name];thencd{pkg\_name} ];then cd {gst_src}/pkg_namegitbranchif[{pkg\_name} git branch if [ ? -ne 0 ];then cd gst_srcrmdir{gst\_src} rm_dir {gst_src}/pkg_namegitclonehttps://gitlab.freedesktop.org/gstreamer/{pkg\_name} git clone https://gitlab.freedesktop.org/gstreamer/{pkg_name}.git check_status ?fielsegitclonehttps://gitlab.freedesktop.org/gstreamer/? fi else git clone https://gitlab.freedesktop.org/gstreamer/{pkg_name}.git check_status $? fi

if [ "${version}" = "" ];then
    return 0
fi

# Switch branches or restore working tree files
cd ${gst\_src}/${pkg\_name}
git pull
# git checkout ${version}
# check\_status $?
check_version ${version}

}

install_meson() { cur_dir=(pwd)meson_version="(pwd) meson\_version="1" if [ "{meson\_version}" = "" ];then meson\_version="0.57" fi # skip install if meson version is 0.5x install\_flag=(meson --version |grep -E "^0.5+") if [ "{install\_flag}" != "" ];then return fi meson\_src=~/meson cd ~ echo -e "\n\n\n------------------------ install meson ------------------------" # download source code if [ -d {meson_src} ];then cd meson_srcgitcheckout{meson\_src} git checkout {meson_version} if [ "X?"!="X0"];thencdrmdir{?}" != "X0" ];then cd - rm_dir {meson_src} git clone github.com/mesonbuild/… check_status ?cd? cd {meson_src} git checkout meson_versionfielsegitclonehttps://github.com/mesonbuild/meson.gitcheckstatus{meson\_version} fi else git clone https://github.com/mesonbuild/meson.git check_status ? cd meson_srcgitcheckout{meson\_src} git checkout {meson_version} fi sudo apt install python3-pip -y # python3 -m pip install meson # python3 setup.py install python3 setup.py install --root=dest check_status ?sudocprvdest//checkstatus? sudo cp -rv dest/* / check_status ? echo -e "\n\n\n------------------------ finish meson ------------------------" cd ${cur_dir} }

install_ninja() { cur_dir=(pwd)ninja_version="(pwd) ninja\_version="1" if [ "{ninja\_version}" = "" ];then ninja\_version="release" fi # ninja --version # if [ ? -eq 0 ];then # return # fi

install\_flag=$(ninja --version |grep -E "^${ninja\_version}")
if [ "${install\_flag}" != "" ];then
    return
fi

sudo apt install re2c -y

ninja\_src=~/ninja
cd ~
rm -rf ~/ninja
# sudo python3 -m pip install ninja
echo -e "\n\n\n------------------------ install ninja ------------------------"

if [ -d ${ninja\_src} ];then
    cd ${ninja\_src}
    git checkout v${ninja\_version}
    if [ "X${?}" != "X0" ];then
        cd -
        rm_dir ${ninja\_src} 
        git clone https://github.com/ninja-build/ninja.git
        check_status $?
        cd ${ninja\_src}
        git checkout v${ninja\_version}
    fi
else
    git clone https://github.com/ninja-build/ninja.git
    check_status $?
    cd ${ninja\_src}
    git checkout v${ninja\_version}
fi

./configure.py --bootstrap
check_status $?
sudo cp ninja /usr/bin/

echo -e "\n\n\n------------------------ finish ninja ------------------------"

cd ${cur\_dir}

}

compile and install current directory source code

install_obj() {

if [ -f ./meson.build ];then
    install_meson
    install_ninja "1.8.2"
    # meson build -Dprefix=/usr && ninja -C build && sudo ninja -C build install
    meson build
    check_status $?
    ninja -C build
    check_status $?
    sudo ninja -C build install
    check_status $?
    
elif [ -f ./autogen.sh ];then
    ./autogen.sh
    if [ $?  -eq 0 ];then
        make -j${thread} && sudo make install
        if [ $?  -eq 0 ];then
            return 0
        else
            ./configure 
            check_status $?
        fi
    else
        ./configure 
        check_status $?
    fi
    make -j${thread} && sudo make install
    check_status $?
elif [ -f ./configure  ];then
    ./configure 
    check_status $?
    make -j${thread} && sudo make install
    check_status $?
else
    pwd
    echo "[error] cannot found meson.build or autogen.sh"
    exit 1
fi

}

build_and_install_pkg() { for i in "@"doif["@" do if [ "{i}" = "" ];then continue fi

    if [ "${i}" = "orc" ];then
        clone_gst_pkg "$i" "${orc\_version}"
        install_obj
        continue
    fi
    clone_gst_pkg "$i" "${gst\_version}"
    install_obj
done

}

uninstall_pkg() { # reverse pkg list for i in (seq(seq # |tac ) # for i in "@"dopkg_name=@" do pkg\_name=(eval echo '"'"i") if [ "${pkg_name}" = "" ];then continue fi

    pkg\_dir="${gst\_src}/${pkg\_name}"
    if [ ! -d ${pkg\_dir} ];then
        continue
    fi
    cd ${pkg\_dir}
    echo -e "\n\n\n------------------------ uninstall ${pkg\_name} ------------------------"
    
    if [ -f ./meson.build ];then
        sudo ninja -C build uninstall
        sudo ninja -C build  clean
    elif [ -f ./autogen.sh -o -f ./configure ];then
        sudo make uninstall
        make distclean
    else
        pwd
        echo "[error] cannot found meson.build or autogen.sh"
    fi
done

}

help_msg() { msg=" Usage: ./${shellname} [options]

options: install - download source code and install gstreamer and gst plugins uninstall - uninstall gstreamer and gst plugins

e.g. ./shellnameinstall./{shellname} install ./{shellname} uninstall

" echo "${msg}" }

main

if [ # -eq 1 ];then exe\_type=(echo "1" | tr 'A-Z' 'a-z' ) if [ "{exe_type}" != "install" -a "exe_type"!="uninstall"];thenecho"[error]unknowoption:{exe\_type}" != "uninstall" ];then echo "[error] unknow option: 1" help_msg exit 1; fi

echo "${exe\_type} gstreamer[y/n]:"
read choose;
echo "Your Choice:${choose}"
choose=$(echo "${choose}" | tr 'A-Z' 'a-z' )
if [ "X${choose}" != "Xy" ];then
    echo "Cancel ${exe\_type}"
    exit 1;
fi

$(sudo ls)

sudo apt install -y git autoconf autopoint libtool bison flex gtk-doc-tools libglib2.0-dev libssl-dev libva-dev libgtk2.0-dev
# sudo apt install meson

if [ "Xinstall" = "X${exe\_type}" ];then
    echo "install....."
    # install\_gst
    build_and_install_pkg "gstreamer" "orc" "gst-plugins-base" "gst-plugins-good" "gst-plugins-ugly" "gst-plugins-bad" "gstreamer-vaapi"
elif [ "Xuninstall" = "X${exe\_type}"  ];then
    echo "uninstall....."
    # uninstall\_gst
    uninstall_pkg "gstreamer" "orc" "gst-plugins-base" "gst-plugins-good" "gst-plugins-ugly" "gst-plugins-bad" "gstreamer-vaapi"
fi

else help_msg fi




![img](https://p3-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/d6d8f2a9855f4a23b0812412383d68e8~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAg5py65Zmo5a2m5Lmg5LmL5b-DQUk=:q75.awebp?rk3s=f64ab15b&x-expires=1772461096&x-signature=rdHU4IehNtKM7LhPMy2WyPorSZw%3D)
![img](https://p3-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/743a4ced6e6a4ee1aaf4e21aca99055b~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAg5py65Zmo5a2m5Lmg5LmL5b-DQUk=:q75.awebp?rk3s=f64ab15b&x-expires=1772461096&x-signature=4YTijU8OPZvYubCzt0No%2FxDw7ZA%3D)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上物联网嵌入式知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新**

**[如果你需要这些资料,可以戳这里获取](https://gitee.com/vip204888)**