Skip to content

Instantly share code, notes, and snippets.

@Sega-Zero
Created January 8, 2016 21:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Sega-Zero/eb05094c1e7f84d2cfdf to your computer and use it in GitHub Desktop.
Save Sega-Zero/eb05094c1e7f84d2cfdf to your computer and use it in GitHub Desktop.
Script copies ffmpeg binaries that are built with brew into a specified folder and makes those binaries to be able to run from the app bundle. More info on http://sega-zero.tumblr.com/post/136899723544/ffmpeg-dylibs
#install ffmpeg if it is not installed
(brew list -1 | grep "ffmpeg" >/dev/null) || brew install ffmpeg
#update your ffmpeg distribution to the latest version
brew outdated ffmpeg || brew upgrade ffmpeg
#cleanup the destination folder
for file in `ls ffmpeg/*`; do rm -f $file; done;
#determine the last local ffmpeg version
COPY_FROM_PATH=""
for ffmpeg_path in `brew info ffmpeg | grep 'Cellar/ffmpeg/.*\*' | awk -F' ' '{ print $1 }'`; do COPY_FROM_PATH="$(echo $ffmpeg_path)"; done;
#copy all the binaries
for source in `find $COPY_FROM_PATH/bin -type f`; do cp -v -f $source ./ffmpeg; done;
#I need ffprobe and ffmpeg only, so I remove ffserver here. If you need it - comment this line
cd ffmpeg && rm -f ffserver && cd ..
#replace references to an absolute path with @executable_path
#which will allow to run ffmpeg that loads dylibs from the bundle
function replace_dlybs() {
DYLIBS=`otool -L $1 | grep "/usr/local/Cellar" | awk -F' ' '{print \$1 }'`
for dylib in $DYLIBS; do sudo install_name_tool -change $dylib @executable_path/`basename $dylib` $1; done;
for dylib in $DYLIBS; do cp -f -n $dylib ./ffmpeg; done;
DYLIBS=`otool -L $1 | grep "/usr/local/opt" | awk -F' ' '{print \$1 }'`
for dylib in $DYLIBS; do sudo install_name_tool -change $dylib @executable_path/`basename $dylib` $1; done;
for dylib in $DYLIBS; do cp -f -n $dylib ./ffmpeg; done;
sudo install_name_tool -id @executable_path/`basename $dylib` $1
}
#first replace occurences in ffmpeg and ffprobe binaries
for file in `ls ffmpeg/*`; do
echo replacing dylibs for $file
replace_dlybs $file
done;
#then replace occurrences in all the additional dylibs that were copied in the previous step
for file in `ls ffmpeg/*.dylib`; do
echo replacing dylibs for $file
replace_dlybs $file
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment