Skip to content

Commit 8295409

Browse files
committed
+) Enable vaapi hw acceleration for h264 and HEVC
+) Add ffmpeg patches for invalid reference frames in vaapi hevc/ h264
1 parent 34289d4 commit 8295409

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed

ffmpeg/cppbuild.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fi
1010
DISABLE="--disable-iconv --disable-opencl --disable-sdl2 --disable-bzlib --disable-lzma --disable-linux-perf --disable-xlib"
1111
ENABLE="--enable-shared --enable-version3 --enable-runtime-cpudetect --enable-zlib --enable-libmp3lame --enable-libspeex --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-openssl --enable-libopenh264 --enable-libvpx --enable-libfreetype --enable-libopus --enable-libxml2 --enable-libsrt --enable-libwebp --enable-libaom --enable-libsvtav1 --enable-libzimg"
1212
ENABLE_VULKAN="--enable-vulkan --enable-hwaccel=h264_vulkan --enable-hwaccel=hevc_vulkan --enable-hwaccel=av1_vulkan"
13+
ENABLE_VAAPI="--enable-hwaccel=h264_vaapi --enable-hwaccel=hevc_vaapi"
1314

1415
if [[ "$EXTENSION" == *gpl ]]; then
1516
# Enable GPLv3 modules
@@ -119,6 +120,8 @@ patch -Np1 -d $LAME < ../../lame.patch
119120
patch -Np1 -d $OPENSSL < ../../openssl-android.patch
120121
patch -Np1 -d ffmpeg-$FFMPEG_VERSION < ../../ffmpeg.patch
121122
patch -Np1 -d ffmpeg-$FFMPEG_VERSION < ../../ffmpeg-vulkan.patch
123+
patch -Np1 -d ffmpeg-$FFMPEG_VERSION < ../../ffmpeg-lavc-vaapi_h264-Fixup-invalid-references.patch
124+
patch -Np1 -d ffmpeg-$FFMPEG_VERSION < ../../ffmpeg-lavc-vaapi_hevc-Fixup-invalid-references.patch
122125
# patch -Np1 -d ffmpeg-$FFMPEG_VERSION < ../../ffmpeg-flv-support-hevc-opus.patch
123126
sedinplace 's/bool bEnableavx512/bool bEnableavx512 = false/g' x265-*/source/common/param.h
124127
sedinplace 's/detect512()/false/g' x265-*/source/common/quant.cpp
@@ -886,7 +889,7 @@ EOF
886889
make install
887890
cd ..
888891
cd ../ffmpeg-$FFMPEG_VERSION
889-
LDEXEFLAGS='-Wl,-rpath,\$$ORIGIN/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-libdrm --enable-cuda --enable-cuvid --enable-nvenc --enable-pthreads --enable-libxcb --enable-libpulse --cc="gcc -m32 -D__ILP32__" --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -lpthread -ldl -lz -lm $LIBS" || cat ffbuild/config.log
892+
LDEXEFLAGS='-Wl,-rpath,\$$ORIGIN/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-libdrm $ENABLE_VAAPI --enable-cuda --enable-cuvid --enable-nvenc --enable-pthreads --enable-libxcb --enable-libpulse --cc="gcc -m32 -D__ILP32__" --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -lpthread -ldl -lz -lm $LIBS" || cat ffbuild/config.log
890893
make -j $MAKEJ
891894
make install
892895
;;
@@ -1036,7 +1039,7 @@ EOF
10361039
make install
10371040
cd ..
10381041
cd ../ffmpeg-$FFMPEG_VERSION
1039-
LDEXEFLAGS='-Wl,-rpath,\$$ORIGIN/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-libdrm --enable-cuda --enable-cuvid --enable-nvenc --enable-pthreads --enable-libxcb --enable-libpulse --cc="gcc -m64" --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -lpthread -ldl -lz -lm $LIBS" || cat ffbuild/config.log
1042+
LDEXEFLAGS='-Wl,-rpath,\$$ORIGIN/' PKG_CONFIG_PATH=../lib/pkgconfig/ ./configure --prefix=.. $DISABLE $ENABLE $ENABLE_VULKAN --enable-libdrm $ENABLE_VAAPI --enable-cuda --enable-cuvid --enable-nvenc --enable-pthreads --enable-libxcb --enable-libpulse --cc="gcc -m64" --extra-cflags="-I../include/ -I../include/libxml2 -I../include/mfx -I../include/svt-av1" --extra-ldflags="-L../lib/" --extra-libs="-lstdc++ -lpthread -ldl -lz -lm $LIBS" || cat ffbuild/config.log
10401043
make -j $MAKEJ
10411044
make install
10421045
;;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
From 9d4b9b0b963f5375317636f4f527a203e21e89b9 Mon Sep 17 00:00:00 2001
2+
From: David Rosca <[email protected]>
3+
Date: Mon, 8 Jan 2024 12:44:20 +0100
4+
Subject: [PATCH] lavc/vaapi_h264: Fixup invalid references
5+
6+
---
7+
libavcodec/vaapi_h264.c | 20 +++++++++++++++++++-
8+
1 file changed, 19 insertions(+), 1 deletion(-)
9+
10+
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
11+
index 55cf5a05ee..c935c88bad 100644
12+
--- a/libavcodec/vaapi_h264.c
13+
+++ b/libavcodec/vaapi_h264.c
14+
@@ -128,6 +128,8 @@ static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param,
15+
DPB dpb;
16+
int i;
17+
18+
+ const H264Picture *pic_good = NULL;
19+
+
20+
dpb.size = 0;
21+
dpb.max_size = FF_ARRAY_ELEMS(pic_param->ReferenceFrames);
22+
dpb.va_pics = pic_param->ReferenceFrames;
23+
@@ -136,7 +138,23 @@ static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param,
24+
25+
for (i = 0; i < h->short_ref_count; i++) {
26+
const H264Picture *pic = h->short_ref[i];
27+
- if (pic && pic->reference && dpb_add(&dpb, pic) < 0)
28+
+ if (!pic || !pic->reference)
29+
+ continue;
30+
+ if (pic->recovered) {
31+
+ pic_good = pic;
32+
+ } else {
33+
+ if (pic_good) {
34+
+ pic = pic_good;
35+
+ } else {
36+
+ for (int i = 0; i < h->short_ref_count; i++) {
37+
+ if (h->short_ref[i] && h->short_ref[i]->reference && h->short_ref[i]->recovered) {
38+
+ pic = h->short_ref[i];
39+
+ break;
40+
+ }
41+
+ }
42+
+ }
43+
+ }
44+
+ if (dpb_add(&dpb, pic) < 0)
45+
return -1;
46+
}
47+
48+
--
49+
2.43.0
50+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 1b516ca017fa45888d4962ebf97a78987e696209 Mon Sep 17 00:00:00 2001
2+
From: David Rosca <[email protected]>
3+
Date: Sun, 10 Dec 2023 10:00:28 +0100
4+
Subject: [PATCH] lavc/vaapi_hevc: Fixup invalid references
5+
6+
---
7+
libavcodec/vaapi_hevc.c | 18 ++++++++++++++++++
8+
1 file changed, 18 insertions(+)
9+
10+
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
11+
index 3bdd2dd1b8..d08fb50e37 100644
12+
--- a/libavcodec/vaapi_hevc.c
13+
+++ b/libavcodec/vaapi_hevc.c
14+
@@ -100,6 +100,8 @@ static void fill_vaapi_reference_frames(const HEVCContext *h, VAPictureParameter
15+
const HEVCFrame *current_picture = h->ref;
16+
int i, j, rps_type;
17+
18+
+ const HEVCFrame *frame_good = NULL;
19+
+
20+
for (i = 0, j = 0; i < FF_ARRAY_ELEMS(pp->ReferenceFrames); i++) {
21+
const HEVCFrame *frame = NULL;
22+
23+
@@ -113,6 +115,22 @@ static void fill_vaapi_reference_frames(const HEVCContext *h, VAPictureParameter
24+
init_vaapi_pic(&pp->ReferenceFrames[i]);
25+
26+
if (frame) {
27+
+ if (frame->sequence != HEVC_SEQUENCE_COUNTER_INVALID) {
28+
+ frame_good = frame;
29+
+ } else {
30+
+ if (frame_good) {
31+
+ frame = frame_good;
32+
+ } else {
33+
+ for (int k = 0; k < FF_ARRAY_ELEMS(h->DPB); k++) {
34+
+ if ((&h->DPB[k] != current_picture || h->ps.pps->pps_curr_pic_ref_enabled_flag) &&
35+
+ (h->DPB[k].flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)) &&
36+
+ h->DPB[k].sequence != HEVC_SEQUENCE_COUNTER_INVALID) {
37+
+ frame = &h->DPB[k];
38+
+ break;
39+
+ }
40+
+ }
41+
+ }
42+
+ }
43+
rps_type = find_frame_rps_type(h, frame);
44+
fill_vaapi_pic(&pp->ReferenceFrames[i], frame, rps_type);
45+
}
46+
--
47+
2.43.0
48+

0 commit comments

Comments
 (0)