diff --git a/thirdparty/FFmpeg/FFmpeg_oh_test.patch b/thirdparty/FFmpeg/FFmpeg_oh_test.patch new file mode 100644 index 0000000000000000000000000000000000000000..6c36918989985f5df036c627966bc235d7c42945 --- /dev/null +++ b/thirdparty/FFmpeg/FFmpeg_oh_test.patch @@ -0,0 +1,12 @@ +diff -Naur FFmpeg-n6.0/tests/md5.sh FFmpeg-n6.0_patch/tests/md5.sh +--- FFmpeg-n6.0/tests/md5.sh 2023-05-30 20:19:15.182858198 +0800 ++++ FFmpeg-n6.0_patch/tests/md5.sh 2023-05-31 09:13:47.753463704 +0800 +@@ -1,7 +1,7 @@ + # try to find an md5 program + + if [ X"$(echo | md5sum -b 2> /dev/null)" != X ]; then +- do_md5sum() { md5sum -b $1; } ++ do_md5sum() { md5sum $1; } + elif [ X"$(echo | command md5 2> /dev/null)" != X ]; then + do_md5sum() { command md5 $1 | sed 's#MD5 (\(.*\)) = \(.*\)#\2 *\1#'; } + elif [ -x /sbin/md5 ]; then diff --git a/thirdparty/FFmpeg/HPKBUILD b/thirdparty/FFmpeg/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..0b2796757eea32331432f26ce2773730882d1fef --- /dev/null +++ b/thirdparty/FFmpeg/HPKBUILD @@ -0,0 +1,178 @@ +# Contributor: Jeff Han +# Maintainer: Jeff Han +pkgname=FFmpeg +pkgver=n6.0 +pkgrel=0 +pkgdesc="FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata." +url="https://github.com/FFmpeg/FFmpeg/" +archs=("armeabi-v7a" "arm64-v8a") +license="GPL2/GPL3/LGPL3" +depends=() +makedepends=() +source="https://github.com/FFmpeg/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +autounpack=false +downloadpackage=true +buildtools="configure" + +builddir=$pkgname-${pkgver} +packagename=$builddir.tar.gz +source envset.sh +buildhost=true + +cpu= +ldflags= +prepare() { + if [ $buildhost == true ] + then + tar -zxf $packagename + cd $builddir + ./configure --enable-static --enable-shared --disable-doc --disable-htmlpages --target-os=linux --disable-optimizations --prefix=`pwd`/hostbuild > `pwd`/build.log 2>&1 + make -j4 >> `pwd`/build.log 2>&1 + make install >> `pwd`/build.log 2>&1 + export LD_LIBRARY_PATH=`pwd`/hostbuild/lib:$LD_LIBRARY_PATH + sed -i 's/include $(SRC_PATH)\/tests\/fate\/source.mak/#include $(SRC_PATH)\/tests\/fate\/source.mak/g' tests/Makefile + make check -j4 >> `pwd`/build.log 2>&1 + ret=$? + buildhost=false + cd $OLDPWD + fi + + mkdir $pkgname-$ARCH-build + tar -zxf $packagename -C $pkgname-$ARCH-build + cd $pkgname-$ARCH-build/$builddir + patch -p1 < ../../FFmpeg_oh_test.patch + cd $OLDPWD + + if [ $ARCH == "armeabi-v7a" ] + then + setarm32ENV + cpu=arm + ldflags="-L${OHOS_SDK}/native/sysroot/usr/lib/arm-linux-ohos" + fi + if [ $ARCH == "arm64-v8a" ] + then + setarm64ENV + cpu=aarch64 + ldflags="-L${OHOS_SDK}/native/sysroot/usr/lib/aarch64-linux-ohos" + fi + + return $ret +} + +build() { + cd $pkgname-$ARCH-build/$builddir + ./configure "$@" --disable-asm --enable-cross-compile --disable-x86asm --enable-static --enable-shared --disable-doc --disable-htmlpages --target-os=linux --disable-optimizations --cpu=$cpu --cc=${CC} --ld=${CC} --strip=${STRIP} --host-cc="${CC}" --host-ld="${CC}" --host-os=linux --host-ldflags=${ldflags} --sysroot=${OHOS_SDK}/native/sysroot > `pwd`/build.log 2>&1 + make -j4 >> `pwd`/build.log 2>&1 + ret=$? + cd $OLDPWD + return $ret +} +package() { + cd $pkgname-$ARCH-build/$builddir + make install >> `pwd`/build.log 2>&1 + cd $OLDPWD + if [ $ARCH == "armeabi-v7a" ] + then + unsetarm32ENV + fi + if [ $ARCH == "arm64-v8a" ] + then + unsetarm64ENV + fi + unset cpu + unset ldflags +} +checktestfiles() { + cd $pkgname-$ARCH-build/$builddir/tests/ref + + tmpdir=("fate" "acodec" "lavf" "lavf-fate" "pixfmt" "seek" "vsynth") + for dir in ${tmpdir[*]} + do + for file in `ls $dir` + do + if [ ! -f $dir/$file ]; then + continue + fi + str=`cat $dir/$file | grep "\*tests"` + if [ ! -z "$str" ] + then + sed -i 's/\*tests/tests/g' $dir/$file + fi + done + done + + cd $OLDPWD +} + +copyhostbin() { + file=$1 + if [[ -f tests/$file ]] && [[ ! -f tests/$file.${ARCH} ]] + then + mv tests/$file tests/$file.${ARCH} + cp ../../$builddir/tests/$file tests/$file + fi +} + +check() { + cd $pkgname-$ARCH-build/$builddir + # disable running cmd + sed -i 's/ $(Q)$(SRC_PATH)\/tests\/fate-run.sh/# $(Q)$(SRC_PATH)\/tests\/fate-run.sh/g' tests/Makefile + # disable check git sources + sed -i 's/include $(SRC_PATH)\/tests\/fate\/source.mak/#include $(SRC_PATH)\/tests\/fate\/source.mak/g' tests/Makefile + # disable check ffprobe,this use xmllint command, which ohos is not support + sed -i 's/include $(SRC_PATH)\/tests\/fate\/ffprobe.mak/#include $(SRC_PATH)\/tests\/fate\/ffprobe.mak/g' tests/Makefile + + # change x86 cmd for generate test target + mv ffmpeg ffmpeg.${ARCH} + cp ../../$builddir/ffmpeg ./ + retrytimes=0 + ret=0 + while true + do + make check -j4 >> `pwd`/build.log 2>&1 + if [ $? -eq 0 ] + then + break; + fi + + copyhostbin base64 + copyhostbin audiomatch + copyhostbin audiogen + copyhostbin videogen + copyhostbin tiny_psnr + copyhostbin tiny_ssim + copyhostbin rotozoom + + let retrytimes=$retrytimes+1 + if [ $retrytimes -gt 4 ] + then + ret=1 + break + fi + done + + mv ffmpeg.${ARCH} ffmpeg + for file in `ls tests/*.${ARCH}` + do + tmpfile=${file%.*} + mv $file $tmpfile + done + + # reduction running cmd for real test + sed -i 's/# $(Q)$(SRC_PATH)\/tests\/fate-run.sh/ $(Q)$(SRC_PATH)\/tests\/fate-run.sh/g' tests/Makefile + cd $OLDPWD + checktestfiles + + echo "The test must be on an OpenHarmony device!" + # skip running test on host + # real test CMD + # make check + + return $ret +} + +# 清理环境 +cleanbuild(){ + rm -rf ${PWD}/${builddir} ${PWD}/$pkgname-arm64-v8a-build ${PWD}/$pkgname-armeabi-v7a-build #${PWD}/$packagename +} diff --git a/thirdparty/FFmpeg/OAT.xml b/thirdparty/FFmpeg/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..96937ea08644b79312d0ced7c0b3eb1e845108ee --- /dev/null +++ b/thirdparty/FFmpeg/OAT.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/thirdparty/FFmpeg/README.OpenSource b/thirdparty/FFmpeg/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..e32dad23be27914927cb83dfd93d712532a09ee3 --- /dev/null +++ b/thirdparty/FFmpeg/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "FFmpge", + "License": "GPL2/GPL3/LGPL3 license", + "License File": "LICENSES", + "Version Number": "n6.0", + "Owner": "cmxud@isoftstone.com", + "Upstream URL": "https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n6.0.tar.gz", + "Description": "FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata." + } +] diff --git a/thirdparty/FFmpeg/README_zh.md b/thirdparty/FFmpeg/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..5f89970e156e1fe7c078dc1ba55be84acff119ec --- /dev/null +++ b/thirdparty/FFmpeg/README_zh.md @@ -0,0 +1,13 @@ +# FFmpeg三方库说明 +## 功能简介 + FFmpeg是领先的多媒体框架,能够解码、编码、转码、mux、demux、流式传输、过滤和播放人类和机器创建的任何东西, +可以运行在linux,mac,windows等平台; +## 使用约束 +- IDE版本:DevEco Studio 3.1 Beta2 +- SDK版本:ohos_sdk_public 3.2.11.9 (API Version 9 Release) +- 三方库版本:n6.0 +- 当前适配的功能:解码,编码,转码,复用,解复用,过滤音视频数据 +- [GPL2/GPL3/LGPL3 license](https://github.com/FFmpeg/FFmpeg) + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/FFmpeg/SHA512SUM b/thirdparty/FFmpeg/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..3f2c78a843463c66b0227db6ef1326d6ac3117d5 --- /dev/null +++ b/thirdparty/FFmpeg/SHA512SUM @@ -0,0 +1 @@ +da1b836c8f51cf69f95db750d5da5191a71d534fa7b0f019d6d6454f8dd6db5598789576b4fe5ad983dcd0197b9a7e8f9d43f10707b6d40ac31425da23da35b2 FFmpeg-n6.0.tar.gz diff --git a/thirdparty/FFmpeg/docs/hap_integrate.md b/thirdparty/FFmpeg/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..318d82174b454465a6c270d137735e1ed792407f --- /dev/null +++ b/thirdparty/FFmpeg/docs/hap_integrate.md @@ -0,0 +1,97 @@ +# FFmpeg集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- ubuntu20.04 +- [OpenHarmony3.2Release镜像](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fdayu200_standard_arm32.tar.gz) +- [ohos_sdk_public 3.2.11.9 (API Version 9 Release)](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fohos-sdk-windows_linux-public.tar.gz) +- [DevEco Studio 3.1 Beta2](https://gitee.com/link?target=https%3A%2F%2Fcontentcenter-vali-drcn.dbankcdn.cn%2Fpvt_2%2FDeveloperAlliance_package_901_9%2Ff3%2Fv3%2FuJyuq3syQ2ak4hE1QZmAug%2Fdevecostudio-windows-3.1.0.400.zip%3FHW-CC-KV%3DV1%26HW-CC-Date%3D20230408T013335Z%26HW-CC-Expire%3D315360000%26HW-CC-Sign%3D96262721EDC9B34E6F62E66884AB7AE2A94C2A7B8C28D6F7FC891F46EB211A70) +- [准备三方库构建环境](../../../tools/README.md#编译环境准备) +- [准备三方库测试环境](../../../tools/README.md#ci环境准备) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/FFmpeg #三方库FFmpeg的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` + +- 将FFmpeg拷贝至tools/main目录下 + + ```shell + cd tpc_c_cplusplus + cp thirdparty/FFmpeg tools/main -rf + ``` + +- 在tools目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../tools/README.md#编译环境准备) + + ```shell + cd tools + ./build.sh FFmpeg + ``` + +- 三方库头文件及生成的库 + + 在tools目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ```shell + FFmpeg/arm64-v8a FFmpeg/armeabi-v7a + ``` +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示 +   + + ![thirdparty_install_dir](pic/FFmpeg_install_dir.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + + ```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/FFmpeg/${OHOS_ARCH}/lib/libavcodec.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/FFmpeg/${OHOS_ARCH}/lib/libavdevice.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/FFmpeg/${OHOS_ARCH}/lib/libavfilter.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/FFmpeg/${OHOS_ARCH}/lib/libavformat.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/FFmpeg/${OHOS_ARCH}/lib/libavutil.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/FFmpeg/${OHOS_ARCH}/lib/libswresample.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/FFmpeg/${OHOS_ARCH}/lib/libswscale.a) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/FFmpeg/${OHOS_ARCH}/include) + ``` + + ![FFmpeg_usage](pic/FFmpeg_usage.png) + +## 测试三方库 + +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../tools/README.md#ci环境准备) + +进入到构建目录,执行如下命令ctest(arm64-v8a-build为构建64位的目录,armeabi-v7a-build为构建32位的目录) + + + ![FFmpeg_test](pic/FFmpeg_test_1.png) + ![FFmpeg_test](pic/FFmpeg_test_2.png) + +## 参考资料 + +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) diff --git a/thirdparty/FFmpeg/docs/pic/FFmpeg_install_dir.png b/thirdparty/FFmpeg/docs/pic/FFmpeg_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..2c128490c06c534271006e78b3c6d668dd05b712 Binary files /dev/null and b/thirdparty/FFmpeg/docs/pic/FFmpeg_install_dir.png differ diff --git a/thirdparty/FFmpeg/docs/pic/FFmpeg_test_1.png b/thirdparty/FFmpeg/docs/pic/FFmpeg_test_1.png new file mode 100644 index 0000000000000000000000000000000000000000..beae1d24dc51313f80d1dfab143eb6f456198e17 Binary files /dev/null and b/thirdparty/FFmpeg/docs/pic/FFmpeg_test_1.png differ diff --git a/thirdparty/FFmpeg/docs/pic/FFmpeg_test_2.png b/thirdparty/FFmpeg/docs/pic/FFmpeg_test_2.png new file mode 100644 index 0000000000000000000000000000000000000000..4b1062f9d052776f49385a9695fc158a3c3a446c Binary files /dev/null and b/thirdparty/FFmpeg/docs/pic/FFmpeg_test_2.png differ diff --git a/thirdparty/FFmpeg/docs/pic/FFmpeg_usage.png b/thirdparty/FFmpeg/docs/pic/FFmpeg_usage.png new file mode 100644 index 0000000000000000000000000000000000000000..cf1008f6af90173825eeaa46e9c5b11ae82df461 Binary files /dev/null and b/thirdparty/FFmpeg/docs/pic/FFmpeg_usage.png differ