#!/usr/bin/env zsh # just for macOS # # The default options for installing ffmpeg and mpv via brew do not include the activation of libplacebo. # As a result, when playing videos in Dolby Vision, the color mapping is not accurate. To resolve this issue, # a script is used to compile ffmpeg with libplacebo activated, followed by the building of mpv. # Extra: build mpv bundle, with jxl if [ "$(uname -s)" != "Darwin" ]; then echo "Only support macOS now." exit 1 fi # Colors GREEN='\033[0;32m' WHITE='\033[1;37m' GRAY='\033[37;40m' NC='\033[0m' # Check if Xcode installed for apple silicon # if [ "$(arch)" == "arm64" && ! -d "/Applications/Xcode.app" ]; then # echo "${WHITE}If you build for Apple Silicon, it is necessary to have Xcode installed to build mpv, as CLT alone is insufficient. Therefore, kindly install Xcode from the App Store before proceeding.${NC}" # exit 1 # fi # Install homebrew if not found if ! command -v brew &> /dev/null; then echo -n "${GRAY}brew is currently not found on your system. installing ... ${NC}" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" &> /dev/null && echo "${GREEN}Done${NC}" fi # source "$ZDOTDIR/.zshrc" &> /dev/null || source "$HOME/.zshrc" &> /dev/null || source "$HOME/.zshenv" &> /dev/null source "$ZDOTDIR/.zshrc" || source "$HOME/.zshrc" || source "$HOME/.zshenv" export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK if [ "$(arch)" = "x86_64" ]; then echo -n "${GRAY}installing yasm for building ffmpeg ... ${NC}" brew install yasm &> /dev/null && echo "${GREEN}Done${NC}" fi # Create working directory WORKDIR="$HOME/Downloads" if [ ! -e $WORKDIR ]; then mkdir -p "$WORKDIR" fi cd "$WORKDIR" # install jq to calculate intersection dependencies of ffmpeg and mpv if ! command -v jq &> /dev/null; then echo -n "${GRAY}install jq to calculate intersection dependencies of ffmpeg and mpv ... ${NC}" brew install jq &> /dev/null && echo "${GREEN}Done${NC}" fi # install dependencies only for ffmpeg and mpv ffmpegdeps=$(brew info --json ffmpeg | jq -r '.[].dependencies | join(" ")') mpvdeps=$(brew info --json mpv | jq -r '.[].dependencies | join(" ")') deps=$( cat < /dev/null) && echo "${GREEN} Done${NC}" || { echo "${WHITE} failed.${NC}"; echo $errvar } fi done # Regardless of the path I set for the SRT, I consistently encounter an error while compiling FFmpeg with the '--enable-libsrt' flag. Consequently, I have decided to abandon the flag. # export PKG_CONFIG_PATH="$(brew --prefix)/opt/srt/lib/pkgconfig:$PKG_CONFIG_PATH" # fetch ffmpeg and mpv source code echo "${WHITE}Clone ffmpeg ...${NC}" if [ -d "$WORKDIR/ffmpeg" ]; then cd "$WORKDIR/ffmpeg" if [ "$(git config --get remote.origin.url)" = "https://git.ffmpeg.org/ffmpeg.git" ]; then git pull else echo "${WHITE}$WORKDIR/ffmpeg is not official repo, please rename or remove it.${NC}" && exit 1 fi else git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg || exit 1 fi cd "${WORKDIR}" echo "${WHITE}Clone mpv ...${NC}" if [ -d "$WORKDIR/mpv" ]; then cd "$WORKDIR/mpv" if [ "$(git config --get remote.origin.url)" = "https://github.com/mpv-player/mpv.git" ]; then git pull else echo "${WHITE}$WORKDIR/mpv is not official repo, please rename or remove it.${NC}" && exit 1 fi else git clone https://github.com/mpv-player/mpv.git mpv || exit 1 fi # # compile ffmpeg echo "Start compiling ffmpeg ..." cd "$WORKDIR/ffmpeg" # 获取Clang编译器的构建版本 clang_build_version=$(clang --version | grep -oE '[0-9]+' | head -1) # check clang version if [ "$clang_build_version" -ge 15 ]; then # add -Wl,-ld_classic to ldflags export LDFLAGS="$LDFLAGS -Wl,-ld_classic" fi if [ -e "ffbuild/config.mak" ]; then sudo make clean fi ./configure --prefix="$(brew --prefix)" --cc=clang --arch=$(arch) --extra-cflags=-I$(brew --prefix)/include --extra-ldflags=-L$(brew --prefix)/lib --enable-shared --enable-pthreads --enable-version3 --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libplacebo --enable-libjxl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon --enable-vapoursynth || exit 1 make -j$(sysctl -n hw.physicalcpu) && sudo make install || exit 1 echo "${GREEN}Done${NC}" if ! command -v meson &> /dev/null; then echo -n "Installing meson to build mpv ..." brew install meson &> /dev/null && echo "${GREEN}Done${NC}" fi # # compile mpv echo "Start compiling mpv ..." cd "$WORKDIR/mpv" sed -i -e 's/UNKNOWN/1/g' "$WORKDIR/mpv/VERSION" rm -rf "$WORKDIR/mpv/build" meson setup build || exit 1 meson compile -j$(sysctl -n hw.physicalcpu) -C build && sudo meson install -C build || exit 1 ./TOOLS/osxbundle.py -s build/mpv || exit 1 # fix crash on Sonoma rm build/mpv.app/Contents/MacOS/mpv-bundle mv build/mpv.app/Contents/MacOS/mpv build/mpv.app/Contents/MacOS/mpv-bundle ln -s mpv-bundle build/mpv.app/Contents/MacOS/mpv codesign --force --deep -s - build/mpv.app if [ -d "/Applications/mpv.app" ]; then rm -rf /Applications/mpv.app fi test -d build/mpv.app && mv build/mpv.app /Applications || exit 1 git restore "$WORKDIR/mpv/VERSION" rm "$WORKDIR/mpv/VERSION-e" echo "${GREEN}All Done! ffmpeg is located in ${WHITE}$(brew --prefix)/bin/ffmpeg ${GREEN}and mpv is ${WHITE}$(brew --prefix)/bin/mpv ${GREEN}alone with a bundle is ${WHITE}/Applications/mpv.app${NC}"