Created
September 24, 2021 04:54
-
-
Save chrisdavidmiles/2bd38ee305c3e2c175d11a0d3a801f9c to your computer and use it in GitHub Desktop.
Windows Movie Maker Shitposting Script
This file contains 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 | |
# | |
# Windows Movie Maker Shitposting Script by @chrisdavidmiles | |
# | |
# This script generates a video of text in the style of 2007 era Windows Movie | |
# Maker youtube tutorials. I'm not really sure why I made this script tbh. | |
# | |
# This script requires ffmpeg and imagemagick to run. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# | |
################################## | |
###### VIDEO SETTINGS START ###### | |
################################## | |
# Full path of .mp3 for video background music | |
wmms_music="/full/path/to/music.mp3" | |
# Length of the video | |
secondsLong="17"; | |
# Video Size | |
width="640" | |
height="480" | |
# Colors | |
# See imagemagick.org/script/color.php | |
background_color="#5282bc" | |
text_color="white" | |
#Font to use | |
#Run "convert -list font" for list of font choices | |
font="Segoe-Script" | |
################################## | |
###### VIDEO SETTINGS END ######## | |
################################## | |
# Usage start | |
wmms_help () { | |
wmms_usage_text="This script generates a video of text in the style of 2007 era Windows Movie Maker youtube tutorials. I'm not really sure why I made this script tbh. | |
Usage: $0 \"Enter your text here\"" | |
echo "$wmms_usage_text"; | |
exit | |
} | |
# Usage end | |
# Error handling start | |
set -e | |
function wmms_error { | |
echo -e "\nThis script has thrown an error." | |
echo "Here's where things went wrong:" | |
echo "$(caller): ${BASH_COMMAND}\n" | |
} | |
trap wmms_error ERR | |
# Error handling end | |
# Pre flight checks start | |
unset wmms_missing_dependencies | |
if [ ! -f "$wmms_music" ] | |
then | |
echo "This script is set to use the .mp3 file located at \"$wmms_music\" as background music but no file was found there. I like using the song \"Trance\" by 009 Sound System for that 2007 era Windows Movie Maker youtube tutorial vibe." | |
exit | |
fi | |
if ! command -v ffmpeg &> /dev/null | |
then | |
wmms_missing_dependencies='ffmpeg' | |
fi | |
if ! command -v convert &> /dev/null | |
then | |
if [ -z "$wmms_missing_dependencies" ] | |
then | |
wmms_missing_dependencies='imagemagick' | |
else | |
wmms_missing_dependencies+=' and imagemagick' | |
fi | |
fi | |
if [ ! -z "$wmms_missing_dependencies" ] | |
then | |
echo "This script requires $wmms_missing_dependencies to run." >&2 | |
if [[ $OSTYPE == 'darwin'* ]] | |
then | |
echo "You can install $wmms_missing_dependencies using https://brew.sh " >&2 | |
else | |
echo "Please install $wmms_missing_dependencies before running this script." >&2 | |
fi | |
exit; | |
fi | |
wmms_tmp="/tmp/wmm-shitpost" | |
if [ ! -d "$wmms_tmp" ] | |
then | |
mkdir -p "$wmms_tmp" || echo "Unable to create the $wmms_tmp directory. Perhaps the /tmp folder on your system is not writable by you?" >&2; | |
fi | |
touch "$wmms_tmp/$$-test" || echo -e "This script was unable to write to $wmms_tmp/\n Perhaps it's not writable by you?" >&2; | |
if [ -z "$1" ] | |
then | |
wmms_help | |
fi | |
# Pre flight checks end | |
# Generate video start | |
if [ $width -gt $height ] | |
then | |
border_size=$((width / 10)) | |
else | |
border_size=$((height / 10)) | |
fi | |
convert_size="$width" | |
convert_size+="x" | |
convert_size+="$height" | |
ffmpeg_mode="-hide_banner -loglevel error" | |
ffmpeg_size="scale=" | |
ffmpeg_size+="$width" | |
ffmpeg_size+=":" | |
ffmpeg_size+="$height" | |
convert -font "$font" -bordercolor "$background_color" -border "$border_size" -background "$background_color" -fill "$text_color" -gravity center -size $convert_size caption:"$1" "$wmms_tmp/$$-image.jpg" | |
ffmpeg $ffmpeg_mode -loop 1 -i "$wmms_tmp/$$-image.jpg" -c:v libx264 -t "$secondsLong" -pix_fmt yuv420p -vf "$ffmpeg_size" "$wmms_tmp/$$-silent.mp4" | |
ffmpeg $ffmpeg_mode -i "$wmms_tmp/$$-silent.mp4" -i $wmms_music -map 0:v -map 1:a -c:v copy -shortest "$wmms_tmp/$$-with-sound.mp4" | |
ffmpeg $ffmpeg_mode -i "$wmms_tmp/$$-with-sound.mp4" -vf "fade=t=in:st=0:d=1.5" -c:a copy "$wmms_tmp/$$.mp4" | |
rm $wmms_tmp/$$-* | |
# Generate video end | |
# Video export start | |
if [[ $OSTYPE == 'darwin'* ]] | |
then | |
# On MacOS open the video. | |
echo "Opening \"$$.mp4\"" | |
open "$wmms_tmp/$$.mp4" | |
else | |
# On other systems, just print the filename. | |
echo "Video exported to \"$wmms_tmp/$$.mp4\"" | |
fi | |
# Video export end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment