#!/bin/sh
# ffmpeg of the package (jellyfin-ffmpeg, a static build) with the VA-API and Quick Sync drivers it loads at run time
# (libva, Intel's iHD and i965, oneVPL/Media SDK), all in ../ffmpeg/lib: nothing comes from DSM but the C library and
# the kernel. The same wrapper runs ffprobe and vainfo (bin/ffprobe and bin/vainfo are links to it).
here=$(cd "$(dirname "$0")/../ffmpeg" && pwd -P) || exit 127
lib="$here/lib"
LD_LIBRARY_PATH="$lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
LIBVA_DRIVERS_PATH="${KY_LIBVA_DRIVERS_PATH:-$lib/dri}"
ONEVPL_SEARCH_PATH="$lib"
export LD_LIBRARY_PATH LIBVA_DRIVERS_PATH ONEVPL_SEARCH_PATH
# libva picks the driver from the GPU (iHD or i965); KY_LIBVA_DRIVER_NAME forces one, for a diagnosis
if [ -n "${KY_LIBVA_DRIVER_NAME:-}" ]; then
  LIBVA_DRIVER_NAME="$KY_LIBVA_DRIVER_NAME"
  export LIBVA_DRIVER_NAME
fi
exec "$here/$(basename "$0")" "$@"
