Old 02-28-2015, 07:12 PM   #1
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,099
Default Lua Script: Export/Import subtitles SubRip SRT format



Download: Only for REAPER 5 pre-release
HeDa_Import SRT.lua
HeDa_Export SRT.lua
__________________
HeDaScripts for REAPER | VIP Donations

Last edited by heda; 02-28-2015 at 07:19 PM. Reason: added downloads
heda is offline   Reply With Quote
Old 03-01-2015, 03:49 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

During the past few months, I tried to optimize the SRT management in REAPER, using regions. That was pretty nice, but I have to admit that subtitles imported has empty item (which we liked to call text items because they are not empty)... that is the best idea on the subject ever.

Why subtitling with empty item ?
  • You can actually text items, not regions
  • More, you can select multiple text items!
  • You can have several layer (tracks) of text items
  • You can see subtitles on the timeline!
  • Some regions actions where not friendly at all with subtitles
  • You can still have other regions, becaus ethey are just items
  • Heda already made a very nice Note Reader
This is the new era of subtitling in REAPER. And subtitling at all.


Next steps?
I will transpose some scripts I wrote for regions / subtitling to make it work with our new worflow.
On my do to list:
  • Merge consecutive/overlapping similar text items on selected track (if same color -aka if same character speaking)
  • Merge selected text items as dialog lines
  • Create text items on selected track from selected takes (almost finished)
  • Create text items from regions
And of course, writing a new complete tutorial to present this worflow.
I'm feel excited

Heda, you're the man!

Note: If you want to work 0 based, without cursor offset for import/export, you can use use this script:
ReaScript: Move edit cursor to time 0 or to project start
X-Raym is offline   Reply With Quote
Old 03-01-2015, 06:13 AM   #3
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,099
Default

Thank you for your words and for sharing your excitement X-Raym
I hope we can make a video effects processor too, that displays the text from the notes, like Notes Reader does, but integrated in the Video Preview window.

I agree, that using Items is better than Regions. It is easier to edit them, and support multiline.

tip: If you don't want to have the note icon in the item visible, double click an item to edit the note. Or use SWS Notes window, to edit selected item note quickly.

Maybe I can do the HTML formatting for Notes Reader, which is part of the SRT specifications.
Bold – <b> ... </b> or {b} ... {/b}
Italic – <i> ... </i> or {i} ... {/i}
Underline – <u> ... </u> or {u} ... {/u}
Font color – <font color="color name or #code"> ... </font> (as in HTML)
__________________
HeDaScripts for REAPER | VIP Donations
heda is offline   Reply With Quote
Old 03-01-2015, 06:59 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

Quote:
Or use SWS Notes window, to edit selected item note quickly.
This is the better solution for editing several items successively.

HTML formating for note reader would be very nice, indeed!!
X-Raym is offline   Reply With Quote
Old 03-04-2015, 02:58 AM   #5
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

Idea: Optionnal function (or fork) for the export to srt script, with font-color markup based on item color
X-Raym is offline   Reply With Quote
Old 03-04-2015, 03:24 AM   #6
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,099
Default

Quote:
Originally Posted by X-Raym View Post
Idea: Optionnal function (or fork) for the export to srt script, with font-color markup based on item color
Another option would be a separated script that adds the markup to selected text items based on the item colour. Maybe you have more control this way.

Notes Reader for SRT is almost ready
__________________
HeDaScripts for REAPER | VIP Donations
heda is offline   Reply With Quote
Old 03-04-2015, 06:13 AM   #7
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@heda
It could be nice but it will not auto update if item color change.
So, another idea: color text in note reader from item color, without coloring the background.
I personnaly like the export with font color based on background item, as a separate script, :P

Damn, there is so much things to do with these subtitles.
X-Raym is offline   Reply With Quote
Old 03-04-2015, 09:27 AM   #8
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

