Advertisement
Guest User

Untitled

a guest
Sep 8th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #!/bin/bash
  2. # Linux LOL
  3. # ./yt.sh -y http://www.youtube.com/watch?v=V5bYDhZBFLA 00:17 10 5 160:120
  4.  
  5. function youtube_to_gif {
  6. if [[ "$1" == "" ]]; then echo "video url required"; exit 0; fi
  7. url=$1
  8. start=${2:-0}
  9. duration=${3:-15}
  10. framestep=${4:-5}
  11. scale=${5:-320:240}
  12. youtube-dl $url
  13. video=$(ls ${url##*=}* |grep -v gif| tail -n1)
  14. gif=${6:-${video%.*}.gif}
  15. r=${7:-}
  16. video_to_gif $video $start $duration $framestep $scale $gif $r
  17. }
  18.  
  19. function video_to_gif {
  20. if [[ "$1" == "" ]]; then echo "video file required"; exit 0; fi
  21. video=$1
  22. start=${2:-0}
  23. duration=${3:-15}
  24. framestep=${4:-5}
  25. scale=",scale="${5:-320:240}
  26. gif=${6:-${video%.*}.gif}
  27. echo mplayer $video -ss $start -endpos $duration -vo png:outdir=temp_$video -vf framestep=${framestep}$scale -nosound
  28. mplayer $video -ss $start -endpos $duration -vo png:outdir=temp_$video -vf framestep=${framestep}$scale -nosound
  29. cd temp_$video
  30. if [[ "$7" != "" ]]; then
  31. lastfile=$(ls -rtv | head -n1)
  32. count=${lastfile##*0}
  33. i=${count%%.png}
  34. for f in $(ls -rtv); do
  35. let i++
  36. fc=${f%%.png}; j=$((10#$fc)); k=$((j+1)); z=${fc/$j/}
  37. cp $f $z$i.png
  38. done
  39. fi
  40. echo "creating gif"
  41. convert $(ls -tv) $gif
  42. mv $gif ..
  43. cd ..
  44. rm -r temp_$video
  45. eog $gif
  46. }
  47.  
  48. function youtube_to_mp3 {
  49. if [[ "$1" == "" ]]; then echo "video url required"; exit 0; fi
  50. youtube-dl -b -t $1
  51. player -dumpaudio $1 -dumpfile ${1%.*}.mp3
  52. }
  53. function youtube_to_mp3_batch {
  54. youtube-dl -b -t -a videos.txt
  55. for f in *.flv,*.mp4; do mplayer -dumpaudio $f -dumpfile ${f/%${f##*.}}; done
  56. }
  57.  
  58. function video_to_mp3 {
  59. if [[ "$1" == "" ]]; then echo "video file required"; exit 0; fi
  60. player -dumpaudio $1 -dumpfile ${1%.*}.mp3
  61. }
  62.  
  63. function help {
  64. echo "read the source"
  65. }
  66.  
  67. select=$1
  68. shift
  69. case $select in
  70. --youtube_to_gif|-y) youtube_to_gif $@;;
  71. --video_to_gif|-v) video_to_gif $@;;
  72. --youtube_to_mp3|-t) video_to_gif $@;;
  73. --video_to_mp3|-m) video_to_gif $@;;
  74. --help|-h|*) help help;;
  75. esac
  76.  
  77. #oneliner
  78. #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
  79.  
  80. #mplayer f4vRdgdj75I.mp4 -ss 0:45 -endpos 6 -vo png:outdir=animated4 -vf framestep=5 -nosound
  81. #convert *.png out.gif
  82.  
  83. #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