θυμήσου με
 
roomap
2010-07-21 17:25
 
#!/bin/bash
#by thimios katsoulis 20190619 -- https://www.facebook.com/thimios.katsoulis 
# a LINUX script to create  gif from video
# uses ffmpeg , convert

if [ $# -lt 3 ]
then
echo "Usage is: `basename $0` <video> <start_time>  <duration> <width> <video_interval> <gif_interval>  "
echo "E.g. :  `basename $0` v.mp4 01:19:13.800 00:00:03.100"
exit 1
fi
echo "--- converting to gif from  $1 ---------"
video=$1
start_time=$2
duration=$3

#optional parameters 
#width
width=${4:-500}
#video_interval
video_interval=${5:-10}
#gif_interval
gif_interval=`expr $video_interval + 10`
gif_interval=${6:-$gif_interval}

printf "Going to make a gif from video: $video \nStart time : $start_time \nDuration:$duration \nSnapshot interval: $video_interval milliseconds\nGif delay: $gif_interval \n" 
read -p "Press enter to continue.." 
fnamevideo=`basename $video`
frames_dir="/tmp/"$fnamevideo"_frames"
mkdir -p $frames_dir
rm -f $frames_dir/*

echo "Cutting video.."
ffmpeg -loglevel panic -i $video -ss "$start_time" -t "$duration" -c copy $frames_dir/$fnamevideo
echo "Extracting images from cutted video.."
ffmpeg -loglevel panic  -i $frames_dir/$fnamevideo -r $video_interval $frames_dir/image-%3d.png
echo "Compressing images.."
pngs=`ls $frames_dir/*png`
pngsLen=`ls $frames_dir/*png|wc -l`
i=0
for im in `ls $frames_dir/*png`
do
i=`expr $i + 1`
echo "$i of $pngsLen" 
convert  $im -resize $width  $im
done
 
echo "Now is the time to delete any unwanted photos in $frames_dir.. "
read -p "When You are ready , Press enter to continue " yn

echo "Making gif : $fnamevideo.gif .."
convert -delay $gif_interval -loop 0 $frames_dir/*.png $fnamevideo.gif
echo "Done"