# Contributor: Sergei Lukin <sergej.lukin@gmail.com>
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Jakub Skrzypnik <j.skrzypnik@openmailbox.org>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: FintasticMan <finlay.neon.kid@gmail.com>
pkgname=jellyfin-ffmpeg
pkgver=6.0.1_p7
_pkgver="${pkgver/_p/-}"
pkgrel=1
pkgdesc="Modified version of FFmpeg for Jellyfin"
url="https://github.com/jellyfin/jellyfin-ffmpeg"
arch="all"
license="GPL-3.0-only"
makedepends="
	alsa-lib-dev
	bzip2-dev
	chromaprint-dev
	coreutils
	dav1d-dev
	fontconfig-dev
	freetype-dev
	fribidi-dev
	gmp-dev
	imlib2-dev
	lame-dev
	libass-dev
	libbluray-dev
	libdrm-dev
	libopenmpt-dev
	libplacebo-dev
	libtheora-dev
	libva-dev
	libvorbis-dev
	libvpx-dev
	libwebp-dev
	nasm
	opencl-dev
	openssl-dev
	opus-dev
	perl-dev
	shaderc-dev
	vulkan-loader-dev
	x264-dev
	x265-dev
	xz-dev
	zimg-dev
	zlib-dev
	"
checkdepends="rsync"
source="$pkgname-$_pkgver.tar.gz::https://github.com/jellyfin/jellyfin-ffmpeg/archive/refs/tags/v$_pkgver.tar.gz
	0001-ffbuild-libversion.sh-add-shebang.patch
	"
options="!check" # tests/data/hls-lists.append.m3u8 fails
builddir="$srcdir/$pkgname-$_pkgver"

case "$CARCH" in
x86_64)
	makedepends="$makedepends onevpl-dev"
	_onevpl="--enable-libvpl"
	;;
esac

prepare() {
	default_prepare

	for i in debian/patches/*.patch; do
		patch -p1 -i "$i"
	done
}

build() {
	case "$CARCH" in
	x86) local asm="--disable-asm" ;;
	esac

	./configure \
		--prefix="/usr/lib/$pkgname" \
		--target-os=linux \
		--extra-version=Jellyfin \
		--disable-doc \
		--disable-ffplay \
		--disable-librtmp \
		--disable-libxcb \
		--disable-sdl2 \
		--disable-shared \
		--disable-xlib \
		--enable-chromaprint \
		--enable-gmp \
		--enable-gpl \
		--enable-libass \
		--enable-libbluray \
		--enable-libdav1d \
		--enable-libdrm \
		--enable-libfontconfig \
		--enable-libfreetype \
		--enable-libfribidi \
		--enable-libmp3lame \
		--enable-libopenmpt \
		--enable-libopus \
		--enable-libplacebo \
		--enable-libshaderc \
		--enable-libtheora \
		--enable-libvorbis \
		--enable-libvpx \
		--enable-libwebp \
		--enable-libx264 \
		--enable-libx265 \
		--enable-libzimg \
		--enable-opencl \
		--enable-openssl \
		--enable-pic \
		--enable-pthreads \
		--enable-static \
		--enable-vaapi \
		--enable-version3 \
		--enable-vulkan \
		$asm \
		$_onevpl
	make
}

# https://ffmpeg.org/fate.html
check() {
	./configure \
		--samples=fate-suite/
	make fate-rsync
	make fate-list
	make fate
}

package() {
	install -Dm755 -t "$pkgdir/usr/lib/$pkgname" ffmpeg ffprobe
}

sha512sums="
cd9864da887bcf2e07ea5c54337ed92cbd216561c297099719dde6c71a27cf6ede500aa6c54a78f26281ae7e8810fbc0d496616f36aeebab921e1f794e68fc72  jellyfin-ffmpeg-6.0.1-7.tar.gz
38443b570cf32b2ba8ffa9ecc5480425c7da9f93f9773fbb3f9ec5f603b369b6225f4329a1b1f34d0ef30b2c9730f25ff9cff31315ed0a89a600df8e53bd54bf  0001-ffbuild-libversion.sh-add-shebang.patch
"
