├── .gitignore ├── README.md ├── ffmpeg-wrapper.sh └── patcher.sh /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MediaServer-FFMPEG-Patcher 2 | 3 | This patcher is designed to simplify the patching steps of the Synology MediaServer and bring DTS, TrueHD and EAC3 transcoding support. 4 | 5 | ### Also want to patch VideoStation ? [there you go](https://github.com/AlexPresso/videostation-ffmpeg-patcher) 6 | 7 | ## Dependencies 8 | - DSM 6.2.2-24922 Update 4 (and above) 9 | - SynoCommunity ffmpeg 4.2.1-23 (and above) ([help](https://synocommunity.com/#easy-install)) 10 | 11 | ## Instructions 12 | - Check that you meet the required [dependencies](https://github.com/AlexPresso/mediaserver-ffmpeg-patcher#dependencies) 13 | - Install SynoCommunity ffmpeg ([help](https://synocommunity.com/#easy-install)) 14 | - Connect to your NAS using SSH (admin user required) ([help](https://www.synology.com/en-global/knowledgebase/DSM/tutorial/General_Setup/How_to_login_to_DSM_with_root_permission_via_SSH_Telnet)) 15 | - Use the command `sudo -i` to switch to root user 16 | - Use the [following](https://github.com/AlexPresso/mediaserver-ffmpeg-patcher#usage) command (Basic command) to execute the patch 17 | - Enable audio transcoding in MediaServer settings 18 | - You'll have to re-run the patcher everytime you update MediaServer and DSM 19 | 20 | ## Usage 21 | Basic command: 22 | `curl https://raw.githubusercontent.com/AlexPresso/mediaserver-ffmpeg-patcher/main/patcher.sh | bash` 23 | With options: 24 | `curl https://raw.githubusercontent.com/AlexPresso/mediaserver-ffmpeg-patcher/main/patcher.sh | bash -s -- ` 25 | 26 | | Flags | Required | Description | 27 | |-------|----------|---------------------------------------------------------------------------------| 28 | | -a | No | Action flag: choose between patch or unpatch ; example: `-a patch` | 29 | | -b | No | Branch flag: allows you to choose the wrapper branch to use ; example `-b main` | 30 | -------------------------------------------------------------------------------- /ffmpeg-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ######################### 4 | # VARS 5 | ######################### 6 | 7 | pid=$$ 8 | stderrfile="/tmp/ffmpeg-$pid.stderr" 9 | logfile="/tmp/ffmpeg.log" 10 | 11 | ######################### 12 | # UTILS 13 | ######################### 14 | 15 | function log() { 16 | echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$1] $2" >> $logfile 17 | } 18 | function newline() { 19 | echo "" >> $logfile 20 | } 21 | function info() { 22 | log "INFO" "$1" 23 | } 24 | 25 | function handle_error() { 26 | log "ERROR" "Error on line $(caller)" 27 | endprocess 28 | } 29 | 30 | function endprocess() { 31 | info "========================================[end ffmpeg (MediaServer) $pid]" 32 | newline 33 | rm -f "$stderrfile" 34 | exit 1 35 | } 36 | 37 | ######################### 38 | # ENTRYPOINT 39 | ######################### 40 | 41 | trap endprocess SIGTERM 42 | trap handle_error ERR 43 | 44 | newline 45 | info "========================================[start ffmpeg (MediaServer) $pid]" 46 | info "DEFAULT_ARGS: $*" 47 | 48 | /var/packages/ffmpeg/target/bin/ffmpeg "$@" 2> $stderrfile 49 | 50 | endprocess 51 | -------------------------------------------------------------------------------- /patcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ############################### 4 | # VARS 5 | ############################### 6 | 7 | dsm_version=$(cat /etc.defaults/VERSION | grep productversion | sed 's/productversion=//' | tr -d '"') 8 | repo_base_url="https://github.com/AlexPresso/mediaserver-ffmpeg-patcher" 9 | version="1.0" 10 | action="patch" 11 | branch="main" 12 | dependencies=("MediaServer" "ffmpeg") 13 | wrappers=("ffmpeg") 14 | 15 | ms_path=/var/packages/MediaServer/target 16 | libsynovte_path="$ms_path/lib/libsynovte.so" 17 | 18 | ############################### 19 | # UTILS 20 | ############################### 21 | 22 | function log() { 23 | echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$1] $2" 24 | } 25 | function info() { 26 | log "INFO" "$1" 27 | } 28 | function error() { 29 | log "ERROR" "$1" 30 | } 31 | 32 | function root_check() { 33 | if [[ "$EUID" -ne 0 ]]; then 34 | error "This tool needs root access (please run 'sudo -i' before proceeding)." 35 | exit 1 36 | fi 37 | } 38 | 39 | function restart_packages() { 40 | info "Restarting MediaServer..." 41 | synopkg restart MediaServer 42 | } 43 | 44 | function check_dependencies() { 45 | missingDeps=false 46 | 47 | for dependency in "${dependencies[@]}"; do 48 | if [[ ! -d "/var/packages/$dependency" ]]; then 49 | error "Missing $dependency package, please install it and re-run the patcher." 50 | missingDeps=true 51 | fi 52 | done 53 | 54 | if [[ $missingDeps -eq 1 ]]; then 55 | exit 1 56 | fi 57 | } 58 | 59 | ################################ 60 | # PATCH PROCEDURES 61 | ################################ 62 | 63 | function patch() { 64 | info "====== Patching procedure (branch: $branch) ======" 65 | 66 | for filename in "${wrappers[@]}"; do 67 | if [[ -f "$ms_path/bin/$filename" ]]; then 68 | info "Saving current $filename as $filename.orig" 69 | mv -n "$ms_path/bin/$filename" "$ms_path/bin/$filename.orig" 70 | 71 | info "Downloading and installing $filename's wrapper..." 72 | wget -q -O - "$repo_base_url/blob/$branch/$filename-wrapper.sh?raw=true" > "$ms_path/bin/$filename" 73 | chown root:MediaServer "$ms_path/bin/$filename" 74 | chmod 750 "$ms_path/bin/$filename" 75 | chmod u+s "$ms_path/bin/$filename" 76 | fi 77 | done 78 | 79 | info "Saving current libsynovte.so as libsynovte.so.orig" 80 | cp -n "$libsynovte_path" "$libsynovte_path.orig" 81 | chown MediaServer:MediaServer "$libsynovte_path.orig" 82 | 83 | info "Enabling eac3, dts and truehd" 84 | sed -i -e 's/eac3/3cae/' -e 's/dts/std/' -e 's/truehd/dheurt/' "$libsynovte_path" 85 | 86 | restart_packages 87 | 88 | echo "" 89 | info "Done patching, you can now enjoy your movies ;) (please add a star to the repo if it worked for you)" 90 | } 91 | 92 | function unpatch() { 93 | info "====== Unpatch procedure ======" 94 | 95 | info "Restoring libsynovte.so" 96 | mv -T -f "$libsynovte_path.orig" "$libsynovte_path" 97 | 98 | find "$ms_path/bin" -type f -name "*.orig" | while read -r filename; do 99 | info "Restoring MediaServer $filename" 100 | mv -T -f "$filename" "${filename::-5}" 101 | done 102 | 103 | restart_packages 104 | 105 | echo "" 106 | info "unpatch complete" 107 | } 108 | 109 | ################################ 110 | # ENTRYPOINT 111 | ################################ 112 | root_check 113 | check_dependencies 114 | 115 | while getopts a:b: flag; do 116 | case "${flag}" in 117 | a) action=${OPTARG};; 118 | b) branch=${OPTARG};; 119 | *) echo "usage: $0 [-a patch|unpatch] [-b branch]" >&2; exit 1;; 120 | esac 121 | done 122 | 123 | info "You're running DSM $dsm_version" 124 | 125 | case "$action" in 126 | unpatch) unpatch;; 127 | patch) patch;; 128 | esac 129 | --------------------------------------------------------------------------------