79 Commits

Author SHA1 Message Date
89110385a6 Update build.sh 2020-08-29 10:57:37 +02:00
2be5db0052 Update build.sh 2020-08-29 10:54:09 +02:00
68c24265bc Update build.sh 2020-08-29 08:28:50 +02:00
d2a2c60bed Update build.sh 2020-08-29 07:22:04 +02:00
405fa7ef42 Update build.sh 2020-08-28 21:23:30 +02:00
dfdfbf0bf9 Update build.sh 2020-08-28 18:35:59 +02:00
4e6af07c40 Update build.sh 2020-08-28 17:51:46 +02:00
75530fcd49 Update build.sh 2020-08-28 16:23:41 +02:00
a6e427fb6c Delete build_tc.sh 2020-08-28 16:22:43 +02:00
8a046eb2cf Update build.sh 2020-08-26 15:04:15 +02:00
b0841dfc7d Update build.sh 2020-08-26 14:17:50 +02:00
cf6f6f6642 Update build.sh
switched to nvenc sdk 9.1 and old libmfx
2020-08-25 22:24:26 +02:00
9d3a2c4e68 Update build.sh 2020-08-07 12:37:28 +02:00
0bfa5dd312 Update build.sh 2020-07-31 19:08:04 +02:00
bc0432b517 Update build.sh 2020-04-23 14:04:51 +02:00
8fccd0798e Update build.sh 2020-04-23 13:12:10 +02:00
3517a9c53c Update build.sh 2020-04-23 10:23:59 +02:00
9296afdc45 Update build.sh 2020-04-23 09:52:56 +02:00
82aee7f226 Update build.sh 2020-04-23 08:29:37 +02:00
fe3d8ac4bb Update build.sh 2020-04-23 07:50:47 +02:00
9eac49cd88 Update build.sh 2020-04-23 07:44:20 +02:00
e4617204b7 Update build.sh 2020-03-29 11:48:01 +02:00
f37501f76a Update build.sh
Migrate to MSVS2019
2020-03-29 09:46:56 +02:00
9e5d393c53 Update build.sh 2020-03-28 22:20:57 +01:00
b599a6b1f4 Update build.sh 2020-02-11 09:21:32 +01:00
b5b64eda35 Update build.sh 2020-02-11 09:13:56 +01:00
ed913d77b8 Update build.sh 2020-02-10 19:03:58 +01:00
9cf0a28e05 Update build.sh 2020-02-10 11:28:39 +01:00
d2bd796ebe Update build.yml 2019-12-29 11:03:51 +01:00
4a012dda14 Update build.sh 2019-12-28 15:32:48 +01:00
063492aa68 Update build.sh 2019-12-28 14:45:24 +01:00
d4e6cf9545 Update build.sh 2019-12-28 14:44:16 +01:00
e01d2d9480 Update build.sh 2019-12-28 12:16:57 +01:00
90159e4cea Update build.sh 2019-12-28 11:12:19 +01:00
c3d0a133a6 Update build.sh 2019-12-28 10:24:36 +01:00
71f4d34d5d Update build.sh 2019-12-28 10:03:10 +01:00
904d742237 Update build.yml 2019-12-28 09:02:54 +01:00
a235255663 Create build.yml 2019-12-27 23:43:46 +01:00
b0a99a749b Update build.sh 2019-12-27 12:24:25 +01:00
4feb53345b Update build.sh 2019-12-26 23:16:44 +01:00
4ca3315ab1 Create build.sh 2019-12-26 22:25:01 +01:00
566f1dc75c Update build_tc.sh 2019-12-26 19:20:20 +01:00
32bff0910e Update build_tc.sh 2019-12-26 18:21:06 +01:00
8b59a0c23a Update build_tc.sh 2019-12-25 10:19:16 +01:00
f82449bbb5 Update build_tc.sh 2019-12-25 00:34:12 +01:00
6d2cebf842 Update build_tc.sh 2019-12-24 23:39:29 +01:00
26a96dbbb6 Update build_tc.sh 2019-12-24 09:55:46 +01:00
9fc7961bc0 Update build_tc.sh 2019-12-11 10:41:19 +01:00
a9abf18adf Update build_tc.sh 2019-12-11 07:58:46 +01:00
fe50e5691a Update build_tc.sh 2019-12-06 19:59:07 +01:00
bb8870e945 Update build_tc.sh 2019-08-18 17:19:44 +02:00
0ef14269af Update build_tc.sh 2019-08-18 17:02:08 +02:00
d7a8ae3c57 Update build_tc.sh 2019-08-17 11:50:48 +02:00
beaf861e2c Update build_tc.sh 2019-08-17 07:13:17 +02:00
7f98c46ad5 Update build_tc.sh 2019-08-15 20:22:04 +02:00
b7fd6e5a56 Update build_tc.sh 2019-08-15 19:31:33 +02:00
ab82bda2b1 Update build_tc.sh 2019-08-15 18:38:28 +02:00
e025161887 Update build_tc.sh 2019-08-15 08:36:20 +02:00
b333a74f26 Update build_tc.sh 2019-08-15 08:01:22 +02:00
7bdc8b7a34 Update build_tc.sh 2019-08-14 22:24:42 +02:00
0804404294 Update build_tc.sh 2019-08-09 09:39:08 +02:00
831a27f759 Update build_tc.sh 2019-08-09 09:33:41 +02:00
ed62183c76 Update build_tc.sh 2019-08-09 09:03:08 +02:00
b507f0f5a6 Update build_tc.sh 2019-08-09 08:32:29 +02:00
1dd6e5f06c Update build_tc.sh 2019-08-07 08:25:28 +02:00
27c57ff047 Update build_tc.sh 2019-08-06 16:35:55 +02:00
3ca042c3f1 Update build_tc.sh 2019-08-06 16:25:21 +02:00
7ce133ed47 Create 0001-libsvt-av1.patch 2019-08-06 16:23:46 +02:00
6b0d2a466d Update build_tc.sh 2019-08-05 19:59:44 +02:00
5dde9efd53 Update build_tc.sh 2019-07-20 12:03:33 +02:00
7ac9bf3d5a Update build_tc.sh 2019-07-20 09:11:43 +02:00
44e8ca59ec Update build_tc.sh 2019-07-20 08:52:57 +02:00
1d7f228d2c Update build_tc.sh 2019-07-20 07:47:00 +02:00
89f7f16202 Update build_tc.sh 2019-07-19 20:08:58 +02:00
98b0eccb87 Update build_tc.sh 2019-07-19 19:11:10 +02:00
f1699d3d3b Update build_tc.sh 2019-07-19 18:27:34 +02:00
2b8ae2daeb Update build_tc.sh 2019-05-31 11:07:15 +02:00
3df0a67006 Update build_tc.sh 2019-05-31 10:44:34 +02:00
0a73914d1d Update 0001-dynamic-loading-of-shared-fdk-aac-library.patch 2019-03-26 08:05:21 +01:00
5 changed files with 851 additions and 187 deletions

