Astroport.ONE/tools/make_video_gifanim_ipfs.sh

57 lines
2.8 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
## Create gifanime ## TODO Search for similarities BEFORE ADD
## "(✜‿‿✜) GIFANIME $PROBETIME (✜‿‿✜)"
# FORMAT MP4 max 720p
# PHI GIFANIM CREATION
path="$1"
file="$2"
length=${#path}
last_char=${path:length-1:1}
[[ $last_char != "/" ]] && path="$path/"; :
[[ ! -s "${path}${file}" ]] && echo "Nothing Found, please check \"${path}${file}\"" && exit 1
MIME=$(file --mime-type -b "${path}${file}")
2023-02-27 13:38:11 +01:00
HOP=0
2023-01-01 23:58:18 +01:00
#################################################################################################################
############# CONVERT NOT MP4
[[ ! $MIME == "video/mp4" ]] \
2023-01-20 15:44:26 +01:00
&& espeak "MP4 CONVERSION PLEASE WAIT" 2>/dev/null \
2023-01-07 20:44:57 +01:00
&& ffmpeg -loglevel error -i "${path}${file}" -c:v libx264 -c:a aac "${path}${file}.mp4" \
2023-02-27 13:38:11 +01:00
&& [[ -s "${path}${file}.mp4" ]] && rm "${path}${file}" && file="${file}.mp4" && extension="mp4" && MIME=$(file --mime-type -b "${path}${file}") && HOP=1
2023-01-01 23:58:18 +01:00
FILE_RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${path}${file}" | cut -d "x" -f 2)
RES=${FILE_RES%?}0p
2023-01-01 23:35:19 +01:00
#################################################################################################################
############# VIDEO LINES MAX IS 720p
LINES=$(echo $RES | tr -dc '0-9')
[ $LINES -gt 720 ] \
2023-01-20 15:44:26 +01:00
&& espeak "VIDEO RESIZING HALF PLEASE WAIT" 2>/dev/null \
2023-01-01 23:35:19 +01:00
&& ffmpeg -loglevel quiet -i "${path}${file}" -vf "scale=iw/2:ih/2" "${path}2${file}" \
&& [[ -s "${path}2${file}" ]] && rm "${path}${file}" && mv "${path}2${file}" "${path}${file}" \
2023-01-14 01:24:09 +01:00
&& FILE_RES=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "${path}${file}" | cut -d "x" -f 2) \
2023-02-27 13:38:11 +01:00
&& RES=${FILE_RES%?}0p && echo $RES && HOP=2
2023-01-01 23:35:19 +01:00
#################################################################################################################
FILE_BSIZE=$(du -b "${path}${file}" | awk '{print $1}')
2023-01-01 19:06:24 +01:00
DURATION=$(ffprobe -v error -i "${path}${file}" -show_entries format=duration -v quiet -of csv="p=0" | cut -d '.' -f 1)
DUREE=$(ffprobe -v error -i "${path}${file}" -show_entries format=duration -sexagesimal -v quiet -of csv="p=0"| cut -d '.' -f 1)
PROBETIME=$(echo "0.618 * $DURATION" | bc -l | cut -d '.' -f 1)
[[ ! $PROBETIME ]] && PROBETIME="1.0"
2023-01-20 15:44:26 +01:00
## How many seconds are encoded by MB ?
VTRATIO=$(echo "$DURATION / $FILE_BSIZE * 1024 * 1024" | bc -l | xargs printf "%.2f")
## CREATE SOME INDEX HOOKS
# ffmpeg -skip_frame nokey -i ${path}${file} -vsync 0 -r 30 -f image2 thumbnails-%02d.jpeg
rm -f ~/.zen/tmp/screen.gif
ffmpeg -loglevel quiet -ss $PROBETIME -t 1.6 -loglevel quiet -i "${path}${file}" ~/.zen/tmp/screen.gif
ANIMH=$(ipfs add -q ~/.zen/tmp/screen.gif)
2023-02-27 13:38:11 +01:00
## -- cross "bash tail -n 1" variable setting in return --- BASH TRICK ;)
echo "export HOP=$HOP ANIMH=$ANIMH PROBETIME=$PROBETIME DURATION=$DURATION DUREE=$DUREE RES=$RES MIME=$MIME VTRATIO=$VTRATIO file=$file"
exit 0