I am trying the export script on Mac OS and it the writting part doesn't work.
I tried to replace \\ by / in the script, and I tried several path type including file:///Users/username or just /Users/username but it doesn't work.
Code:
/Users/username/Desktop/HeDa_Export SRT.lua:81: cannot open file 'file:///Users/username/sub.srt' (No such file or directory)
As long as we doesn't have a proper write file window, maybe we could use the display output in the console trick, as you suggest me for my export subtitles from regions scripts.
It then would be easy to copy paste the result in an empty file and save it.
--
I was trying to make the font color part of the script, but I dont.
Here is how far I get (but I don't know if it works or no). LINE 99:
Code:
        -- FONT COLOR, by X_RAYM
        color_int = reaper.GetMediaItemInfo_Value(item, "I_CUSTOMCOLOR")
        if color_int > 0 then
            R = color_int & 255
            G = (color_int >> 8) & 255
            B = (color_int >> 16) & 255
            color_hex = string.format("%02x", R) + string.format("%02x", G) + string.format("%02x", B)
            ShowConsoleMsg(color_hex)-- debug
note = "<font-color:#" .. color_hex .. ">" .. note .. "</font-color>"
        end
X-Raym is offline   Reply With Quote
Old 03-04-2015, 11:21 AM   #9
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,099
Default

I don't have a mac so I can't test that.

As for the automatic color from item, sometimes you can have multiple lines at the same time when two people speak at the same time for example. And you have one line in one color and the other line in other color. What do you do then?

The best would be to do each actor (color) in one track.. then a function that merges all items in one track with multiple lines if needed and colored formatting where needed. But that's too much for now
__________________
HeDaScripts for REAPER | VIP Donations
heda is offline   Reply With Quote
Old 03-04-2015, 12:39 PM   #10
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@heda
I tested it on a mac for you, that's how I now it doesnt work. Note: it's not my computer. :P

Totally right for multiple character dialog item.
I can create a fork of my merge text item that handle font color form original items color.
That said we more often used font color for more basic things than representig each different characters. It is more used to represent other sounds for non hearing people.
All of the dialog subtitles are often pure white, for contrast with picture.
That why be your current script to export without color from item background will be the most used
I can create probably create script that add font color from item background for select text items.

Edit: I succee to write a file a mac, with a script modification. I will try to improve it.

Last edited by X-Raym; 03-04-2015 at 01:50 PM.
X-Raym is offline   Reply With Quote
Old 03-04-2015, 02:04 PM   #11
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

I did succeed to write the code on mac!

So, several things can be corrected:
  • scripts broke because of a nil value in 112 (I had empty text items on my track). It would be nice to have a condition such as
    Code:
    if note = nil then note = "" end
  • path exportation is wrong. Line 168 replace by
    Code:
    filenamefull = retvals_csv .. track_label .. ".srt"
    The final of the folder path / or \ can be added by user. It will allow cross platforms support.
  • Default user path could be OS dependant (just like in with my debug functions script in lua). The default user path on mac would be /USERS/username/
AFter that it will be working on windows et mac more nicely, and there shouldn't be any more error with empty text items.

EDIT: I propose you modification via direct editing in github. So you just have to "validate the commit" :P -- I saw a mistake, forget to add 0.3 in changelog, and to put a signature :P

Last edited by X-Raym; 03-04-2015 at 03:17 PM.
X-Raym is offline   Reply With Quote
Old 03-04-2015, 02:24 PM   #12
Samelot
Human being with feelings
 
Join Date: Oct 2013
Posts: 77
Default

Just curious.. Do you guys have careers in video editing / post-production?

These scripts are great and i plan to incorporate them.
Samelot is offline   Reply With Quote
Old 03-04-2015, 06:51 PM   #13
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,099
Default

Quote:
Originally Posted by Samelot View Post
Just curious.. Do you guys have careers in video editing / post-production?

These scripts are great and i plan to incorporate them.
are you hiring?
I do video fx/production/editing for music videos, among other things

I'm happy to hear that you will be using them. A lot of subtitling scripts are coming, right X-Raym?
__________________
HeDaScripts for REAPER | VIP Donations
heda is offline   Reply With Quote
Old 03-05-2015, 04:52 AM   #14
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@heda
Oh yes! The subtitles scripts release night is coming!

Btw, a new fork proposition!
Code:
 * Change log:
 * v0.4 (2015-03-05), by X-Raym
    + contextual os-based separator
    + negative timing fix
    + no item selected => export track all items as SRT, starting from time 0 in the project
 * v0.3 (2015-03-04), by X-Raym
    + default folder based on OS
    + user area
@Samelot
Oh yes, I have a really deep background on video, especially with Premiere Pro, After Effects, Photoshop, Illustrator and DaVinci resolve :P I used the first three since 10 years, and I made my studies in multimedia I also started to learn 3dsMax and Boujou, but I really prefer audio-video than 3D
X-Raym is offline   Reply With Quote
Old 03-05-2015, 10:15 AM   #15
Samelot
Human being with feelings
 
Join Date: Oct 2013
Posts: 77
Default

You sound like quite the expert

I was mostly wondering if you guys were getting paid to subtitle videos online, and that's why you were making these workflows. Haha

I'm skeptical, but I think if you can do it fast enough, some (minor) profits could be made. They're pay rate is low so some form of beating the system would be necessary. That's where Reaper comes in.
Samelot is offline   Reply With Quote
Old 03-07-2015, 08:32 AM   #16
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@Samelot
Thank you a lot
I'm not paid for subtitlting, when I do it, it is more for help things I like or for y personnal work.
But I think that subtitling and translation is very important.

---
Annoucement:
Thanks to Heda, I'm now in charge of the SRT exporter script. And I have lot of new things for you guys!

In one word: Multitracks subtitling is born!

Code:
 * Change log:
 * v0.6 (2015-03-06), by X-Raym
    + Multitrack export support -> every selected track can would be exported
    + Selected items on non selected track will also be exported
    + If no track selected, selected items notes can be exported anyway
    + Better track and item selection restoration
 * v0.5 (2015-03-05), by X-Raym
     # default name is track name - thanks to spk77 for split at comma
     # default folder is project folder
     # if empty fields, back to default values
 * v0.4 (2015-03-05), by X-Raym
    # contextual os-based separator
    + negative first (selected) item pos fix (consider first (selected) item start as time = 0 if cursor pos is after)
    + no item selected => export all items on first selected track as subtitles
    + item selected => export only selected items as subtitles
So, I reorganize the code and rethink the script for several puproses:
  • Multitracks subtitles export
  • Export only selected items of non selected track
So here it is. An actual multitracks/selective SRT exporter !!


I renamed the file with a less generic name, so you can easily distinguish this way to export SRT than any other, which whould be based on custom actions for exemple.


Download here:
My REAPER Scripts / ExtremRaym
Click and download an browse for: Text Items and Item Notes\Subtitles



Cheers
And many thanks Heda for the hard work he put in it! This is the man who made it possible!

Last edited by X-Raym; 03-07-2015 at 09:26 AM.
X-Raym is offline   Reply With Quote
Old 03-07-2015, 08:59 AM   #17
Jason Brian Merrill
Human being with feelings
 
Jason Brian Merrill's Avatar
 
Join Date: Jun 2006
Location: Northeastern PA, USA
Posts: 20,371
Default

I plan on trying to do some subtitling for some jobs as an added value feature.

if this yields some profit, as my videos have in the past, I want to donate. Where would I donate to?
__________________
Beliefs do not require respect. People do.
Jason Brian Merrill is offline   Reply With Quote
Old 03-07-2015, 09:06 AM   #18
Jason Brian Merrill
Human being with feelings
 
Jason Brian Merrill's Avatar
 
Join Date: Jun 2006
Location: Northeastern PA, USA
Posts: 20,371
Default

so is X-raym's version of this the most updated one?

thanks to both of you!
__________________
Beliefs do not require respect. People do.
Jason Brian Merrill is offline   Reply With Quote
Old 03-07-2015, 09:23 AM   #19
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@Jason
This would be very kind of you! Really

This is the new page which gave access to all my scripts.
It leads to my dropbox account, so you will be able to browser folers and downlads scripts (or folders) individually. My GitHub account is now reserved for developpement.
I put a donation button on it. It is pretty raw for the moment, but it works. For donate to Heda, I think he will give you all necessary infos
I will add screenshots and infos later!

Thank you again, Jason

Edit: Exactly. it correspond to v0.6 of the script! It is on my dropbox!
X-Raym is offline   Reply With Quote
Old 03-11-2015, 02:53 PM   #20
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default Sorting table in Lua

OMG!
HEDA!

There is table.sort function in Lua, that allow sorting datas!

Look at this, it is a comparaison between the GetSelectedItem function order and what it does if we use table.sort!




In the actual version of the script exporter, I did a whole thing so that it look for selected items in position order and not in track + position in track order, involving actions in background to put all selected items one one track only

Lua is so cool, really
X-Raym is offline   Reply With Quote
Old 03-13-2015, 08:37 AM   #21
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

I just remembered that I had prepared screenshots of all functionalities of the SRT exporter v0.6 (renammed 1.0, cause it works well :P) !

So, the text of the pop up windows has change, but you will have overview of the capacities:

Offset From Cursor Pos



Track Selection




Item Selection




Mixed Selection (track + item)




Empty Track Detection




No Selection Detection




X-Raym is offline   Reply With Quote
Old 05-01-2015, 09:58 AM   #22
mrlimbic
Human being with feelings
 
mrlimbic's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 408
Default

Item notes are really useful for storing metadata. I use them in Vordio to store an ID for each item which is later used to reconform the sound edit to a new version of the visual edit. I also use them to display useful information to the sound editor such as scene and take.

However, I recently started worrying about conflicts with other tools that use item notes and also not stopping people from writing their own notes.

So in the end, instead of taking over the whole note, I started prefixing lines with a header for each line. Each header I can use to store different metadata.



This way Vordio can ignore all lines that don't contain a header that Vordio uses.

I just mention this because it is an easy way to avoid conflicting with other people's tools.
__________________
Mac OS X 10.11.x, Motu Ultralite, Reaper, FCP X.
http://vordio.net
http://twitter.com/vordio
mrlimbic is offline   Reply With Quote
Old 05-01-2015, 01:19 PM   #23
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@mrlimbic
Thanks for the tip !

In case of a subtitling workflow, no prefix is needed. We use empty items for that: it items without audio and without MIDI, just the text notes.
+, the srt exporter is selective, you can choose what items/tracks to consider or not.
X-Raym is offline   Reply With Quote
Old 05-02-2015, 07:38 AM   #24
mrlimbic
Human being with feelings
 
mrlimbic's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 408
Default

Quote:
Originally Posted by X-Raym View Post
@mrlimbic
Thanks for the tip !

In case of a subtitling workflow, no prefix is needed. We use empty items for that: it items without audio and without MIDI, just the text notes.
+, the srt exporter is selective, you can choose what items/tracks to consider or not.
Yes, you are right that empty items won't affect my tool.

It is just a general worry with so many wonderful scripts people are writing that there may be note conflicts unless we try to come up with some standard for not affecting other scripts/tools.
__________________
Mac OS X 10.11.x, Motu Ultralite, Reaper, FCP X.
http://vordio.net
http://twitter.com/vordio
mrlimbic is offline   Reply With Quote
Old 05-02-2015, 08:55 AM   #25
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@mrlimbic
Other text (empty) items related scripts I know also work with certain tracks. As long as your organize your tracks and items right (grouped tracks for subtitles, grouped tracks for region for heda's regions and marker from item script, etc...), you will have no conflict

It's all about project organization.
X-Raym is offline   Reply With Quote
Old 05-08-2015, 04:19 PM   #26
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default Text Encoding Format

Question: Actual export text encoding format is ANSI, do you think it could be UTF-8 ?
It can be useful for some languages.
X-Raym is offline   Reply With Quote
Old 05-08-2015, 04:45 PM   #27
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,099
Default

mmm no idea... I didn't check that. I always assume on modern OS everything should be UTF-8
here is some information about Lua and UTF-8
http://lua-users.org/wiki/LuaUnicode
__________________
HeDaScripts for REAPER | VIP Donations
heda is offline   Reply With Quote
Old 05-08-2015, 11:06 PM   #28
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@heda
Thanks for your answer.

Well for the moment, SRT exporter is ANSI.
I just read your doc, and some other page... That's quite hard. I didn't find a way to tell that the export file have to be utf-8.
Can you take a look ?
X-Raym is offline   Reply With Quote
Old 05-08-2015, 11:15 PM   #29
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 4,099
Default

Sorry I have a bug to kill this morning
but I annotate this in the txt of things to look at.
__________________
HeDaScripts for REAPER | VIP Donations
heda is offline   Reply With Quote
Old 05-08-2015, 11:36 PM   #30
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

Thanks for the note I wonder what cool things there is in it !

I guess it is something to look with the io libraries. I found this page that gave some infos of why it works with ansi on windows.
http://lua.2524044.n2.nabble.com/Lua...td4285043.html
Maybe some infos for you in it

Meanwhile, good luck for the bug !
X-Raym is offline   Reply With Quote
Old 07-22-2015, 03:20 AM   #31
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

Quote:
Are SubRip SRT kind of standard for subtitles? Asking out of curiosity.
They are !

ANd sure, empty items can be used in a lot of things. I'm still, surprised there is only one native actions for them in REAPER. They are so useful !
X-Raym is offline   Reply With Quote
Old 07-22-2015, 05:03 AM   #32
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

  1. Lyrics (up to Karaoke)
  2. Dialog Line for ADR
  3. Regions (thanks to heda's script (with several set of regions possible)
  4. Infos (for the composer for exemple)
  5. Chords
  6. Placeholder for other items
ETC... :P
X-Raym is offline   Reply With Quote
Old 07-22-2015, 05:27 AM   #33
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 4,039
Default

@TonE
Be aware of two things:
  • The workflow presented in this video was the previous v5 worflow, without text items. Text items are not faster to put in place, but fare more powerful.
  • I am talking about professional subtitling with break lines put at semantic places in the dialog lines (according to group of words, punctuation...); This can only be done manually. Of course there is subtitle editor that make do automatic job for "cleaning purpose" but then you will have to manually fine tune the result.
I use Subtitle Edit for subtitling fine tuning.

An detailed article about the text item workflow will came out when Rv5 will.
X-Raym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:23 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.