Skip to content

Commit c700436

Browse files
committed
Consolidate ffmpeg install code, fix install prompt,
install manpages when built, use sudo only when needed, workaround ffmpeg version build due to .git dir, use local rather than system installation directories if they exist
1 parent 0d114a0 commit c700436

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ Options:
260260
--latest Build latest version of dependencies if newer available
261261
-c, --cleanup Remove all working dirs
262262
--full-static Complete static build of ffmpeg (eg. glibc, pthreads etc...) **only Linux**
263+
--small Prioritize small size over speed and usability; don't build manpages.
263264
Note: Because of the NSS (Name Service Switch), glibc does not recommend static links.
264265
```
265266

build-ffmpeg

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,12 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
926926
EXTRA_VERSION="${FFMPEG_VERSION}"
927927
fi
928928

929+
if [ -d "$CWD/.git" ]; then
930+
echo -e "\nTemporarily moving .git dir to .git.bak to workaround ffmpeg build bug" #causing ffmpeg version number to be wrong
931+
mv "$CWD/.git" "$CWD/.git.bak"
932+
# if build fails below, .git will remain in the wrong place...
933+
fi
934+
929935
build "ffmpeg" "$FFMPEG_VERSION"
930936
download "https://github.com/FFmpeg/FFmpeg/archive/refs/heads/release/$FFMPEG_VERSION.tar.gz" "FFmpeg-release-$FFMPEG_VERSION.tar.gz"
931937
# shellcheck disable=SC2086
@@ -947,9 +953,19 @@ download "https://github.com/FFmpeg/FFmpeg/archive/refs/heads/release/$FFMPEG_VE
947953
execute make -j $MJOBS
948954
execute make install
949955

950-
INSTALL_FOLDER="/usr/bin"
956+
if [ -d "$CWD/.git.bak" ]; then
957+
mv "$CWD/.git.bak" "$CWD/.git"
958+
fi
959+
960+
INSTALL_FOLDER="/usr" # not recommended, overwrites system ffmpeg package
951961
if [[ "$OSTYPE" == "darwin"* ]]; then
952-
INSTALL_FOLDER="/usr/local/bin"
962+
INSTALL_FOLDER="/usr/local"
963+
else
964+
if [ -d "$HOME/.local" ]; then # systemd-standard user path
965+
INSTALL_FOLDER="$HOME/.local"
966+
elif [ -d "/usr/local" ]; then
967+
INSTALL_FOLDER="/usr/local"
968+
fi
953969
fi
954970

955971
verify_binary_type
@@ -961,34 +977,37 @@ echo "- ffprobe: $WORKSPACE/bin/ffprobe"
961977
echo "- ffplay: $WORKSPACE/bin/ffplay"
962978
echo ""
963979

980+
INSTALL_NOW=0
964981
if [[ "$AUTOINSTALL" == "yes" ]]; then
965-
if command_exists "sudo"; then
966-
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
967-
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
968-
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
969-
echo "Done. FFmpeg is now installed to your system."
970-
else
971-
cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
972-
cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
973-
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
974-
echo "Done. FFmpeg is now installed to your system."
975-
fi
982+
INSTALL_NOW=1
976983
elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
977984
read -r -p "Install these binaries to your $INSTALL_FOLDER folder? Existing binaries will be replaced. [Y/n] " response
978985
case $response in
979-
[yY][eE][sS] | [yY])
980-
if command_exists "sudo"; then
981-
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
982-
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
983-
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
984-
else
985-
cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
986-
cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
987-
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
988-
fi
989-
echo "Done. FFmpeg is now installed to your system."
986+
("" | [yY][eE][sS] | [yY])
987+
INSTALL_NOW=1
990988
;;
991989
esac
992990
fi
993991

992+
if [ "$INSTALL_NOW" = 1 ]; then
993+
if command_exists "sudo" && [[ $INSTALL_FOLDER == /usr* ]]; then
994+
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/bin/ffmpeg"
995+
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/bin/ffprobe"
996+
sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/bin/ffplay"
997+
if [ $MANPAGES = 1 ]; then
998+
sudo mkdir -p "$INSTALL_FOLDER/share/man/man1"
999+
sudo cp "$WORKSPACE/share/man/man1"/ff* "$INSTALL_FOLDER/share/man/man1"
1000+
fi
1001+
else
1002+
cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/bin/ffmpeg"
1003+
cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/bin/ffprobe"
1004+
cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/bin/ffplay"
1005+
if [ $MANPAGES = 1 ]; then
1006+
mkdir -p "$INSTALL_FOLDER/share/man/man1"
1007+
cp "$WORKSPACE/share/man/man1"/ff* "$INSTALL_FOLDER/share/man/man1"
1008+
fi
1009+
fi
1010+
echo "Done. FFmpeg is now installed to your system."
1011+
fi
1012+
9941013
exit 0

0 commit comments

Comments
 (0)