Skip to content

Commit

Permalink
Merge pull request #498 from nyanmisaka/fix-rkmpp-enc-pkt-free
Browse files Browse the repository at this point in the history
Fix artifacts caused by delayed release of MppPacket data
  • Loading branch information
nyanmisaka authored Nov 11, 2024
2 parents 55eeb86 + 4e94c66 commit af68c43
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# We just wrap `build` so this is really it
name: "jellyfin-ffmpeg"
version: "7.0.2-5"
version: "7.0.2-6"
packages:
- bullseye-amd64
- bullseye-armhf
Expand Down
2 changes: 1 addition & 1 deletion builder/scripts.d/50-rkmpp.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

SCRIPT_REPO="https://github.com/nyanmisaka/mpp.git"
SCRIPT_COMMIT="ba5c98ac8dbf485de9f03e625e1dd024afdc2eb9"
SCRIPT_COMMIT="110d2660a18855656205cdda8f40527c8a9cc3c1"
SCRIPT_BRANCH="jellyfin-mpp"

ffbuild_enabled() {
Expand Down
6 changes: 3 additions & 3 deletions builder/scripts.d/50-svtav1.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

SCRIPT_REPO="https://gitlab.com/AOMediaCodec/SVT-AV1.git"
SCRIPT_COMMIT="34d4d591d87aeba6d347f09bfb5a7429fe58bd46"
SCRIPT_COMMIT="6e69def4ec283fe0b71195671245c3b768bebdef"

ffbuild_enabled() {
[[ $TARGET == win32 ]] && return -1
Expand All @@ -16,10 +16,10 @@ ffbuild_dockerbuild() {
mkdir -p build && cd build

if [[ $TARGET == mac* ]]; then
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$FFBUILD_PREFIX" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_APPS=OFF -DENABLE_AVX512=ON ..
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$FFBUILD_PREFIX" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_APPS=OFF ..

else
cmake -DCMAKE_TOOLCHAIN_FILE="$FFBUILD_CMAKE_TOOLCHAIN" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$FFBUILD_PREFIX" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_APPS=OFF -DENABLE_AVX512=ON ..
cmake -DCMAKE_TOOLCHAIN_FILE="$FFBUILD_CMAKE_TOOLCHAIN" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$FFBUILD_PREFIX" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_APPS=OFF ..
fi
make -j$(nproc)
make install
Expand Down
8 changes: 8 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
jellyfin-ffmpeg (7.0.2-6) unstable; urgency=medium

* Use dynamic pool for VPL QSV hwupload to save VRAM
* Fix artifacts caused by delayed release of MppPacket data
* Update dependencies

-- nyanmisaka <[email protected]> Sun, 10 Nov 2024 22:03:57 +0800

jellyfin-ffmpeg (7.0.2-5) unstable; urgency=medium

* Add bsf options to drop the DoVi and HDR10Plus metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ Index: FFmpeg/libavcodec/rkmppenc.c
===================================================================
--- /dev/null
+++ FFmpeg/libavcodec/rkmppenc.c
@@ -0,0 +1,1114 @@
@@ -0,0 +1,1116 @@
+/*
+ * Copyright (c) 2023 Huseyin BIYIK
+ * Copyright (c) 2023 NyanMisaka
Expand Down Expand Up @@ -2662,12 +2662,6 @@ Index: FFmpeg/libavcodec/rkmppenc.c
+ return ret;
+}
+
+static void rkmpp_free_packet_buf(void *opaque, uint8_t *data)
+{
+ MppPacket mpp_pkt = opaque;
+ mpp_packet_deinit(&mpp_pkt);
+}
+
+static int rkmpp_get_packet(AVCodecContext *avctx, AVPacket *packet, int timeout)
+{
+ RKMPPEncContext *r = avctx->priv_data;
Expand Down Expand Up @@ -2698,13 +2692,15 @@ Index: FFmpeg/libavcodec/rkmppenc.c
+ }
+ av_log(avctx, AV_LOG_DEBUG, "Received a packet\n");
+
+ packet->data = mpp_packet_get_data(mpp_pkt);
+ packet->size = mpp_packet_get_length(mpp_pkt);
+ packet->buf = av_buffer_create(packet->data, packet->size, rkmpp_free_packet_buf,
+ mpp_pkt, AV_BUFFER_FLAG_READONLY);
+ if (!packet->buf) {
+ ret = AVERROR(ENOMEM);
+ goto exit;
+ /* freeing MppPacket data in buffer callbacks is not supported in async mode */
+ {
+ size_t mpp_pkt_length = mpp_packet_get_length(mpp_pkt);
+
+ if ((ret = ff_get_encode_buffer(avctx, packet, mpp_pkt_length, 0)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "ff_get_encode_buffer failed: %d\n", ret);
+ goto exit;
+ }
+ memcpy(packet->data, mpp_packet_get_data(mpp_pkt), mpp_pkt_length);
+ }
+
+ packet->time_base.num = avctx->time_base.num;
Expand All @@ -2718,6 +2714,7 @@ Index: FFmpeg/libavcodec/rkmppenc.c
+ ret = AVERROR_EXTERNAL;
+ goto exit;
+ }
+ mpp_packet_deinit(&mpp_pkt);
+
+ mpp_meta_get_s32(mpp_meta, KEY_OUTPUT_INTRA, &key_frame);
+ if (key_frame)
Expand Down Expand Up @@ -2796,6 +2793,11 @@ Index: FFmpeg/libavcodec/rkmppenc.c
+ r->cfg_init = 0;
+ r->async_frames = 0;
+
+ if (r->mcfg) {
+ mpp_enc_cfg_deinit(r->mcfg);
+ r->mcfg = NULL;
+ }
+
+ if (r->mapi) {
+ r->mapi->reset(r->mctx);
+ mpp_destroy(r->mctx);
Expand Down Expand Up @@ -3267,7 +3269,7 @@ Index: FFmpeg/libavcodec/rkmppenc.h
+static const FFCodecDefault rkmpp_enc_defaults[] = {
+ { "b", "2M" },
+ { "g", "250" },
+ { NULL }
+ { NULL },
+};
+
+#define DEFINE_RKMPP_ENCODER(x, X, xx) \
Expand Down
6 changes: 2 additions & 4 deletions docker-build-win64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ pushd x264
--host=${FF_TOOLCHAIN} \
--cross-prefix=${FF_CROSS_PREFIX} \
--disable-cli \
--enable-{static,lto,strip,pic}
--enable-{static,strip,pic}
make -j$(nproc)
make install
popd
Expand Down Expand Up @@ -456,15 +456,14 @@ popd
popd

# SVT-AV1
git clone -b v2.2.1 --depth=1 https://gitlab.com/AOMediaCodec/SVT-AV1.git
git clone -b v2.3.0 --depth=1 https://gitlab.com/AOMediaCodec/SVT-AV1.git
pushd SVT-AV1
mkdir build
pushd build
cmake \
-DCMAKE_TOOLCHAIN_FILE=${FF_CMAKE_TOOLCHAIN} \
-DCMAKE_INSTALL_PREFIX=${FF_DEPS_PREFIX} \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_AVX512=ON \
-DBUILD_{SHARED_LIBS,TESTING,APPS,DEC}=OFF \
..
make -j$(nproc)
Expand Down Expand Up @@ -593,7 +592,6 @@ fi
--disable-w32threads \
--enable-pthreads \
--enable-shared \
--enable-lto=auto \
--enable-gpl \
--enable-version3 \
--enable-schannel \
Expand Down
14 changes: 4 additions & 10 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,14 @@ prepare_extra_common() {

# SVT-AV1
pushd ${SOURCE_DIR}
git clone -b v2.2.1 --depth=1 https://gitlab.com/AOMediaCodec/SVT-AV1.git
git clone -b v2.3.0 --depth=1 https://gitlab.com/AOMediaCodec/SVT-AV1.git
pushd SVT-AV1
mkdir build
pushd build
if [ "${ARCH}" = "amd64" ]; then
svtav1_avx512="-DENABLE_AVX512=ON"
else
svtav1_avx512="-DENABLE_AVX512=OFF"
fi
cmake \
${CMAKE_TOOLCHAIN_OPT} \
-DCMAKE_INSTALL_PREFIX=${TARGET_DIR} \
-DCMAKE_BUILD_TYPE=Release \
$svtav1_avx512 \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_{TESTING,APPS,DEC}=OFF \
..
Expand Down Expand Up @@ -382,7 +376,7 @@ prepare_extra_amd64() {

# GMMLIB
pushd ${SOURCE_DIR}
git clone -b intel-gmmlib-22.5.2 --depth=1 https://github.com/intel/gmmlib.git
git clone -b intel-gmmlib-22.5.3 --depth=1 https://github.com/intel/gmmlib.git
pushd gmmlib
mkdir build && pushd build
cmake -DCMAKE_INSTALL_PREFIX=${TARGET_DIR} ..
Expand Down Expand Up @@ -439,7 +433,7 @@ prepare_extra_amd64() {
# VPL-GPU-RT (RT only)
# Provides VPL runtime (libmfx-gen.so.1.2) for 11th Gen Tiger Lake and newer
pushd ${SOURCE_DIR}
git clone -b intel-onevpl-24.4.1 --depth=1 https://github.com/intel/vpl-gpu-rt.git
git clone -b intel-onevpl-24.4.2 --depth=1 https://github.com/intel/vpl-gpu-rt.git
pushd vpl-gpu-rt
mkdir build && pushd build
cmake -DCMAKE_INSTALL_PREFIX=${TARGET_DIR} \
Expand All @@ -459,7 +453,7 @@ prepare_extra_amd64() {
# Full Feature Build: ENABLE_KERNELS=ON(Default) ENABLE_NONFREE_KERNELS=ON(Default)
# Free Kernel Build: ENABLE_KERNELS=ON ENABLE_NONFREE_KERNELS=OFF
pushd ${SOURCE_DIR}
git clone -b intel-media-24.4.1 --depth=1 https://github.com/intel/media-driver.git
git clone -b intel-media-24.4.2 --depth=1 https://github.com/intel/media-driver.git
pushd media-driver
# enable vc1 decode on dg2 (note that mtl+ is not supported)
wget -q -O - https://github.com/intel/media-driver/commit/d5dd47b.patch | git apply
Expand Down
2 changes: 1 addition & 1 deletion msys2/PKGBUILD/40-mingw-w64-svt-av1/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
_realname=SVT-AV1
pkgbase=mingw-w64-jellyfin-svt-av1
pkgname=("${MINGW_PACKAGE_PREFIX}-jellyfin-svt-av1")
pkgver=2.2.1
pkgver=2.3.0
pkgrel=1
pkgdesc="Scalable Video Technology AV1 encoder and decoder (mingw-w64)"
arch=('any')
Expand Down

0 comments on commit af68c43

Please sign in to comment.