18
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: CI
on:
schedule:
- cron: "0 2 * * *"
jobs:
build:
runs-on: windows-latest
steps:
- name: Build it!
run:
choco install msys2
echo "::set-env name=CHERE_INVOKING::enabled_from_arguments"
echo "::set-env name=MODE::release"
echo "::set-env name=MSYS2_PATH_TYPE::inherit"
echo "::set-env name=MSYSTEM::MINGW64"
c:\tools\msys64\usr\bin\bash.exe -l -c "pacman -S base-devel binutils git make pkg-config"

282
build.sh Normal file
View File

@ -0,0 +1,282 @@
#!/bin/bash
COMPONENTS=""
if [ "$MODE" == "debug" ]; then
MSBUILD_CONFIG=Debug
CFLAGS=-MDd
elif [ "$MODE" == "release" ]; then
MSBUILD_CONFIG=Release
CFLAGS=-MD
else
echo "Please supply build mode [debug|release]!"
exit 1
fi
function build {
cd $SRC/$1
if [ -f autogen.sh ]; then
./autogen.sh
fi
CC=cl CXXFLAGS=$CFLAGS ./configure --prefix=$BUILD $2
make -j $NUMBER_OF_PROCESSORS
make install
}
function build_nvenc {
git clone git://github.com/FFmpeg/nv-codec-headers.git $SRC/ffnvcodec
# git checkout sdk/9.0
cd $SRC/ffnvcodec
make PREFIX=$BUILD install
add_comp nvenc
}
function build_amf {
git clone git://github.com/GPUOpen-LibrariesAndSDKs/AMF.git $SRC/amf
cp -a $SRC/amf/amf/public/include $BUILD/include/AMF
add_comp amf
}
function build_mfx {
git clone https://github.com/lu-zero/mfx_dispatch.git $SRC/libmfx
cd $SRC/libmfx
#git checkout c200d833e25a91e3e49d69890dac1ffa3486cbe9
if [[ ! -f "configure" ]]; then
autoreconf -fiv || exit 1
fi
build libmfx
sed -i 's/-lstdc++/-ladvapi32/g' $BUILD/lib/pkgconfig/libmfx.pc
add_comp libmfx
}
function build_aom {
git clone https://aomedia.googlesource.com/aom $SRC/libaom
cd $SRC/libaom
rm -rf work
mkdir work
cd work
cmake -G "Visual Studio 15 2017" .. -A x64 -DENABLE_{DOCS,TOOLS,TESTS}=off -DAOM_TARGET_CPU=x86_64 -DCMAKE_INSTALL_PREFIX=$BUILD
MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration="$MSBUILD_CONFIG" AOM.sln
cp $MSBUILD_CONFIG/aom.lib $BUILD/lib/aom.lib
cp -r ../aom $BUILD/include/aom
cmake -DAOM_CONFIG_DIR=. -DAOM_ROOT=.. -DCMAKE_INSTALL_PREFIX=@prefix@ -DCMAKE_PROJECT_NAME=aom -DCONFIG_MULTITHREAD=true -DHAVE_PTHREAD_H=false -P "../build/cmake/pkg_config.cmake"
sed -i "s#@prefix@#$BUILD#g" aom.pc
sed -i '/^Libs\.private.*/d' aom.pc
sed -i 's/-lm//' aom.pc
cp aom.pc $BUILD/lib/pkgconfig/aom.pc
add_comp libaom
}
function build_svt {
# HEVC
#git clone https://github.com/OpenVisualCloud/SVT-HEVC.git $SRC/svt-hevc
#cd $SRC/svt-hevc/Build
#cmake .. -G"Visual Studio 15 2017" -A x64 -DCMAKE_INSTALL_PREFIX=$BUILD -DCMAKE_CONFIGURATION_TYPES=$MSBUILD_CONFIG
#MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration=$MSBUILD_CONFIG /property:ConfigurationType=StaticLibrary /property:TargetExt=.lib svt-hevc.sln
#cp -r ../Source/API $BUILD/include/svt-hevc ; cp ../Bin/$MSBUILD_CONFIG/SvtHevcEnc.lib $BUILD/lib/ ; cp SvtHevcEnc.pc $BUILD/lib/pkgconfig/
#add_comp libsvthevc
#
# AV1 (patch needed for FFmpeg 4.3)
git clone --depth 1 --branch v0.8.4 https://github.com/OpenVisualCloud/SVT-AV1.git $SRC/svt-av1
cd $SRC/svt-av1/Build
cmake .. -G"Visual Studio 15 2017" -A x64 -DCMAKE_INSTALL_PREFIX=$BUILD -DCMAKE_CONFIGURATION_TYPES=$MSBUILD_CONFIG
MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration=$MSBUILD_CONFIG /property:ConfigurationType=StaticLibrary /property:TargetExt=.lib Source/Lib/Encoder/SvtAv1Enc.vcxproj
cp -r ../Source/API $BUILD/include/svt-av1 ; cp ../Bin/$MSBUILD_CONFIG/SvtAv1Enc.lib $BUILD/lib/ ; cp SvtAv1Enc.pc $BUILD/lib/pkgconfig/
add_comp libsvtav1
#
# VP9
#git clone https://github.com/OpenVisualCloud/SVT-VP9.git $SRC/svt-vp9
#cd $SRC/svt-vp9/Build
#cmake .. -G"Visual Studio 15 2017" -A x64 -DCMAKE_INSTALL_PREFIX=$BUILD -DCMAKE_CONFIGURATION_TYPES=$MSBUILD_CONFIG
#MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration=$MSBUILD_CONFIG /property:ConfigurationType=StaticLibrary /property:TargetExt=".lib" svt-vp9.sln
#cp -r ../Source/API $BUILD/include/svt-vp9 ; cp ../Bin/$MSBUILD_CONFIG/SvtVp9Enc.lib $BUILD/lib/ ; cp SvtVp9Enc.pc $BUILD/lib/pkgconfig/
#sed -i 's/ -lpthread//g' $BUILD/lib/pkgconfig/SvtVp9Enc.pc
#sed -i 's/ -lm//g' $BUILD/lib/pkgconfig/SvtVp9Enc.pc
#add_comp libsvtvp9
cd $SRC/ffmpeg
#git apply $SRC/svt-hevc/ffmpeg_plugin/0001-lavc-svt_hevc-add-libsvt-hevc-encoder-wrapper.patch
#git apply $SRC/svt-av1/ffmpeg_plugin/0001-Add-ability-for-ffmpeg-to-run-svt-av1-with-svt-hevc.patch
#git apply $SRC/svt-vp9/ffmpeg_plugin/0001-Add-ability-for-ffmpeg-to-run-svt-vp9-with-hevc-av1.patch
#git am $SRC/svt-hevc/ffmpeg_plugin/0001*.patch
git apply $SRC/svt-av1/ffmpeg_plugin/0001-Add-ability-for-ffmpeg-to-run-svt-av1.patch
}
function build_ogg {
git clone https://github.com/xiph/ogg.git $SRC/libogg
cd $SRC/libogg
build libogg "--disable-shared"
}
function build_vorbis {
git clone https://github.com/xiph/vorbis.git $SRC/libvorbis
cd $SRC/libvorbis
build libvorbis "--disable-shared"
sed -i '/^Libs\.private.*/d' $BUILD/lib/pkgconfig/vorbis.pc # don't need m.lib on windows
add_comp libvorbis
}
function build_snappy {
git clone https://github.com/google/snappy.git $SRC/snappy
cd $SRC/snappy
rm -rf work
mkdir work
cd work
cmake -G "Visual Studio 15 Win64" .. -DCMAKE_INSTALL_PREFIX=$BUILD -DBUILD_SHARED_LIBS=OFF -DSNAPPY_BUILD_TESTS=OFF
MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration="$MSBUILD_CONFIG" Snappy.sln
cp $MSBUILD_CONFIG/snappy.lib $BUILD/lib/snappy.lib
cp ../snappy.h ../snappy-c.h $BUILD/include/
add_comp libsnappy
}
function build_libvpx {
git clone https://github.com/webmproject/libvpx.git $SRC/libvpx
cd $SRC/libvpx
./configure --prefix=$BUILD --target=x86_64-win64-vs15 --enable-vp9-highbitdepth --disable-shared --disable-examples --disable-tools --disable-docs --disable-libyuv --disable-unit_tests --disable-postproc
make -j $NUMBER_OF_PROCESSORS
make install
mv $BUILD/lib/x64/vpxmd.lib $BUILD/lib/vpx.lib
rm -rf $BUILD/lib/x64
add_comp libvpx
}
function build_libfdkaac {
git clone git://github.com/mstorsjo/fdk-aac.git $SRC/fdk-aac
cd $SRC/fdk-aac
build fdk-aac "--disable-static --disable-shared"
add_comp libfdk-aac
cd $SRC/ffmpeg
patch -N -p1 -i ../../patches/0001-dynamic-loading-of-shared-fdk-aac-library.patch
}
function build_lame {
svn co svn://svn.code.sf.net/p/lame/svn/trunk/lame $SRC/lame
cd $SRC/lame
build lame "--enable-nasm --disable-frontend --disable-shared --enable-static"
add_comp libmp3lame
}
function build_zimg {
git clone https://github.com/sekrit-twc/zimg.git $SRC/zimg
cd $SRC/zimg
git checkout release-2.9.2
./autogen.sh
./configure --prefix=$BUILD
cd _msvc/zimg
MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration="$MSBUILD_CONFIG" /property:ConfigurationType=StaticLibrary /property:WindowsTargetPlatformVersion=10.0.17134.0 /property:PlatformToolset=v141 /property:Platform=x64 /property:WholeProgramOptimization=false zimg.vcxproj
cp x64/$MSBUILD_CONFIG/z.lib $BUILD/lib/zimg.lib
cd ../..
cp $SRC/zimg/src/zimg/api/zimg.h $BUILD/include/zimg.h
cp zimg.pc $BUILD/lib/pkgconfig/zimg.pc
add_comp libzimg
}
function build_x264 {
git clone https://code.videolan.org/videolan/x264.git $SRC/x264
cd $SRC/x264
git checkout b5bc5d69c580429ff716bafcd43655e855c31b02
#f9af2a0f71d0fca7c1cafa7657f03a302da0ca1c
CC=cl ./configure --prefix=$BUILD --disable-cli --enable-static --enable-pic --libdir=$BUILD/lib
make -j $NUMBER_OF_PROCESSORS
make install-lib-static
add_comp libx264
}
function build_opus {
git clone https://github.com/xiph/opus.git $SRC/opus
cd $SRC/opus/win32/VS2015
echo \nConverting project file ...
sed -i 's/v140/v141/g' opus.vcxproj
echo Building project 'opus' ...
MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration="$MSBUILD_CONFIG" /property:Platform=x64 opus.vcxproj
echo Done.
cp x64/$MSBUILD_CONFIG/opus.lib $BUILD/lib/opus.lib
cp -r $SRC/opus/include $BUILD/include/opus
cp $SRC/opus/opus.pc.in $BUILD/lib/pkgconfig/opus.pc
sed -i "s#@prefix@#$BUILD#g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@exec_prefix@/\$\{prefix\}/g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@libdir@/\$\{prefix\}\/lib/g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@includedir@/\$\{prefix\}\/include/g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@LIBM@//g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@VERSION@/2.0.0/g" $BUILD/lib/pkgconfig/opus.pc
add_comp libopus
}
function build_x265 {
git clone https://github.com/videolan/x265.git --branch stable $SRC/x265
cd $SRC/x265/build/vc15-x86_64
rm -rf work*
mkdir work work10 work12
# 12bit
cd work12
cmake -G "Visual Studio 15 Win64" ../../../source -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF -DMAIN12=ON
MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration="$MSBUILD_CONFIG" x265-static.vcxproj
cp $MSBUILD_CONFIG/x265-static.lib ../work/x265_12bit.lib
# 10bit
cd ../work10
cmake -G "Visual Studio 15 Win64" ../../../source -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF
MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration="$MSBUILD_CONFIG" x265-static.vcxproj
cp $MSBUILD_CONFIG/x265-static.lib ../work/x265_10bit.lib
# 8bit - main
cd ../work
cmake -G "Visual Studio 15 Win64" ../../../source -DCMAKE_INSTALL_PREFIX=$BUILD -DENABLE_SHARED=OFF -DENABLE_CLI=OFF -DEXTRA_LIB="x265_10bit.lib;x265_12bit.lib" -DLINKED_10BIT=ON -DLINKED_12BIT=ON
#-DSTATIC_LINK_CRT=ON
MSBuild.exe /maxcpucount:$NUMBER_OF_PROCESSORS /property:Configuration="$MSBUILD_CONFIG" x265-static.vcxproj
cp $MSBUILD_CONFIG/x265-static.lib ./x265_main.lib
LIB.EXE /ignore:4006 /ignore:4221 /OUT:x265.lib x265_main.lib x265_10bit.lib x265_12bit.lib
cp x265.lib $BUILD/lib/x265.lib
cp x265.pc $BUILD/lib/pkgconfig/x265.pc
cp x265_config.h $BUILD/include/
cp ../../../source/x265.h $BUILD/include/
add_comp libx265
}
function add_comp {
COMPONENTS="$COMPONENTS --enable-$1"
}
rm -rf src build
mkdir src build build/include build/lib build/lib/pkgconfig
BUILD=`realpath build`
SRC=`realpath src`
git clone -b release/4.3 git://source.ffmpeg.org/ffmpeg.git $SRC/ffmpeg
build_nvenc
build_amf
build_mfx
build_svt
build_ogg
build_vorbis
build_snappy
build_libvpx
build_libfdkaac
build_lame
build_zimg
build_x264
build_opus
build_x265
#build_aom
cd $SRC/ffmpeg
PKG_CONFIG_PATH=$BUILD/lib/pkgconfig:$PKG_CONFIG_PATH ./configure --toolchain=msvc --extra-cflags="$CFLAGS -I$BUILD/include" --extra-ldflags="-LIBPATH:$BUILD/lib" --prefix=$BUILD --pkg-config-flags="--static" --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --disable-devices --disable-demuxers --disable-decoders --disable-network --enable-w32threads --enable-gpl $COMPONENTS
sed -i 's/\x81/ue/g' config.h
make -j $NUMBER_OF_PROCESSORS
make install
# rename *.a to *.lib
cd $BUILD/lib
for file in *.a; do
mv "$file" "`basename "$file" .a`.lib"
done
# clean up
rm -rf $BUILD/lib/pkgconfig $BUILD/lib/fdk-aac.lib $BUILD/lib/*.la
# Create archives
cd $BUILD
mkdir ../dist 2>/dev/null
tar czf ../dist/ffmpeg-win64-static-$MODE.tar.gz *
cd $SRC/ffmpeg
tar czf ../../dist/ffmpeg-win64-static-src-$MODE.tar.gz *

View File

@ -1,185 +0,0 @@
#!/bin/bash
STEP=$1
MODE=$2
CPU_CORES=$3
ENABLED_TOOLS=$4
SRC=`realpath src`
BUILD=`realpath build`
if [ "$MODE" == "debug" ]; then
MSBUILD_CONFIG=Debug
elif [ "$MODE" == "release" ]; then
MSBUILD_CONFIG=Release
else
echo "Please supply build mode [debug|release]!"
exit 1
fi
if [ ! -d "$BUILD" ]; then
mkdir $BUILD $BUILD/include $BUILD/lib
fi
function compile {
cd $SRC/$1
if [ -f autogen.sh ]; then
./autogen.sh
fi
CC=cl ./configure --prefix=$BUILD $2
make -j $CPU_CORES
make install
}
if [ "$STEP" == "opus" ]; then
cd $SRC/opus/win32/VS2015
echo \nConverting project file ...
sed -i 's/v140/v141/g' opus.vcxproj
echo Building project 'opus' ...
MSBuild.exe /maxcpucount:$CPU_CORES /property:Configuration="$MSBUILD_CONFIG" /property:Platform=x64 opus.vcxproj
echo Done.
cp x64/$MSBUILD_CONFIG/opus.lib $BUILD/lib/opus.lib
cp -r $SRC/opus/include $BUILD/include/opus
cp $SRC/opus/opus.pc.in $BUILD/lib/pkgconfig/opus.pc
sed -i "s#@prefix@#$BUILD#g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@exec_prefix@/\$\{prefix\}/g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@libdir@/\$\{prefix\}\/lib/g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@includedir@/\$\{prefix\}\/include/g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@LIBM@//g" $BUILD/lib/pkgconfig/opus.pc
sed -i "s/@VERSION@/2.0.0/g" $BUILD/lib/pkgconfig/opus.pc
elif [ "$STEP" == "libfdk-aac" ]; then
compile fdk-aac "--disable-static --disable-shared"
elif [ "$STEP" == "lame" ]; then
compile lame "--enable-nasm --disable-frontend --disable-shared --enable-static"
elif [ "$STEP" == "zimg" ]; then
cd $SRC/zimg
./autogen.sh
./configure --prefix=$BUILD
cd _msvc/zimg
MSBuild.exe /maxcpucount:$CPU_CORES /property:Configuration="$MSBUILD_CONFIG" /property:Platform=x64 /property:WholeProgramOptimization=false zimg.vcxproj
cp x64/$MSBUILD_CONFIG/z.lib $BUILD/lib/zimg.lib
cd ../..
cp src/zimg/api/zimg.h $BUILD/include/zimg.h
cp zimg.pc $BUILD/lib/pkgconfig/zimg.pc
elif [ "$STEP" == "x264" ]; then
cd $SRC/x264
CC=cl ./configure --prefix=$BUILD --extra-cflags='-DNO_PREFIX' --disable-cli --enable-static --libdir=$BUILD/lib
make -j $CPU_CORES
make install-lib-static
elif [ "$STEP" == "x265" ]; then
# checkout manually (cmake is getting values from git)
cd $src/..
if [ ! -d $SRC/x265/.git ]; then
git clone https://github.com/videolan/x265.git --branch stable $SRC/x265
fi
git reset --hard
git pull
cd $SRC/x265/build/vc15-x86_64
rm -rf work*
mkdir work work10 work12
# 12bit
cd work12
cmake -G "Visual Studio 15 Win64" ../../../source -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF -DMAIN12=ON
MSBuild.exe /maxcpucount:$CPU_CORES /property:Configuration="$MSBUILD_CONFIG" x265-static.vcxproj
cp $MSBUILD_CONFIG/x265-static.lib ../work/x265_12bit.lib
# 10bit
cd ../work10
cmake -G "Visual Studio 15 Win64" ../../../source -DHIGH_BIT_DEPTH=ON -DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF
MSBuild.exe /maxcpucount:$CPU_CORES /property:Configuration="$MSBUILD_CONFIG" x265-static.vcxproj
cp $MSBUILD_CONFIG/x265-static.lib ../work/x265_10bit.lib
# 8bit - main
cd ../work
cmake -G "Visual Studio 15 Win64" ../../../source -DCMAKE_INSTALL_PREFIX=$BUILD -DENABLE_SHARED=OFF -DENABLE_CLI=OFF -DEXTRA_LIB="x265_10bit.lib;x265_12bit.lib" -DLINKED_10BIT=ON -DLINKED_12BIT=ON
#-DSTATIC_LINK_CRT=ON
MSBuild.exe /maxcpucount:$CPU_CORES /property:Configuration="$MSBUILD_CONFIG" x265-static.vcxproj
cp $MSBUILD_CONFIG/x265-static.lib ./x265_main.lib
LIB.EXE /ignore:4006 /ignore:4221 /OUT:x265.lib x265_main.lib x265_10bit.lib x265_12bit.lib
cp x265.lib $BUILD/lib/x265.lib
cp x265.pc $BUILD/lib/pkgconfig/x265.pc
cp x265_config.h $BUILD/include/
cp ../../../source/x265.h $BUILD/include/
elif [ "$STEP" == "libogg" ]; then
compile libogg "--disable-shared"
elif [ "$STEP" == "libvorbis" ]; then
compile libvorbis "--disable-shared"
sed -i '/^Libs\.private.*/d' $BUILD/lib/pkgconfig/vorbis.pc # don't need m.lib on windows
elif [ "$STEP" == "libvpx" ]; then
cd $SRC/libvpx
./configure --prefix=$BUILD --target=x86_64-win64-vs15 --enable-vp9-highbitdepth --disable-shared --disable-examples --disable-tools --disable-docs --disable-libyuv --disable-unit_tests --disable-postproc
make -j $CPU_CORES
make install
mv $BUILD/lib/x64/vpxmd.lib $BUILD/lib/vpx.lib
rm -rf $BUILD/lib/x64
elif [ "$STEP" == "snappy" ]; then
cd $SRC/snappy
rm -rf work
mkdir work
cd work
cmake -G "Visual Studio 15 Win64" .. -DCMAKE_INSTALL_PREFIX=$BUILD -DBUILD_SHARED_LIBS=OFF -DSNAPPY_BUILD_TESTS=OFF
MSBuild.exe /maxcpucount:$CPU_CORES /property:Configuration="$MSBUILD_CONFIG" Snappy.sln
cp $MSBUILD_CONFIG/snappy.lib $BUILD/lib/snappy.lib
cp ../snappy.h ../snappy-c.h $BUILD/include/
elif [ "$STEP" == "libaom" ]; then
cd $SRC/libaom
rm -rf work
mkdir work
cd work
cmake -G "Visual Studio 15 Win64" .. -DENABLE_{DOCS,TOOLS,TESTS}=off -DAOM_TARGET_CPU=x86_64 -DCMAKE_INSTALL_PREFIX=$BUILD
MSBuild.exe /maxcpucount:$CPU_CORES /property:Configuration="$MSBUILD_CONFIG" AOM.sln
cp $MSBUILD_CONFIG/aom.lib $BUILD/lib/aom.lib
cp -r ../aom $BUILD/include/aom
cmake -DAOM_CONFIG_DIR=. -DAOM_ROOT=.. -DCMAKE_INSTALL_PREFIX=@prefix@ -DCMAKE_PROJECT_NAME=aom -DCONFIG_MULTITHREAD=true -DHAVE_PTHREAD_H=false -P "../build/cmake/pkg_config.cmake"
sed -i "s#@prefix@#$BUILD#g" aom.pc
sed -i '/^Libs\.private.*/d' aom.pc
sed -i 's/-lm//' aom.pc
cp aom.pc $BUILD/lib/pkgconfig/aom.pc
elif [ "$STEP" == "ffmpeg" ]; then
echo "### Copying NVENC headers ..."
cd $SRC/ffnvcodec
make PREFIX=$BUILD install
echo "### Copying AMF headers ..."
cp -a $SRC/amf/amf/public/include $BUILD/include/AMF
echo "### Applying patches ..."
cd $SRC/ffmpeg
ffbranch=$(git rev-parse --abbrev-ref HEAD)
echo "FFMpeg branch: $ffbranch ..."
if [ "$ffbranch" == "release/4.0" ]; then
patch -N -p1 -i ../../patches/0001-dynamic-loading-of-shared-fdk-aac-library-4.0.patch
patch -N -p0 -i ../../patches/0002-patch-ffmpeg-to-new-fdk-api.patch
else
patch -N -p1 -i ../../patches/0001-dynamic-loading-of-shared-fdk-aac-library.patch
fi
echo "### Compiling FFMpeg ..."
cd $SRC/ffmpeg
if [ "$MODE" == "debug" ]; then
CFLAGS=-MDd
elif [ "$MODE" == "release" ]; then
CFLAGS=-MD
fi
PKG_CONFIG_PATH=$BUILD/lib/pkgconfig:$PKG_CONFIG_PATH ./configure --toolchain=msvc --extra-cflags="$CFLAGS -I$BUILD/include" --extra-ldflags="-LIBPATH:$BUILD/lib" --prefix=$BUILD --pkg-config-flags="--static" --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --disable-devices --disable-network --enable-w32threads $ENABLED_TOOLS
make -j $CPU_CORES
make install
# rename *.a to *.lib
cd $BUILD/lib
for file in *.a; do
mv "$file" "`basename "$file" .a`.lib"
done
# clean up
rm -rf $BUILD/lib/pkgconfig $BUILD/lib/fdk-aac.lib $BUILD/lib/*.la
# Create archives
cd $BUILD
mkdir ../dist 2>/dev/null
tar czf ../dist/ffmpeg-win64-static-$MODE.tar.gz *
cd $SRC/ffmpeg
tar czf ../../dist/ffmpeg-win64-static-src-$MODE.tar.gz *
else
echo "Unknown build step!"
exit 1
fi

View File

@ -15,10 +15,9 @@ diff --git a/configure b/configure
index 25120337de..36e8d99f00 100755
--- a/configure
+++ b/configure
@@ -1675,7 +1675,6 @@ EXTERNAL_LIBRARY_GPL_LIST="
@@ -1675,6 +1675,5 @@ EXTERNAL_LIBRARY_GPL_LIST="
EXTERNAL_LIBRARY_NONFREE_LIST="
decklink
libndi_newtek
- libfdk_aac
openssl
libtls

View File

@ -0,0 +1,550 @@
diff --git a/configure b/configure
index 48e8536..fa6a7f9 100755
--- a/configure
+++ b/configure
@@ -213,6 +213,7 @@ External library support:
--enable-libschroedinger Dirac video encoding/decoding
--enable-libsnappy snappy compression
--enable-libspeex Speex audio encoding/decoding
+ --enable-libsvtav1 enable AV1 encoding via svt [no]
--enable-libsrt Haivision SRT protocol
--enable-libtheora Theora video encoding/decoding
--enable-libtwolame MP2 audio encoding
@@ -1376,6 +1377,7 @@ EXTERNAL_LIBRARY_LIST="
libschroedinger
libsnappy
libspeex
+ libsvtav1
libsrt
libtheora
libtwolame
@@ -2404,6 +2406,7 @@ libschroedinger_encoder_deps="libschroedinger"
libspeex_decoder_deps="libspeex"
libspeex_encoder_deps="libspeex"
libspeex_encoder_select="audio_frame_queue"
+libsvt_av1_encoder_deps="libsvtav1"
libtheora_encoder_deps="libtheora"
libtwolame_encoder_deps="libtwolame"
libvo_aacenc_encoder_deps="libvo_aacenc"
@@ -4692,6 +4695,7 @@ enabled libschroedinger && require_pkg_config libschroedinger schroedinger-1.0
enabled libsnappy && require libsnappy snappy-c.h snappy_compress -lsnappy
enabled libspeex && require_pkg_config libspeex speex speex/speex.h speex_decoder_init
enabled libsrt && require_pkg_config libsrt "srt >= 1.3.0" srt/srt.h srt_socket
+enabled libsvtav1 && require_pkg_config libsvtav1 SvtAv1Enc EbSvtAv1Enc.h eb_init_handle
enabled libtheora && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame
enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ea0c9dc..7f66c2f 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -718,6 +718,7 @@ OBJS-$(CONFIG_LIBSCHROEDINGER_ENCODER) += libschroedingerenc.o \
libschroedinger.o
OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o
OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o
+OBJS-$(CONFIG_LIBSVT_AV1_ENCODER) += libsvt_av1.o
OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o
OBJS-$(CONFIG_LIBTWOLAME_ENCODER) += libtwolame.o
OBJS-$(CONFIG_LIBVO_AACENC_ENCODER) += libvo-aacenc.o mpeg4audio.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4aee657..486405a 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -436,6 +436,7 @@ void avcodec_register_all(void)
REGISTER_ENCDEC (LIBSCHROEDINGER, libschroedinger);
REGISTER_ENCDEC (LIBSPEEX, libspeex);
REGISTER_ENCODER(LIBTHEORA, libtheora);
+ REGISTER_ENCODER(LIBSVT_AV1, libsvt_av1);
REGISTER_ENCODER(LIBTWOLAME, libtwolame);
REGISTER_ENCODER(LIBVO_AACENC, libvo_aacenc);
REGISTER_ENCODER(LIBVO_AMRWBENC, libvo_amrwbenc);
new file mode 100644
index 0000000..8f0e5a6
--- /dev/null
+++ b/libavcodec/libsvt_av1.c
@@ -0,0 +1,483 @@
+/*
+* Scalable Video Technology for AV1 encoder library plugin
+*
+* Copyright (c) 2018 Intel Corporation
+*
+* This file is part of FFmpeg.
+*
+* FFmpeg is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* FFmpeg is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include <stdint.h>
+#include "EbSvtAv1ErrorCodes.h"
+#include "EbSvtAv1Enc.h"
+
+#include "libavutil/common.h"
+#include "libavutil/frame.h"
+#include "libavutil/opt.h"
+
+#include "internal.h"
+#include "avcodec.h"
+
+typedef enum eos_status {
+ EOS_NOT_REACHED = 0,
+ EOS_SENT,
+ EOS_RECEIVED
+}EOS_STATUS;
+
+typedef struct SvtContext {
+ AVClass *class;
+
+ EbSvtAv1EncConfiguration enc_params;
+ EbComponentType *svt_handle;
+
+ EbBufferHeaderType *in_buf;
+ int raw_size;
+
+ EOS_STATUS eos_flag;
+
+ // User options.
+ int hierarchical_level;
+ int la_depth;
+ int enc_mode;
+ int rc_mode;
+ int scd;
+ int qp;
+
+ int forced_idr;
+
+ int aud;
+
+ int tier;
+ int level;
+
+ int base_layer_switch_mode;
+} SvtContext;
+
+static int error_mapping(EbErrorType svt_ret)
+{
+ int err;
+
+ switch (svt_ret) {
+ case EB_ErrorInsufficientResources:
+ err = AVERROR(ENOMEM);
+ break;
+
+ case EB_ErrorUndefined:
+ case EB_ErrorInvalidComponent:
+ case EB_ErrorBadParameter:
+ err = AVERROR(EINVAL);
+ break;
+
+ case EB_ErrorDestroyThreadFailed:
+ case EB_ErrorSemaphoreUnresponsive:
+ case EB_ErrorDestroySemaphoreFailed:
+ case EB_ErrorCreateMutexFailed:
+ case EB_ErrorMutexUnresponsive:
+ case EB_ErrorDestroyMutexFailed:
+ err = AVERROR_EXTERNAL;
+ break;
+
+ case EB_NoErrorEmptyQueue:
+ err = AVERROR(EAGAIN);
+
+ case EB_ErrorNone:
+ err = 0;
+ break;
+
+ default:
+ err = AVERROR_UNKNOWN;
+ }
+
+ return err;
+}
+
+static void free_buffer(SvtContext *svt_enc)
+{
+ if (svt_enc->in_buf) {
+ EbSvtIOFormat *in_data = (EbSvtIOFormat *)svt_enc->in_buf->p_buffer;
+ av_freep(&in_data);
+ av_freep(&svt_enc->in_buf);
+ }
+}
+
+static int alloc_buffer(EbSvtAv1EncConfiguration *config, SvtContext *svt_enc)
+{
+ const int pack_mode_10bit =
+ (config->encoder_bit_depth > 8) && (config->compressed_ten_bit_format == 0) ? 1 : 0;
+ const size_t luma_size_8bit =
+ config->source_width * config->source_height * (1 << pack_mode_10bit);
+ const size_t luma_size_10bit =
+ (config->encoder_bit_depth > 8 && pack_mode_10bit == 0) ? luma_size_8bit : 0;
+
+ EbSvtIOFormat *in_data;
+
+ svt_enc->raw_size = (luma_size_8bit + luma_size_10bit) * 3 / 2;
+
+ // allocate buffer for in and out
+ svt_enc->in_buf = av_mallocz(sizeof(*svt_enc->in_buf));
+ if (!svt_enc->in_buf)
+ goto failed;
+
+ in_data = av_mallocz(sizeof(*in_data));
+ if (!in_data)
+ goto failed;
+ svt_enc->in_buf->p_buffer = (unsigned char *)in_data;
+
+ svt_enc->in_buf->size = sizeof(*svt_enc->in_buf);
+ svt_enc->in_buf->p_app_private = NULL;
+
+ return 0;
+
+failed:
+ free_buffer(svt_enc);
+ return AVERROR(ENOMEM);
+}
+
+static int config_enc_params(EbSvtAv1EncConfiguration *param,
+ AVCodecContext *avctx)
+{
+ SvtContext *svt_enc = avctx->priv_data;
+ int ret;
+
+ param->source_width = avctx->width;
+ param->source_height = avctx->height;
+
+ if (avctx->pix_fmt == AV_PIX_FMT_YUV420P10) {
+ av_log(avctx, AV_LOG_DEBUG, "Set 10 bits depth input\n");
+ param->encoder_bit_depth = 10;
+ } else {
+ av_log(avctx, AV_LOG_DEBUG, "Set 8 bits depth input\n");
+ param->encoder_bit_depth = 8;
+ }
+
+ param->encoder_color_format = EB_YUV420;
+
+ // Update param from options
+ param->hierarchical_levels = svt_enc->hierarchical_level;
+ param->enc_mode = svt_enc->enc_mode;
+ param->tier = svt_enc->tier;
+ param->level = svt_enc->level;
+ param->rate_control_mode = svt_enc->rc_mode;
+ param->scene_change_detection = svt_enc->scd;
+ param->base_layer_switch_mode = svt_enc->base_layer_switch_mode;
+ param->qp = svt_enc->qp;
+
+
+ param->target_bit_rate = avctx->bit_rate;
+ if (avctx->gop_size > 0)
+ param->intra_period_length = avctx->gop_size - 1;
+
+ if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
+ param->frame_rate_numerator = avctx->framerate.num;
+ param->frame_rate_denominator = avctx->framerate.den * avctx->ticks_per_frame;
+ } else {
+ param->frame_rate_numerator = avctx->time_base.den;
+ param->frame_rate_denominator = avctx->time_base.num * avctx->ticks_per_frame;
+ }
+
+ if (param->rate_control_mode) {
+ param->max_qp_allowed = avctx->qmax;
+ param->min_qp_allowed = avctx->qmin;
+ }
+
+ param->intra_refresh_type = svt_enc->forced_idr + 1;
+
+ if (svt_enc->la_depth != -1)
+ param->look_ahead_distance = svt_enc->la_depth;
+
+ ret = alloc_buffer(param, svt_enc);
+
+ return ret;
+}
+
+static void read_in_data(EbSvtAv1EncConfiguration *config,
+ const AVFrame *frame,
+ EbBufferHeaderType *headerPtr)
+{
+ uint8_t is16bit = config->encoder_bit_depth > 8;
+ uint64_t luma_size =
+ (uint64_t)config->source_width * config->source_height<< is16bit;
+ EbSvtIOFormat *in_data = (EbSvtIOFormat *)headerPtr->p_buffer;
+
+ // support yuv420p and yuv420p010
+ in_data->luma = frame->data[0];
+ in_data->cb = frame->data[1];
+ in_data->cr = frame->data[2];
+
+ // stride info
+ in_data->y_stride = frame->linesize[0] >> is16bit;
+ in_data->cb_stride = frame->linesize[1] >> is16bit;
+ in_data->cr_stride = frame->linesize[2] >> is16bit;
+
+ headerPtr->n_filled_len += luma_size * 3/2u;
+}
+
+static av_cold int eb_enc_init(AVCodecContext *avctx)
+{
+ SvtContext *svt_enc = avctx->priv_data;
+ EbErrorType svt_ret;
+
+ svt_enc->eos_flag = EOS_NOT_REACHED;
+
+ svt_ret = eb_init_handle(&svt_enc->svt_handle, svt_enc, &svt_enc->enc_params);
+ if (svt_ret != EB_ErrorNone) {
+ av_log(avctx, AV_LOG_ERROR, "Error init encoder handle\n");
+ goto failed;
+ }
+
+ svt_ret = config_enc_params(&svt_enc->enc_params, avctx);
+ if (svt_ret != EB_ErrorNone) {
+ av_log(avctx, AV_LOG_ERROR, "Error configure encoder parameters\n");
+ goto failed_init_handle;
+ }
+
+ svt_ret = eb_svt_enc_set_parameter(svt_enc->svt_handle, &svt_enc->enc_params);
+ if (svt_ret != EB_ErrorNone) {
+ av_log(avctx, AV_LOG_ERROR, "Error setting encoder parameters\n");
+ goto failed_init_handle;
+ }
+
+ svt_ret = eb_init_encoder(svt_enc->svt_handle);
+ if (svt_ret != EB_ErrorNone) {
+ av_log(avctx, AV_LOG_ERROR, "Error init encoder\n");
+ goto failed_init_handle;
+ }
+
+ if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
+ EbBufferHeaderType *headerPtr = NULL;
+
+ svt_ret = eb_svt_enc_stream_header(svt_enc->svt_handle, &headerPtr);
+ if (svt_ret != EB_ErrorNone) {
+ av_log(avctx, AV_LOG_ERROR, "Error when build stream header.\n");
+ goto failed_init_enc;
+ }
+
+ avctx->extradata_size = headerPtr->n_filled_len;
+ avctx->extradata = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!avctx->extradata) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Cannot allocate AV1 header of size %d.\n", avctx->extradata_size);
+ svt_ret = EB_ErrorInsufficientResources;
+ goto failed_init_enc;
+ }
+
+ memcpy(avctx->extradata, headerPtr->p_buffer, avctx->extradata_size);
+
+ svt_ret = eb_svt_release_enc_stream_header(headerPtr);
+ if (svt_ret != EB_ErrorNone) {
+ av_log(avctx, AV_LOG_ERROR, "Error when destroy stream header.\n");
+ goto failed_init_enc;
+ }
+ }
+
+ return 0;
+
+failed_init_enc:
+ eb_deinit_encoder(svt_enc->svt_handle);
+failed_init_handle:
+ eb_deinit_handle(svt_enc->svt_handle);
+failed:
+ free_buffer(svt_enc);
+ return error_mapping(svt_ret);
+}
+
+static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame)
+{
+ SvtContext *svt_enc = avctx->priv_data;
+ EbBufferHeaderType *headerPtr = svt_enc->in_buf;
+
+ if (!frame) {
+ EbBufferHeaderType headerPtrLast;
+ headerPtrLast.n_alloc_len = 0;
+ headerPtrLast.n_filled_len = 0;
+ headerPtrLast.n_tick_count = 0;
+ headerPtrLast.p_app_private = NULL;
+ headerPtrLast.p_buffer = NULL;
+ headerPtrLast.flags = EB_BUFFERFLAG_EOS;
+
+ eb_svt_enc_send_picture(svt_enc->svt_handle, &headerPtrLast);
+ svt_enc->eos_flag = EOS_SENT;
+ av_log(avctx, AV_LOG_DEBUG, "Finish sending frames!!!\n");
+ return 0;
+ }
+
+ read_in_data(&svt_enc->enc_params, frame, headerPtr);
+
+ headerPtr->flags = 0;
+ headerPtr->p_app_private = NULL;
+ headerPtr->pts = frame->pts;
+
+ eb_svt_enc_send_picture(svt_enc->svt_handle, headerPtr);
+
+ return 0;
+}
+
+static int eb_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
+{
+ SvtContext *svt_enc = avctx->priv_data;
+ EbBufferHeaderType *headerPtr;
+ EbErrorType svt_ret;
+ int ret = 0;
+
+ if (svt_enc->eos_flag == EOS_RECEIVED)
+ return AVERROR_EOF;
+
+ if ((ret = ff_alloc_packet2(avctx, pkt, svt_enc->raw_size, 0)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to allocate output packet.\n");
+ return ret;
+ }
+ svt_ret = eb_svt_get_packet(svt_enc->svt_handle, &headerPtr, svt_enc->eos_flag);
+ if (svt_ret == EB_NoErrorEmptyQueue)
+ return AVERROR(EAGAIN);
+
+ memcpy(pkt->data, headerPtr->p_buffer, headerPtr->n_filled_len);
+ pkt->size = headerPtr->n_filled_len;
+ pkt->pts = headerPtr->pts;
+ pkt->dts = headerPtr->dts;
+ if (headerPtr->pic_type == EB_AV1_KEY_PICTURE)
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ if (headerPtr->pic_type == EB_AV1_NON_REF_PICTURE)
+ pkt->flags |= AV_PKT_FLAG_DISPOSABLE;
+
+ if (headerPtr->flags & EB_BUFFERFLAG_EOS)
+ svt_enc->eos_flag = EOS_RECEIVED;
+
+ eb_svt_release_out_buffer(&headerPtr);
+
+ return ret;
+}
+
+static av_cold int eb_enc_close(AVCodecContext *avctx)
+{
+ SvtContext *svt_enc = avctx->priv_data;
+
+ eb_deinit_encoder(svt_enc->svt_handle);
+ eb_deinit_handle(svt_enc->svt_handle);
+
+ free_buffer(svt_enc);
+
+ return 0;
+}
+
+#define OFFSET(x) offsetof(SvtContext, x)
+#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "aud", "Include AUD", OFFSET(aud),
+ AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+
+ { "hielevel", "Hierarchical prediction levels setting", OFFSET(hierarchical_level),
+ AV_OPT_TYPE_INT, { .i64 = 4 }, 3, 4, VE , "hielevel"},
+ { "flat", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "hielevel" },
+ { "2level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "hielevel" },
+ { "3level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, VE, "hielevel" },
+ { "4level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 4 }, INT_MIN, INT_MAX, VE, "hielevel" },
+
+ { "la_depth", "Look ahead distance [0, 256]", OFFSET(la_depth),
+ AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 256, VE },
+
+ { "preset", "Encoding preset [0, 7]",
+ OFFSET(enc_mode), AV_OPT_TYPE_INT, { .i64 = MAX_ENC_PRESET }, 0, MAX_ENC_PRESET, VE },
+
+ { "tier", "Set tier (general_tier_flag)", OFFSET(tier),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE, "tier" },
+ { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, VE, "tier" },
+ { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, VE, "tier" },
+
+ { "level", "Set level (level_idc)", OFFSET(level),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0x1f, VE, "level" },
+
+#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
+ { .i64 = value }, 0, 0, VE, "level"
+ { LEVEL("2.0", 20) },
+ { LEVEL("2.1", 21) },
+ { LEVEL("2.2", 22) },
+ { LEVEL("2.3", 23) },
+ { LEVEL("3.0", 30) },
+ { LEVEL("3.1", 31) },
+ { LEVEL("3.2", 32) },
+ { LEVEL("3.3", 33) },
+ { LEVEL("4.0", 40) },
+ { LEVEL("4.1", 41) },
+ { LEVEL("4.2", 42) },
+ { LEVEL("4.3", 43) },
+ { LEVEL("5.0", 50) },
+ { LEVEL("5.1", 51) },
+ { LEVEL("5.2", 52) },
+ { LEVEL("5.3", 53) },
+ { LEVEL("6.0", 60) },
+ { LEVEL("6.1", 61) },
+ { LEVEL("6.2", 62) },
+ { LEVEL("6.3", 63) },
+ { LEVEL("7.0", 70) },
+ { LEVEL("7.1", 71) },
+ { LEVEL("7.2", 72) },
+ { LEVEL("7.3", 73) },
+#undef LEVEL
+
+ { "rc", "Bit rate control mode", OFFSET(rc_mode),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE , "rc"},
+ { "cqp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "rc" },
+ { "vbr", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "rc" },
+
+ { "qp", "QP value for intra frames", OFFSET(qp),
+ AV_OPT_TYPE_INT, { .i64 = 50 }, 0, 63, VE },
+
+ { "sc_detection", "Scene change detection", OFFSET(scd),
+ AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+
+ { "bl_mode", "Random Access Prediction Structure type setting", OFFSET(base_layer_switch_mode),
+ AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+
+ { "forced-idr", "If forcing keyframes, force them as IDR frames.", OFFSET(forced_idr),
+ AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+
+ {NULL},
+};
+
+static const AVClass class = {
+ .class_name = "libsvt_av1",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVCodecDefault eb_enc_defaults[] = {
+ { "b", "7M" },
+ { "g", "-2" },
+ { "qmin", "0" },
+ { "qmax", "63" },
+ { NULL },
+};
+
+AVCodec ff_libsvt_av1_encoder = {
+ .name = "libsvt_av1",
+ .long_name = NULL_IF_CONFIG_SMALL("SVT-AV1(Scalable Video Technology for AV1) encoder"),
+ .priv_data_size = sizeof(SvtContext),
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_AV1,
+ .init = eb_enc_init,
+ .send_frame = eb_send_frame,
+ .receive_packet = eb_receive_packet,
+ .close = eb_enc_close,
+ .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS,
+ .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
+ AV_PIX_FMT_YUV420P10,
+ AV_PIX_FMT_NONE },
+ .priv_class = &class,
+ .defaults = eb_enc_defaults,
+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
+ .wrapper_name = "libsvt_av1",
+};
--
1.8.3.1