Skip to content

Instantly share code, notes, and snippets.

@Fire7ly
Forked from jaredrummler/youtube-to-bootanimation.sh
Last active November 12, 2023 19:58
Show Gist options
  • Save Fire7ly/8a46d6605dac976e140911cf8a45a090 to your computer and use it in GitHub Desktop.
Save Fire7ly/8a46d6605dac976e140911cf8a45a090 to your computer and use it in GitHub Desktop.
Create an Android bootanimation from a Any link or local video file
#!/bin/bash
#
# youtube-to-bootanimation.sh - Download & create Android boot animations from YouTube videos
#
# author: Jared Rummler <jared@jrummyapps.com>
#
# define veriable where the bootanimation will be created
tmp=~/Desktop/temp
out=~/Desktop/temp/temp.mp4
# Set the frames per second for the boot animation
fps=30
getlink () {
# Replace URL with any YouTube link
#url="https://www.youtube.com/watch?v=Ynm6Vgyzah4"
read -p "Enter Any url Or File Location : " input
link=$(echo $input | cut -f 1 -d ":")
if [[ $link = 'https' ]]; then
echo ""
echo -e "[🌐] : Url Detected..\n"
#overwrite veriable for url
url=$input
download
else
echo "[📁] : Local File Detected.^-^."
#overwrite veriable for direct push input video into ffmpeg
ext=${input##*.}
cd $tmp && cp "$input" $PWD && mv *.$ext tmp.$ext && cd ..
out="$tmp/tmp.$ext"
bootanimation
fi
}
# delete the directory if it currently exists
rm -rf $tmp
# create the directory
mkdir -p $tmp
download () {
# Use youtube-dl to download the video
# https://github.com/rg3/youtube-dl
yt=$(echo $url | cut -f 2 -d ".")
if [[ $yt = 'youtube' ]]; then
echo -e "[🎞️] : youtube link detected using youtube-dl\n"
youtube-dl -o $out $url
else
echo -e "[🔗] : Genral Link detected using aria2\n"
aria2c $url -d $tmp -o temp.mp4
fi
bootanimation
}
bootanimation () {
# Make the directory for the frames to be extracted to
mkdir -p $tmp/part0
# Use ffmpeg to extract frames from the video
# https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide
ffmpeg -i $out $tmp/part0/00%05d.jpg
# Use ImageMagick to get the width and height of the first image
# http://www.imagemagick.org/
size=`identify -format '%w %h' $tmp/part0/0000001.jpg`
# Create the desc.txt file
echo "$size $fps" > $tmp/desc.txt
echo "p 1 0 part0" >> $tmp/desc.txt
# Create the bootanimation
cd $tmp
zip -0r bootanimation part0 desc.txt
# Remove the downloaded video
rm $out
# Remove desc.txt
rm $tmp/desc.txt
# Create a GIF of the bootanimation
# fps = 1/(delay in seconds) = 100/(delay ticks)
delay=`echo "scale=2; 100/${fps}" | bc`
echo "Creating animated GIF..."
convert -delay $delay -loop 0 $tmp/part0/*.jpg -resize 300x -layers optimize $tmp/animation.gif
# Remove the folder with the images
echo "Cleaning up..."
rm -rf $tmp/part0
echo "Finished! Your boot animation is at $tmp/bootanimation.zip"
}
getlink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment