Want more features on Pastebin? Sign Up, it's FREE!
Guest

subs2srt converter for linux

By: a guest on Sep 4th, 2012  |  syntax: Bash  |  size: 0.98 KB  |  views: 172  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. # converts subtitles to "srt" format
  4. # uses: mplayer to detect movie framerate
  5. #       subs (from Subtitles perl swiss army knife: http://karasik.eu.org/software/)
  6.  
  7. echo "subs2srt by l0co@wp.pl"
  8.  
  9. if [ ! "$#" = "2" ]; then
  10.   if [ ! "$#" = "1" ]; then
  11.     echo Usage: subs2srt.sh MOVIENAME SUBSNAME
  12.     exit
  13.   fi
  14.   MOVIENAME=$1
  15.   SUBSNAME="${MOVIENAME%.*}.txt"
  16. else
  17.   MOVIENAME=$1
  18.   SUBSNAME=$2
  19. fi
  20.  
  21. SRTNAME="${SUBSNAME%.*}.srt"
  22.  
  23. if [ "$SRTNAME" == "$SUBSNAME" ]; then
  24.   SRTNAME="${SUBSNAME%.*}1.srt"
  25. fi
  26.  
  27. echo "moviename: $MOVIENAME"
  28. echo "subsname: $SUBSNAME"
  29. echo "srtname: $SRTNAME"
  30.  
  31. if [ ! -f $MOVIENAME ]; then
  32.   echo "Movie not found"
  33.   exit
  34. fi
  35. if [ ! -f $SUBSNAME ]; then
  36.   echo "Movie not found"
  37.   exit
  38. fi
  39.  
  40. # detect framerate
  41.  
  42. FRAMERATE=`mplayer -vo null -ao null -identify -frames 0 $MOVIENAME |grep ID_VIDEO_FPS| sed "s/ID_VIDEO_FPS=//"`
  43. echo "framerate: $FRAMERATE"
  44.  
  45. # execute conversion
  46. subs $SUBSNAME -r $FRAMERATE -c srt -o $SRTNAME
clone this paste RAW Paste Data