LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1583|回复: 14

cli-apps.org上淘到的好东西

[复制链接]
发表于 2010-4-22 14:50:52 | 显示全部楼层 |阅读模式
依赖mplayer,imagemagick,一个shell脚本
  1. #!/bin/bash
  2. #####################################################################
  3. #                        Version: 1.5.9
  4. #####################################################################
  5. #
  6. # This script takes screenshots of a movie
  7. # Depends on mplayer and imagemagick
  8. #
  9. # Made by        Starlite        <http://starl1te.wordpress.com/>
  10. #
  11. # This program is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation, either version 3 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23. #
  24. #####################################################################

  25. usage="Type shot -h for help"

  26. _help(){
  27. echo -e "\nusage: shot [options] [file] ... [fileN]\n
  28. Options:
  29.   -t <time> - Set time (in minutes) between screenshots; the number of screenshots is calculated automatically.
  30.   -n <number> - Set a fixed number of screenshots to take.
  31.   -m - Manual mode. Use arrows to FF/rewind. Press [S] to make screenshots. Quit mplayer to continue.
  32.   -r <percent> - Change the size of the output image. Less than 40% is recommended.
  33.   -s - Seed mode. Gives extra video and audio information. Removes spaces from filenames.
  34.   -h - Display this help message\n

  35. If you don't like screenshots run the script again.
  36. This script depends on Mplayer and ImageMagic. Make sure you have them installed.\n
  37. Usage example:
  38. shot -n 25 -r 35% ~/films/film.avi\n"
  39. }

  40. shot(){
  41. # Making screenshots...
  42. for i in `seq 1 $shots_number`;
  43. do
  44.   randomiser=$RANDOM; let "randomiser %= 25"
  45.   hop=`echo $[$shot_time*60*$i+$randomiser]`
  46.   mplayer -ss $hop -noautosub -frames 1 -ao null -vo png "$file_path" &> /dev/null
  47.   mv 00000001.png /tmp/shots/$i.png &> /dev/null
  48.   echo -ne "Taking screenshot #${i} \r"
  49. done
  50.   echo "Taking screenshots...           [OK]"
  51. }

  52. # ====== first step is here! ^_^ ========
  53. # Checking options...
  54. while getopts ":t:n:mr:sh" option
  55.         do
  56.                 case $option in
  57.                 t ) shot_time=$OPTARG; opt=_time;;
  58.                 n ) shots_number=$OPTARG; opt=_num;;
  59.                 m ) opt=_manual;;
  60.                 h ) _help; opt=1; exit 1;;
  61.                 s ) seed=1;;
  62.                 r ) res=$OPTARG;;
  63.                 : ) echo "No argument given"; opt=1; exit 1;;
  64.                 * ) echo "Unknown option"; echo $usage; opt=1; exit 1;;
  65.                 esac
  66.         done

  67. if [ "$res" == "" ]; then res=35%; fi
  68. if [ "$opt" == "" ]; then echo "No options given!"; echo $usage; exit 1; fi
  69. shift $(($OPTIND - 1))
  70. if [ "$1" == "" ]; then echo "No file given!"; echo $usage; exit 1; fi
  71. mkdir /tmp/shots

  72. # Parsing files...
  73. while [ "$1" != "" ]
  74. do
  75.   file_path=$1
  76.   file_name_ext=${file_path##*/}
  77.   file_name=`echo "$file_name_ext" | sed '$s/....$//'`
  78.   randomiser=0
  79.   quality=87
  80.   testpath=`dirname "$file_path" | cut -c1`
  81.         if [ "$testpath" == "." ]||[ "$testpath" != "/" ]; then
  82.         file_path=`pwd`/$file_path
  83.         fi
  84.   path=`pwd`
  85.   cd "$path"
  86. echo -e "==> Processing file $file_name_ext..."

  87. # Getting video info...
  88. tmp="/tmp/shots/info"
  89. inf=`mplayer "$file_path" -identify -frames 1 -ao null -vo null 2>/dev/null | tee $tmp`

  90. length=`cat $tmp | grep LENGTH | sed -e 's/^.*=//' -e 's/[.].*//'`
  91. if [ "$length" == "" ]; then echo "Error! Can't get the length of the movie."; exit 1; fi

  92. # Calculating timing...
  93. if [ "$opt" == "_time" ]; then
  94.         shots_number=`echo $[$length/60/$shot_time]`
  95.         shot
  96. elif [ "$opt" == "_num" ]; then
  97.         shot_time=`echo $[$length/$shots_number/60]`
  98.         shot
  99. elif [ "$opt" == "_manual" ]; then
  100.         cd /tmp/shots
  101.         echo "Press [S] to make screenshots."
  102.         mplayer -ao null -vf screenshot -quiet "$file_path"
  103.         echo "Taking screenshots...           [OK]"
  104. fi

  105. # Merging screenshots...
  106. echo -n "Putting screenshots together..."
  107. cd /tmp/shots/
  108. montage -geometry +2+2 `ls *.png | sort -n` "$file_name".jpg
  109. mogrify -resize $res "$file_name".jpg
  110. echo " [OK]"
  111. echo -n "Getting video info..."
  112. size=`stat -c%s  "$file_path"`
  113. size=`echo $[$size/1024/1024]`
  114. format=`cat $tmp | grep VIDEO: | cut -d " " -f 5`
  115. length=`echo $[$length/60]`

  116. # It's a tricky code here, it adds some info about the movie to the output image.
  117. echo -e "File name: $file_name_ext\nSize: $size Mb\nResolution: $format\nDuration: $length min." | convert -pointsize 16 -trim +repage text:- text.jpg
  118. convert "$file_name".jpg -quality $quality -splice 0x80 -draw 'image over 5,5 0,0 text.jpg' "$path/$file_name".jpg
  119. echo "           [OK]"
  120. cd "$path"
  121. # Extra info
  122.     if [ "$seed" == "1" ]; then
  123.         #====Video====
  124.         width=`cat $tmp | grep VIDEO_WIDTH | sed -e 's/^.*=//'`
  125.         height=`cat $tmp | grep VIDEO_HEIGHT | sed -e 's/^.*=//'`
  126.         format=`cat $tmp | grep VIDEO_FORMAT | sed -e 's/^.*=//'`
  127.         vcodec=`cat $tmp | grep VIDEO_CODEC | sed -e 's/^.*=//'`
  128.         video="Format:  $format\nCodec:  $vcodec"
  129.         size="Size:  $width*$height"
  130.         #====Audio====
  131.         rate=`cat $tmp | grep AUDIO_RATE | sed -e 's/^.*=//' | tail -n 1`
  132.         acodec=`cat $tmp | grep afm: | sed -e 's/^.*: //'`
  133.         lang1=`cat $tmp | grep ID_AID_0_LANG | sed -e 's/^.*=//'`
  134.         lang2=`cat $tmp | grep ID_AID_1_LANG | sed -e 's/^.*=//'`
  135.         audio="Audio:  $rate $acodec"
  136.         lang="Dub:  1: $lang1  2: $lang2"
  137.         echo -e "\n$video\n$size\n$audio\n$lang"
  138.         #filenames trimming
  139.         file_name_sp=`echo "$file_name" | sed 's/ /_/g'`
  140.         mv "$file_name".jpg "$file_name_sp".jpg &> /dev/null
  141.     fi
  142. rm /tmp/shots/*
  143. echo
  144. shift
  145. done

  146. rm -r /tmp/shots
  147. echo "Done"
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
发表于 2010-4-22 15:12:59 | 显示全部楼层
what?
!
回复 支持 反对

使用道具 举报

发表于 2010-4-22 15:30:48 | 显示全部楼层
推荐vcs~
回复 支持 反对

使用道具 举报

发表于 2010-4-22 15:43:00 | 显示全部楼层
分段预览? !
回复 支持 反对

使用道具 举报

发表于 2010-4-22 16:08:35 | 显示全部楼层
用来做 AV 预览么……
回复 支持 反对

使用道具 举报

发表于 2010-4-22 18:07:32 | 显示全部楼层
Post by jjj137;2084906
用来做 AV 预览么……


You got it.

话说,有没有能将某段视频截取为gif的脚本?
回复 支持 反对

使用道具 举报

发表于 2010-4-22 20:31:26 | 显示全部楼层
Post by dickeny;2084935
You got it.

话说,有没有能将某段视频截取为gif的脚本?


可以分拆为许多单个图片,然后用 convert 转换一下,不过不要期待效果太好,文件体积也可能比较可怕……
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-4-22 20:39:20 | 显示全部楼层
Post by jjj137;2084906
用来做 AV 预览么……


同道中人啊:%
回复 支持 反对

使用道具 举报

发表于 2010-4-24 04:10:22 | 显示全部楼层
这个果然nb
回复 支持 反对

使用道具 举报

发表于 2010-4-26 09:20:16 | 显示全部楼层
今天发布视频种子。刚好用上这脚本。

折腾了大半天,总算把字幕给截图进去了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表