Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Linux LOL
- # ./yt.sh -y http://www.youtube.com/watch?v=V5bYDhZBFLA 00:17 10 5 160:120
- function youtube_to_gif {
- if [[ "$1" == "" ]]; then echo "video url required"; exit 0; fi
- url=$1
- start=${2:-0}
- duration=${3:-15}
- framestep=${4:-5}
- scale=${5:-320:240}
- youtube-dl $url
- video=$(ls ${url##*=}* |grep -v gif| tail -n1)
- gif=${6:-${video%.*}.gif}
- r=${7:-}
- video_to_gif $video $start $duration $framestep $scale $gif $r
- }
- function video_to_gif {
- if [[ "$1" == "" ]]; then echo "video file required"; exit 0; fi
- video=$1
- start=${2:-0}
- duration=${3:-15}
- framestep=${4:-5}
- scale=",scale="${5:-320:240}
- gif=${6:-${video%.*}.gif}
- echo mplayer $video -ss $start -endpos $duration -vo png:outdir=temp_$video -vf framestep=${framestep}$scale -nosound
- mplayer $video -ss $start -endpos $duration -vo png:outdir=temp_$video -vf framestep=${framestep}$scale -nosound
- cd temp_$video
- if [[ "$7" != "" ]]; then
- lastfile=$(ls -rtv | head -n1)
- count=${lastfile##*0}
- i=${count%%.png}
- for f in $(ls -rtv); do
- let i++
- fc=${f%%.png}; j=$((10#$fc)); k=$((j+1)); z=${fc/$j/}
- cp $f $z$i.png
- done
- fi
- echo "creating gif"
- convert $(ls -tv) $gif
- mv $gif ..
- cd ..
- rm -r temp_$video
- eog $gif
- }
- function youtube_to_mp3 {
- if [[ "$1" == "" ]]; then echo "video url required"; exit 0; fi
- youtube-dl -b -t $1
- player -dumpaudio $1 -dumpfile ${1%.*}.mp3
- }
- function youtube_to_mp3_batch {
- youtube-dl -b -t -a videos.txt
- for f in *.flv,*.mp4; do mplayer -dumpaudio $f -dumpfile ${f/%${f##*.}}; done
- }
- function video_to_mp3 {
- if [[ "$1" == "" ]]; then echo "video file required"; exit 0; fi
- player -dumpaudio $1 -dumpfile ${1%.*}.mp3
- }
- function help {
- echo "read the source"
- }
- select=$1
- shift
- case $select in
- --youtube_to_gif|-y) youtube_to_gif $@;;
- --video_to_gif|-v) video_to_gif $@;;
- --youtube_to_mp3|-t) video_to_gif $@;;
- --video_to_mp3|-m) video_to_gif $@;;
- --help|-h|*) help help;;
- esac
- #oneliner
- #url=http://www.youtube.com/watch?v=V5bYDhZBFLA; youtube-dl -b $url; mplayer $(ls ${url##*=}*| tail -n1) -ss 00:57 -endpos 10 -vo gif89a:fps=5:output=output.gif -vf scale=400:300 -nosound
- #mplayer f4vRdgdj75I.mp4 -ss 0:45 -endpos 6 -vo png:outdir=animated4 -vf framestep=5 -nosound
- #convert *.png out.gif
- #url=http://www.youtube.com/watch?v=V5bYDhZBFLA; youtube-dl -b $url; video=$(ls ${url##*=}*| tail -n1); mplayer $video -ss 00:57 -endpos 5 -vo png:outdir=animated_$video -vf scale=400:300,framestep=5 -nosound; cd animated_$video; convert *.png $video.gif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement