Last active
August 29, 2015 14:05
-
-
Save astrataro/78b806ce4be40473f1bb to your computer and use it in GitHub Desktop.
build and update LAVFilters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# determine which ramdisk to use | |
for VOL_NAME in A B X; do | |
VOL_SIZE=$(df 2>nul | grep -i "${VOL_NAME}:" | awk '{print $4}') | |
if [ -n "$VOL_SIZE" ] && [ $VOL_SIZE -ge 921600 ]; then | |
RAMD=/${VOL_NAME}/ | |
break | |
fi | |
done | |
# if no ramdisk, temporarily create one | |
# I use imdisk, which need Administrator privilege and call some hacks to do it | |
if [ "$RAMD" == "" ]; then | |
for VOL_NAME in A B X; do | |
if [ -z "$(df 2>nul | grep -i "${VOL_NAME}:")" ]; then | |
start "D:\\MSYS\\runasMe-call.bat" "D:\\MSYS\\imdisk-attach-1GB.bat $VOL_NAME 930M" | |
until [ -w "/${VOL_NAME}" ]; do | |
sleep 1s | |
done | |
RAMD=/${VOL_NAME}/ | |
TMP_RAMD=1 | |
break | |
fi | |
done | |
fi | |
# update git | |
GIT_UPDATE_LOG="${HOME}/LAVFilters/git-update.log" | |
GIT_UPDATE_ERR="${HOME}/LAVFilters/git-update.err" | |
cd ${HOME}/LAVFilters | |
git pull >$GIT_UPDATE_LOG 2>$GIT_UPDATE_ERR || exit 1 | |
# check if there is update | |
# if none, only --force enables building | |
if [ "$1" != "--force" ] && [ "$(grep 'Already up-to-date.' < $GIT_UPDATE_LOG)" != "" ]; then | |
exit 0 | |
fi | |
# check submodule updated or not | |
for SUB_MODULE in ffmpeg libbluray qsdecoder; do | |
if [ "$(grep " $SUB_MODULE " < $GIT_UPDATE_LOG)" != "" ]; then | |
cd ${HOME}/LAVFilters/${SUB_MODULE} | |
LINE_NUM=`grep -n "From git://git.1f0.de/${SUB_MODULE}" < ${GIT_UPDATE_ERR} | awk -F: '{print $1}'` | |
# if there is a forced update ( e.g. fetched upstream and force rebasing ) | |
if [ "$(awk 'NR=='$LINE_NUM', NR=='$(($LINE_NUM+1))' {print}' ${GIT_UPDATE_ERR} | grep '(forced update)')" != "" ]; then | |
git reset --hard origin/upstream || exit 1 | |
fi | |
git pull || exit 1 | |
fi | |
done | |
cd ${HOME}/LAVFilters | |
rm $GIT_UPDATE_LOG $GIT_UPDATE_ERR | |
cd ${HOME} | |
# copy files to ramdisk | |
# /!\: new ramdisk cannot be automatically mounted if it does not exist before MSYS launched | |
# but we can add all disk partitions in /etc/fstab | |
# a: /a | |
# b: /b | |
# x: /x | |
cp -r ${HOME}/LAVFilters ${RAMD}/LAVFilters || exit 1 | |
# check for git short hash | |
cd ${RAMD}/LAVFilters || exit 1 | |
LAVGit=`git describe --always | cut -f 1 -d g` | |
LAVVer="LAVFilters-`echo $LAVGit | grep - || echo $LAVGit-`git-r`git rev-list HEAD | wc -l`(`git rev-list HEAD -n 1 | cut -c 1-7`)" | |
LAV32=${RAMD}/${LAVVer}/LAVFilters | |
LAV64=${RAMD}/${LAVVer}/LAVFilters-x64 | |
cd ${RAMD}/LAVFilters | |
git stash && git clean -fxd || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0001-Autobuild-with-rtmp-and-rtmpt-enabled.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0002-Add-Git-revision.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0003-Change-priorities-of-output-pixel-format.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0004-Update-moreuuids.h.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0005-Raise-ALAC-priority.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0006-Use-SWS_BICUBIC-instead-of-SWS_BILINEAR-in-swscale.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0007-Enable-setting-YV16-as-output-pixel-format.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0008-Automatically-detect-building-threads.diff || exit 1 | |
# preserved for patch 0009, then apply MPC-HC patches below | |
patch -p1<${HOME}/LAVFpatches/lavf-0010-MPC-HC-LAV-Splitter-Exhibits-MKV-attachments-through.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/lavf-0011-MPC-HC-Tray-icon-Add-an-optional-custom-callback-for.diff || exit 1 | |
find ${RAMD}/LAVFilters -name '*.orig' -exec rm {} \; | |
cp -f ${HOME}/LAVFicons/*.ico ${RAMD}/LAVFilters/resources || exit 1 | |
cd ${RAMD}/LAVFilters/ffmpeg | |
git stash && git clean -fxd || exit 1 | |
patch -p1<${HOME}/LAVFpatches/ffmpeg-lavf-0001-matroskadec_haali-hidden-chapters-if-edition-is-hidden.diff || exit 1 | |
patch -p1<${HOME}/LAVFpatches/ffmpeg-lavf-0002-matroskadec_haali-parse-matroska-tags-to-set-metadat.diff || exit 1 | |
find ${RAMD}/LAVFilters/ffmpeg -name '*.orig' -exec rm {} \; | |
# Build MPC-HC internal filter first | |
# then patch the last one and build normal builds | |
for FOR_MPC in 1 0; do | |
mkdir -p ${LAV32} || exit 1 | |
mkdir -p ${LAV64} || exit 1 | |
cd ${RAMD}/LAVFilters | |
if [ "$FOR_MPC" == "0" ]; then | |
# Another patch for normal build | |
# this patch breaks LAVVideoSettings API, thus crash for MPC-HC or other internal called edition | |
patch -p1<${HOME}/LAVFpatches/lavf-0009-Add-an-option-to-try-DXVA2-native-first-and-fall-bac.diff || exit 1 | |
# Build normal builds / Second Run | |
cmd /c "build2.bat" || exit 1 | |
# Compile an installer for normal build | |
# search for inno setup folder from registry | |
for INNO_REG in "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1" \ | |
"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1"; do | |
INNO_PATH=$(REG QUERY "$INNO_REG" -v 'Inno Setup: App Path' | grep 'Inno Setup: App Path' | cut -c 39- | awk 'gsub(/\\/, "\\\\")') | |
done | |
# my hard-code one | |
if [ -z "$INNO_PATH" ]; then | |
INNO_PATH="/D/Version/Inno Setup" | |
fi | |
"${INNO_PATH}\\ISCC.exe" LAVFilters.iss \ | |
&& mv ${RAMD}/LAVFilters/*.exe ${LAVVer}.exe || exit 1 | |
# collect miscellaneous files for normal build | |
cd ${RAMD}/LAVFilters | |
cp ${HOME}/LAVFreg/* ${LAV32} | |
cp -r ./developer_info ${LAV32} | |
cp ./CHANGELOG.txt ${LAV32} | |
cp ./COPYING ${LAV32} | |
cp ./README.txt ${LAV32} | |
else | |
# Build MPC-HC compliant dlls / First Run | |
cmd /c "build.bat" || exit 1 | |
fi | |
# collect dependencies | |
cd ${RAMD}/LAVFilters | |
cp ./resources/LAVFilters.Dependencies.manifest ${LAV32} | |
cp -r ${LAV32}/* ${LAV64} | |
# collect binaries for Win32 | |
cd ${RAMD}/LAVFilters/bin_Win32 | |
cp *.dll ${LAV32} | |
cp *.ax ${LAV32} | |
# collect binaries for x64 | |
cd ${RAMD}/LAVFilters/bin_x64 | |
cp *.dll ${LAV64} | |
cp *.ax ${LAV64} | |
# make archives | |
cd ${RAMD}/${LAVVer} | |
# I put 7z in /bin.... | |
if [ "$FOR_MPC" == "0" ]; then | |
7z a -m0=BCJ2 -m1=LZMA2:x=9:d=1024m:fb=273 "${HOME}/${LAVVer}.7z" ./LAVFilters ./LAVFilters-x64 && cd ${RAMD} || exit 1 | |
7z a -m0=BCJ2 -m1=LZMA2:x=9:d=1024m:fb=273 "${HOME}/${LAVVer}-Installer.7z" ${RAMD}/LAVFilters/${LAVVer}.exe \ | |
&& rm ${RAMD}/LAVFilters/${LAVVer}.exe || exit 1 | |
else | |
7z a -m0=BCJ2 -m1=LZMA2:x=9:d=1024m:fb=273 "${HOME}/${LAVVer}-for_MPC-HC.7z" ./LAVFilters ./LAVFilters-x64 && cd ${RAMD} || exit 1 | |
fi | |
cd ${HOME} | |
rm -rf ${RAMD}/${LAVVer} | |
done | |
# upload compiled files to FTP | |
cd ${HOME} | |
LFTP=${MSYS}/bin/lftp/lftp | |
FTP_DIR=`grep 'LAVFilters' < ${HOME}/FTP-servers.txt` | |
# move old builds to old folder | |
for FTP_OLD_FILE in $(${LFTP} -c "open ${FTP_DIR}; renlist" | grep ".7z"); do | |
${LFTP} -c "open ${FTP_DIR}; mv ./${FTP_OLD_FILE} ./old/${FTP_OLD_FILE}" | |
done | |
# upload new builds | |
for FTP_NEW_FILE in ${LAVVer}.7z ${LAVVer}-Installer.7z ${LAVVer}-for_MPC-HC.7z; do | |
${LFTP} -c "open ${FTP_DIR}; put -c ./${FTP_NEW_FILE}" | |
done | |
# clean ups | |
rm -rf ${RAMD}/LAVFilters | |
# remove temporary ramdisk | |
if [ "$TMP_RAMD" == "1" ]; then | |
start "D:\\MSYS\\runasMe-call.bat" "D:\\MSYS\\imdisk-detach.bat ${RAMD//\//}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment