VideoHelp Forum
+ Reply to Thread
Results 1 to 4 of 4
Thread
  1. Member
    Join Date
    Jun 2005
    Location
    Portugal
    Search Comp PM
    Hi,

    I think everyone knows Subtitle Workshop, if not, well there is a lot of subtitles tools around

    Well, I made a DOT.NET APP mostly for my personal use, that accomplish AVI->DVD conversion, MPG-1 -> DVD, MPG-2 -> DVD, and burning itself a DVD movie at final stage. Works plenty well

    I want to join subtitles and recalculate time values, but this is a little hard because subtitles files are TEXT FILES, nothing indexed for direct reading, and I must read each line, etc...

    Where can I get a Subtitles algorithm mainly for joining. Or does someone hava an idea how to do this easily ?
    Quote Quote  
  2. Member
    Join Date
    Jun 2005
    Location
    Portugal
    Search Comp PM
    never mind

    I made my one code

    usage:

    (legendas=subtitles)
    SubFiles is a string array with subtitles full path, like :

    SubFiles(0)="c:\dvd\subtitle1.srt"
    SubFiles(2)="c:\dvd\subtitle2.srt"

    Dim legendas As New SubsClass(SubFiles, WorkingPath, Me)
    legendas.Join()



    =====================
    Imports System.Runtime.InteropServices
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports System.IO
    Imports Microsoft.Win32
    Imports System.Diagnostics
    Imports System.ComponentModel


    Public Class SubsClass
    Private formObj As Form1
    Private Structure legenda
    Dim old_text As String()
    Dim new_text As String()
    Dim old_timings() As String
    Dim new_timings() As String
    End Structure

    Private SubFiles(20) As legenda
    Private Files() As String
    Private WorkingPath As String


    Public Sub Join()
    Dim i, j As Integer
    Dim startTime(3) As Integer
    Dim endTime(3) As Integer
    Dim tempos() As String
    Dim ultimoTempo As TimeSpan

    '
    Dim inicio As TimeSpan
    Dim fim As TimeSpan
    Dim oldTiming As String
    Dim newTiming As String

    'hours + minutes + seconds + milliseconds

    '00:00:00,030 --> 00:00:20,470

    '
    'tempos(0) - início
    'tempos(1) - fim
    '
    i = UBound(SubFiles(0).old_timings)
    tempos = Strings.Split(SubFiles(0).old_timings(i), "-->")
    tempos(0) = Trim(tempos(0))
    tempos(1) = Trim(tempos(1))

    endTime(0) = CInt(Strings.Split(tempos(1), ":")(0))
    endTime(1) = CInt(Strings.Split(tempos(1), ":")(1))
    endTime(2) = CInt(Strings.Left(Strings.Split(tempos(1), ":")(2), 2))
    endTime(3) = CInt(Strings.Right(Strings.Split(tempos(1), ":")(2), 3))

    ultimoTempo = New TimeSpan(0, endTime(0), endTime(1), endTime(2), endTime(3))

    For i = 0 To UBound(SubFiles(1).old_timings)
    tempos = Strings.Split(SubFiles(1).old_timings(i), "-->")
    tempos(0) = Trim(tempos(0))
    tempos(1) = Trim(tempos(1))

    startTime(0) = CInt(Strings.Split(tempos(0), ":")(0))
    startTime(1) = CInt(Strings.Split(tempos(0), ":")(1))
    startTime(2) = CInt(Strings.Left(Strings.Split(tempos(0), ":")(2), 2))
    startTime(3) = CInt(Strings.Right(Strings.Split(tempos(0), ":")(2), 3))

    endTime(0) = CInt(Strings.Split(tempos(1), ":")(0))
    endTime(1) = CInt(Strings.Split(tempos(1), ":")(1))
    endTime(2) = CInt(Strings.Left(Strings.Split(tempos(1), ":")(2), 2))
    endTime(3) = CInt(Strings.Right(Strings.Split(tempos(1), ":")(2), 3))

    inicio = New TimeSpan(0, startTime(0), startTime(1), startTime(2), startTime(3))
    fim = New TimeSpan(0, endTime(0), endTime(1), endTime(2), endTime(3))

    inicio = inicio.Add(ultimoTempo)
    fim = fim.Add(ultimoTempo)

    newTiming = CStr(inicio.Hours) & ":" & CStr(inicio.Minutes) & ":" & CStr(inicio.Seconds) & "," & CStr(inicio.Milliseconds)
    newTiming = newTiming & " --> "
    newTiming = newTiming & CStr(fim.Hours) & ":" & CStr(fim.Minutes) & ":" & CStr(fim.Seconds) & "," & CStr(fim.Milliseconds)

    SubFiles(1).new_timings(i) = newTiming
    Next

    Dim contador As Integer = 0
    For i = 0 To UBound(SubFiles(1).old_text)

    If (InStr(SubFiles(1).old_text(i), "-->") > 0) And (InStr(SubFiles(1).old_text(i), ":") > 0) Then
    SubFiles(1).new_text(i) = SubFiles(1).new_timings(contador)
    contador = contador + 1
    Else
    SubFiles(1).new_text(i) = SubFiles(1).old_text(i)
    End If
    Next

    Dim ultimaLegenda As Integer

    Dim A, B As String
    For i = 0 To UBound(SubFiles(0).old_text)
    If IsNumeric(Trim(SubFiles(0).old_text(i))) Then ultimaLegenda = CInt(Trim(SubFiles(0).old_text(i)))
    A = A + SubFiles(0).old_text(i) & vbCrLf
    Next

    contador = ultimaLegenda + 1

    For i = 0 To UBound(SubFiles(1).new_text)
    If IsNumeric(Trim(SubFiles(1).new_text(i))) Then
    SubFiles(1).new_text(i) = CStr(contador)
    contador = contador + 1
    End If
    B = B + SubFiles(1).new_text(i) & vbCrLf
    Next

    Dim outfile As New StreamWriter(WorkingPath & "legendas.srt", False, System.Text.Encoding.GetEncoding("iso-8859-1"))
    Try
    outfile.Write(A + B)
    Finally
    outfile.Close()
    End Try
    End Sub

    Public Sub loadLegendas()
    Dim sr As StreamReader
    Dim contador, i, j As Integer


    For i = 0 To UBound(Files)
    sr = New StreamReader(Files(i), System.Text.Encoding.GetEncoding("iso-8859-1"))
    SubFiles(i).old_text = Split(sr.ReadToEnd, vbCrLf)
    sr = Nothing

    SubFiles(i).new_text = SubFiles(i).old_text

    contador = 0
    ReDim SubFiles(i).old_timings(5000)
    ReDim SubFiles(i).new_timings(5000)

    For j = 0 To UBound(SubFiles(i).old_text)
    If (InStr(SubFiles(i).old_text(j), "-->") > 0) And (InStr(SubFiles(i).old_text(j), ":") > 0) Then
    SubFiles(i).old_timings(contador) = SubFiles(i).old_text(j)
    SubFiles(i).new_timings(contador) = SubFiles(i).old_text(j)
    contador = contador + 1
    End If
    Next

    ReDim Preserve SubFiles(i).old_timings(contador - 1)
    ReDim Preserve SubFiles(i).new_timings(contador - 1)
    Next
    End Sub

    Public Sub New(ByRef subs() As String, ByVal path As String, ByRef frm As Form1)
    Files = subs
    ReDim SubFiles(UBound(Files))
    WorkingPath = path
    formObj = frm
    loadLegendas()
    End Sub
    End Class
    Quote Quote  
  3. Member
    Join Date
    Nov 2006
    Location
    United Kingdom
    Search Comp PM
    Hi Delta2,

    I am playing around with a few video capture cards which encode to MPEG2.

    One of my requirements is to also extract/capture the subtitle data.

    WHat I have found is that the capture cards seem to output the subtitles as bitmaps and not as strings - have you come across this?

    I would be eternally greatfull if you could shed some light on how I can extract the subtitles as string.

    Many thanks,

    KS
    Quote Quote  
  4. If the subs are bitmaps, there is no other way but OCR to get strings. Or use the bitmaps directly if the 'target' is a DVD. On DVDs the subs are bitmaps encoded in a 2Bit RLE format.

    If the subs are part of a DVB straem, these could be found as strings in the teletext. If that's the case, one of the best programs to look at is projectx.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!