initial commit
This commit is contained in:
commit
76d5925c74
2 changed files with 43 additions and 0 deletions
0
README.md
Normal file
0
README.md
Normal file
43
video2gif.sh
Executable file
43
video2gif.sh
Executable file
|
@ -0,0 +1,43 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#video2gif.sh
|
||||||
|
#PARAMS:
|
||||||
|
# - filename [REQUIRED]
|
||||||
|
# - ffmpeg params [OPTIONAL]
|
||||||
|
|
||||||
|
# BASED on:
|
||||||
|
# https://askubuntu.com/questions/110264/how-to-find-frames-per-second-of-any-video-file
|
||||||
|
# https://stackoverflow.com/questions/32484504/using-random-to-generate-a-random-string-in-bash
|
||||||
|
# https://stackoverflow.com/questions/53566442/ffmpeg-gif-with-transparency-from-png-image-sequence
|
||||||
|
|
||||||
|
filename=$1
|
||||||
|
#keep only the ffmpeg params
|
||||||
|
shift
|
||||||
|
framerate=$(ffmpeg -i $filename 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p") # stolen from: https://askubuntu.com/questions/110264/how-to-find-frames-per-second-of-any-video-file
|
||||||
|
|
||||||
|
if [ -n "$filename" -a -f $filename ] && [ -n "$framerate" ]
|
||||||
|
then
|
||||||
|
|
||||||
|
# temporary directory for garbage generated in the process
|
||||||
|
alphanum="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" #fuсkoff
|
||||||
|
RANDOM=$$
|
||||||
|
tmp_dir=""
|
||||||
|
for i in {1..8} ; do
|
||||||
|
tmp_dir="$tmp_dir${alphanum:RANDOM%${#alphanum}:1}"
|
||||||
|
done
|
||||||
|
mkdir $tmp_dir
|
||||||
|
|
||||||
|
# here we go
|
||||||
|
options=$*
|
||||||
|
# video to frames and maybe some processing
|
||||||
|
ffmpeg -i $filename $options $tmp_dir/out%d.png
|
||||||
|
# generate pallete with transparency support
|
||||||
|
ffmpeg -i $tmp_dir/out%d.png -vf palettegen=reserve_transparent=1 $tmp_dir/palette.png
|
||||||
|
# combine all frames into gif
|
||||||
|
ffmpeg -framerate $framerate -i $tmp_dir/out%d.png -i $tmp_dir/palette.png -lavfi paletteuse=alpha_threshold=128 -gifflags -offsetting "${filename%.*}_out.gif"
|
||||||
|
# i guess that's it
|
||||||
|
rm -rf $tmp_dir
|
||||||
|
else
|
||||||
|
echo "Invalid file"
|
||||||
|
fi
|
||||||
|
# 🍆 i wanna fuck
|
Loading…
Add table
Reference in a new issue