Advertisement
Guest User

subs2srt converter for linux

a guest
Sep 4th, 2012
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.98 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement