Skip to content

Instantly share code, notes, and snippets.

@danielfomin96
Last active June 19, 2023 01:36
Show Gist options
  • Save danielfomin96/e79d223d0cb439fadd868edccce9a172 to your computer and use it in GitHub Desktop.
Save danielfomin96/e79d223d0cb439fadd868edccce9a172 to your computer and use it in GitHub Desktop.
ffmpeg wrapper to customely downmix videos opened by jellyfin
#!/bin/bash -
#title :ffmpeg
#description :This script is a wrapper for jellyfin ffmpeg to downmix audio to stereo using a custom formula
#author :Daniel Fomin
#date :20230104
#version :0.2
#reference :https://superuser.com/questions/852400/properly-downmix-5-1-to-stereo-using-ffmpeg
#
#
#==============================================================================
###############################################################################
# Installation Notes:
# 1. Put wrapper in directory accessible from jellyfin
# 2. `chmod +x path/to/wrapper/dir/ffmpeg`
# 3. `ln -s $(which ffprobe) path/to/wrapper/dir/` to the same directory
# 4. Point jellyfin to the wrapper directory
#
###############################################################################
function join { local IFS=$'\n'; echo "${*}"; }
args=$(join "${@}")
match='-ac\n[3-9]'
replace='-af\npan=stereo|FL<0.707*FC+0.707*FL+0.707*BL+0.5*LFE|FR<0.707*FC+0.707*FR+0.707*BR+0.5*LFE'
ffmpeg="/usr/lib/jellyfin-ffmpeg/ffmpeg"
readarray -t new_args < <(sed -z "s/$match/$replace/g" <<<"$args")
#echo "Command Rewrite: $ffmpeg $new_args" 1>&2
$ffmpeg "${new_args[@]}"
exit $?
@ivaylo-mk
Copy link

Real noob question, but I stumbled upon your script and I am wondering if it is possible to use it somehow in Windows, as currently I am experiencing issues with Jellyfin and 5.1 audio, and want to force downmixing to stereo of everything that is being played.

@mark-cassidy
Copy link

mark-cassidy commented Jan 22, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment