LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-16-2012, 01:18 AM   #1
OutsiderFilms
LQ Newbie
 
Registered: May 2012
Posts: 10

Rep: Reputation: Disabled
Question Plain text subtitle converter script


Hello All,

I have a subtitle file (a plain text file) that contain lines like this:

---------------------------------------------
Start subtitles

00:01:25:05 00:01:28:07
Any stuff that does not sell at all?

00:01:30:24 00:01:32:15
Here is one!
You got it?

00:01:34:05 00:01:37:06
Of course I have!
Why shouldn't I bring this?

and so forth

---------------------------------------------

It needs to be converted to a text file like this:

---------------------------------------------
Start subtitles

1
00:01:25,166 --> 00:01:28,233
Any stuff that does not sell at all?

2
00:01:30,800 --> 00:01:32,500
Here is one!
You got it?

3
00:01:34,166 --> 00:01:37,200
Of course I have!
Why shouldn't I bring this?

and so forth

---------------------------------------------

Details:

The original file has the following format:

LINEBREAK
n1:n2:n3:n4 m1:m2:m3:m4LINEBREAK
textLINEBREAK,
text (OPTIONAL, some subtitles might have only one line of text)
LINEBREAK

The converted file should have the following format. The last number in the timecode m4=n4*33.33, rounded to the nearest integer, could be either rounded up or down:

SUBTITLENUMBER
n1:n2:n3,ROUND(n4*33.33) --> m1:m2:m3,ROUND(m4*33.33)
textLINEBREAK
textIF THERE'S A SECOND LINE OF TEXT
LINEBREAK

----------------------------------------------

I guess, the algorithm would be:

1 open original file
2 create a new file
3 initiate a line number counter at 1
4 write the line number value to the new file
5 write a linebreak
6 read the chunk of timecode till you hit SPACE (gives n1:n2:n3:n4)
7 perform the calculation ROUND(n4*33.33)
8 write the new timecode chunk n1:n2:n3,ROUND(n4*33.33) to file
9 write"SPACE-->SPACE"
10 read the next chunk of timecode till hit LINEBREAK (gives m1:m2:m3:m4)
11 perform the calculation in line 7
12 write the new timecode chunk m1:m2:m3,ROUND(m4*33.33) to file
13 write a linebreak
14 read the text till you reach a linebreak
15 copy it to the new file
16 repeat


I suppose it could also do it this way:

1) Check if the first character on the line is a number. If it is, then, in the new file,
write the line number
insert a linebreak
do the calculation and write the result
insert a linebreak
2) If the first characted on the line is text
just copy the text and linebreaks as is

NOTES:

1 The text lines might contain all sorts of characters and punctuation like ,.:!?()[]/"' and so forth or even accented characters

2 The text lines will NEVER begin with a number and ALWAYS end with a linebreak

3 The timecode lines ALWAYS begin with a number and ALWAYS end with a linebreak

Thanks for reading all this!

The source text file is generated by an editing application (Avid Media Composer).
The output is a subrip format text file, used by Youtube.
The finished script would be the first open source "Avid DS to Subrip convertor script". None exist (for Linux) right now, as far as I know.

I'll share copies around and will be happy to call it the "LQ Avid to Youtube Subtitle Script" !

Cheers,

Amit
 
Old 11-16-2012, 03:13 AM   #2
OutsiderFilms
LQ Newbie
 
Registered: May 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Hello All,

I've managed to find a program that already does what I wanted (Subtitle Editor)
home.gna.org/subtitleeditor/

I had ignored this program earlier because it did not list Avid DS as a supported filetype. Some rooting around let to the discovery that the "plain text" mode can be used instead.

Thanks for everyone who tried (or is still trying) to work out the code.

I'm downloading a tutorial on perl... Hopefully, will manage to solve problems such as these myself!

Cheers,

Amit
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
The best way to convert from text/x-c++ iso-8859-1 to text/plain utf8. rm_-rf_windows Linux - General 1 10-03-2012 04:08 AM
LXer: Plain English Calculator/Unit Converter Released LXer Syndicated Linux News 0 04-24-2010 03:10 PM
LXer: Audio / Video / Image / Text / ISO Converter Nautilus Script LXer Syndicated Linux News 0 06-14-2009 06:42 AM
Script need to choose plain text documents ChartmanSg Linux - General 8 12-04-2008 10:44 AM
Subtitle maker and video converter bsdpowa Linux - Software 2 07-21-2005 11:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration