HarmonyOS鸿蒙Next中ffmpeg如何开启硬件加速?
HarmonyOS鸿蒙Next中ffmpeg如何开启硬件加速? 如题: HKBUILD脚本如下
# Contributor: Jeff Han <hanjinfei@foxmail.com>
# Maintainer: Jeff Han <hanjinfei@foxmail.com>
pkgname=FFmpeg
pkgver=n4.2
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", "x86_64")
archs=("x86_64")
license=("GPL2" "GPL3" "LGPL3" "MIT" "X11" "BSD-styl")
depends=("openssl_1_0_2u")
#depends=("lame", "x264")
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
arch=
ldflags=
prepare() {
if [ "$LYCIUM_BUILD_OS" == "Linux" ]
then
hostosname=linux
elif [ "$LYCIUM_BUILD_OS" == "Darwi" ]
then
hostosname=darwin
else
echo "System cannot recognize, exiting"
return -1
fi
if [ $buildhost == true ]
then
tar -zxf $packagename
cd $builddir
./configure --enable-static --enable-shared --disable-doc --disable-htmlpages \
--target-os=$hostosname --prefix=`pwd`/hostbuild > $publicbuildlog 2>&1
$MAKE >> $publicbuildlog 2>&1
$MAKE install >> $publicbuildlog 2>&1
export LD_LIBRARY_PATH=`pwd`/hostbuild/lib:$LD_LIBRARY_PATH
sed -i.bak 's/include $(SRC_PATH)\/tests\/fate\/source.mak/#include $(SRC_PATH)\/tests\/fate\/source.mak/g' tests/Makefile
$MAKE check >> $publicbuildlog 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
arch=arm
ldflags="-L${OHOS_SDK}/native/sysroot/usr/lib/arm-linux-ohos"
elif [ $ARCH == "arm64-v8a" ]
then
setarm64ENV
arch=aarch64
ldflags="-L${OHOS_SDK}/native/sysroot/usr/lib/aarch64-linux-ohos"
elif [ $ARCH == "x86_64" ]
then
setx86_64ENV
arch=x86_64
ldflags="-L${OHOS_SDK}/native/sysroot/usr/lib/x86_64-linux-ohos"
else
echo "${ARCH} not support"
return -1
fi
return $ret
}
build() {
cd $pkgname-$ARCH-build/$builddir
PKG_CONFIG_LIBDIR="${pkgconfigpath}" ./configure "$@" \
--enable-small \
--enable-runtime-cpudetect \
--disable-debug \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--enable-avdevice \
--enable-avcodec \
--enable-avformat \
--enable-avutil \
--enable-swresample \
--enable-swscale \
--enable-avfilter \
--enable-postproc \
--enable-avresample \
--disable-network \
--disable-hwaccels \
--disable-encoders \
--enable-encoder=mpeg4 \
--enable-encoder=aac \
--enable-encoder=ac3 \
--enable-encoder=mpeg1video \
--enable-encoder=mp2 \
--enable-encoder=mjpeg \
--enable-encoder=png \
--enable-encoder=pcm_s16le \
--enable-encoder=wav \
--disable-decoders \
--enable-decoder=mpeg4 \
--enable-decoder=aac \
--enable-decoder=ac3 \
--enable-decoder=h264 \
--enable-decoder=hevc \
--enable-decoder=mp3float \
--enable-decoder=mpeg1video \
--enable-decoder=mp2float \
--enable-decoder=mjpeg \
--enable-decoder=png \
--enable-decoder=pcm_s16le \
--enable-decoder=wav \
--disable-muxers \
--enable-muxer=mpegts \
--enable-muxer=mpeg1system \
--enable-muxer=flv \
--enable-muxer=avi \
--enable-muxer=mp4 \
--enable-muxer=h264 \
--enable-muxer=adts \
--enable-muxer=mp3 \
--enable-muxer=ac3 \
--enable-muxer=image2 \
--enable-muxer=matroska \
--enable-muxer=wav \
--disable-demuxers \
--enable-demuxer=mpegts \
--enable-demuxer=mpegps \
--enable-demuxer=mpegvideo \
--enable-demuxer=flv \
--enable-demuxer=avi \
--enable-demuxer=mov \
--enable-demuxer=h264 \
--enable-demuxer=hevc \
--enable-demuxer=aac \
--enable-demuxer=mp3 \
--enable-demuxer=ac3 \
--enable-demuxer=image2 \
--enable-demuxer=matroska \
--enable-demuxer=wav \
--disable-parsers \
--enable-parser=aac \
--enable-parser=aac_latm \
--enable-parser=h264 \
--enable-parser=hevc \
--enable-parser=mpegvideo \
--disable-filters \
--enable-filter=aformat \
--enable-filter=aresample \
--enable-filter=volume \
--enable-filter=scale \
--enable-filter=aloop \
--enable-filter=loop \
--enable-filter=adelay \
--enable-filter=amix \
--enable-filter=transpose \
--enable-filter=acrossfade \
--disable-bsfs \
--enable-bsf=aac_adtstoasc \
--enable-bsf=h264_mp4toannexb \
--enable-bsf=extract_extradata \
--disable-protocols \
--enable-protocol=file \
--enable-protocol=http \
--enable-protocol=https \
--enable-neon \
--enable-asm \
--enable-cross-compile \
--enable-pic \
--enable-static \
--enable-shared \
--target-os=linux \
--arch=$arch \
--cc=${CC} --ld=${CC} --strip=${STRIP} --host-cc="${CC}" --host-ld="${CC}" --host-os=linux \
--host-ldflags=${ldflags} --sysroot=${OHOS_SDK}/native/sysroot > $buildlog 2>&1
$MAKE >> $buildlog 2>&1
ret=$?
cd $OLDPWD
return $ret
}
package() {
cd $pkgname-$ARCH-build/$builddir
$MAKE install >> $buildlog 2>&1
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() {
return 0
}
recoverpkgbuildenv() {
unset arch
unset ldflags
if [ $ARCH == "armeabi-v7a" ]
then
unsetarm32ENV
elif [ $ARCH == "arm64-v8a" ]
then
unsetarm64ENV
elif [ $ARCH == "x86_64" ]
then
unsetx86_64ENV
else
echo "${ARCH} not support"
return -1
fi
}
# 清理环境
cleanbuild() {
rm -rf ${PWD}/${builddir} ${PWD}/$pkgname-arm64-v8a-build ${PWD}/$pkgname-armeabi-v7a-build ${PWD}/$pkgname-x86-64-build #${PWD}/$packagename
}
更多关于HarmonyOS鸿蒙Next中ffmpeg如何开启硬件加速?的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中启用ffmpeg硬件加速,需使用鸿蒙NDK调用媒体硬件抽象层。通过ohos.media.codec接口配置硬件解码器,设置surface输出和硬件加速标志。具体实现需调用CodecComponent接口初始化硬件编解码器,配置MediaFormat参数指定视频格式和硬件加速模式。在ffmpeg中通过hwaccel参数选择鸿蒙专用加速器,使用AVCodecContext的hw_device_ctx绑定设备上下文。
更多关于HarmonyOS鸿蒙Next中ffmpeg如何开启硬件加速?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS Next中启用FFmpeg硬件加速,需要在编译配置中开启相关硬件加速选项。从你提供的脚本看,当前配置明确禁用了硬件加速(--disable-hwaccels)。
需要修改build()函数中的configure参数:
- 移除
--disable-hwaccels - 添加硬件加速启用选项,例如:
--enable-hwaccels(启用通用硬件加速)--enable-vaapi(启用VA-API)--enable-vdpau(启用VDPAU)--enable-cuvid(启用NVIDIA解码)
具体支持的硬件加速后端取决于HarmonyOS Next的图形架构和可用驱动。建议参考HarmonyOS的媒体硬件加速文档,确认支持的加速接口后选择对应配置选项。
同时确保系统已安装相应的硬件加速驱动和开发库,否则编译可能失败。

