Respond to this messageReturn to Index
Original Message
  • 27 second delay?! I would think your subs would be set up for that!
    • a (no login)
      Posted May 27, 2012 7:33 AM

      You could also just use VLC's built-in sub delay feature... You can find it in the advanced preferences under Input / Codecs => Demuxers => Subtitles. You can also run the movie from the command line:
      vlc --sub-delay <integer> <filename>

      I'm fairly certain the integer specifying the delay is the number of milliseconds (multiply the number of seconds by 1000) because if it was the number of seconds, the subtitles might seem slightly off.

      In any case, here's a program to do it. I designed it to run from the command line because typing a long SRT file name is far too prone to error and renaming isn't always an option when you just want to play the movie. Therefore, this program should be run compiled rather than interpreted. This also assumes a well-formed SRT file that follows the format

      <number>
      <sub startTime> --> <sub endTime>
      <text> (one or more lines)
      <empty line>

      so no error checking is done in that regard. Here's the program that is completely untested and not spell-checked:

      TYPE srtTime
      hrs AS INTEGER
      mins AS INTEGER
      secs AS INTEGER
      msecs AS INTEGER
      END TYPE

      DIM amount AS srtTime, amountString$
      DIM fnames$
      DIM fi AS INTEGER, fo AS INTEGER
      DIM fromVal AS srtTime, toVal AS srtTime
      DIM i AS LONG
      DIM x$

      IF LEN(COMMAND$) < 2 THEN
      PRINT "usage: srtdelay.exe millisec_delay FILE..."
      PRINT
      PRINT "Examples:"
      PRINT
      PRINT " 20 second delay for all files listed:"
      PRINT " srtdelay.exe 20000 file1.srt file2.srt file3.srt"
      PRINT
      PRINT " 500 millisecond delay for the files listed:"
      PRINT " srtdelay.exe 500 file1.srt file2.srt file3.srt"
      PRINT
      END
      END IF

      amountString$ = LEFT$(COMMAND$, INSTR(COMMAND$, " ") - 1)
      fnames$ = MID$(COMMAND$, 1 + INSTR(COMMAND$, " "))

      amount.hrs = FIX(VAL(amountString$) / 3600000)
      amount.mins = FIX(VAL(amountString$) / 60000) MOD 60
      amount.secs = FIX(VAL(amountString$) / 1000) MOD 60
      amount.msecs = VAL(amountString$) MOD 1000

      WHILE LEN(fnames$) > 0
      i = INSTR(fnames$, " ") - 1
      IF i = -1 THEN i = LEN(fnames$)

      ON ERROR GOTO openerr

      'Make a backup
      fi = FREEFILE
      fo = FREEFILE
      OPEN LEFT$(fnames$, i) FOR INPUT AS #fi
      OPEN LEFT$(fnames$, i) + ".BAK" FOR OUTPUT AS #fo
      LINE INPUT #fi, x$
      PRINT #fo, x$
      CLOSE #fo
      CLOSE #fi

      'Open the backup and actually do what we should
      fo = FREEFILE
      fi = FREEFILE
      OPEN LEFT$(fnames$, i) FOR OUTPUT AS #fo
      OPEN LEFT$(fnames$, i) + ".BAK" FOR INPUT AS #fi
      WHILE NOT EOF(#fi)
      LINE INPUT #fi, x$
      PRINT #fo, x$
      LINE INPUT #fi, x$
      fromVal.msecs = amount.msecs + VAL(MID$(x$, 10, 3))
      fromVal.secs = amount.secs + VAL(MID$(x$, 7, 2)) - (fromVal.msecs > 1000)
      fromVal.mins = amount.mins + VAL(MID$(x$, 4, 2)) - (fromVal.secs > 60)
      fromVal.hrs = amount.hrs + VAL(MID$(x$, 1, 2)) - (fromVal.mins > 60)
      fromVal.msecs = fromVal.msecs MOD 1000
      fromVal.secs = fromVal.secs MOD 60
      fromVal.mins = fromVal.mins MOD 60
      toVal.msecs = amount.msecs + VAL(MID$(x$, 27, 3))
      toVal.secs = amount.secs + VAL(MID$(x$, 24, 2)) - (toVal.msecs > 1000)
      toVal.mins = amount.mins + VAL(MID$(x$, 21, 2)) - (toVal.secs > 60)
      toVal.hrs = amount.hrs + VAL(MID$(x$, 18, 2)) - (toVal.mins > 60)
      toVal.msecs = toVal.msecs MOD 1000
      toVal.secs = toVal.secs MOD 60
      toVal.mins = toVal.mins MOD 60
      x$ = LTRIM$(RTRIM$(STR$(FIX(fromVal.hrs / 10))))
      x$ = x$ + LTRIM$(RTRIM$(STR$(fromVal.hrs MOD 10))) + ":"
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(fromVal.mins / 10))))
      x$ = x$ + LTRIM$(RTRIM$(STR$(fromVal.mins MOD 10))) + ":"
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(fromVal.secs / 10))))
      x$ = x$ + LTRIM$(RTRIM$(STR$(fromVal.secs MOD 10))) + ","
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(fromVal.msecs / 100)))
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(fromVal.msecs / 10) MOD 10)))
      x$ = x$ + LTRIM$(RTRIM$(STR$(fromVal.msecs MOD 10))) + " --> "
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(toVal.hrs / 10))))
      x$ = x$ + LTRIM$(RTRIM$(STR$(toVal.hrs MOD 10))) + ":"
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(toVal.mins / 10))))
      x$ = x$ + LTRIM$(RTRIM$(STR$(toVal.mins MOD 10))) + ":"
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(toVal.secs / 10))))
      x$ = x$ + LTRIM$(RTRIM$(STR$(toVal.secs MOD 10))) + ","
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(toVal.msecs / 100)))
      x$ = x$ + LTRIM$(RTRIM$(STR$(FIX(toVal.msecs / 10) MOD 10)))
      x$ = x$ + LTRIM$(RTRIM$(STR$(toVal.msecs MOD 10)))
      PRINT #fo, x$
      WHILE NOT EOF(#fi) AND LEN(x$) > 0
      LINE INPUT #fi, x$
      PRINT #fo, x$
      WEND
      WEND 'NOT EOF(#fi)
      CLOSE #fi
      CLOSE #fo

      opennext:
      IF i <> LEN(fnames$) THEN fnames$ = MID$(fnames$, 2 + i) ELSE fnames$ = ""
      WEND 'LEN(fnames$) > 0)
      END

      openerr:
      PRINT "Failed to open file "; LEFT$(fnames$, i); " for input"
      GOTO opennext
    Your Name
    Your Email
    (Optional)
    Message Title
    Message Text
    Options Also send responses to my email address