Exporting subs to plain text

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline
User avatar

buckenmeyer

  • Posts: 81
  • Joined: Thu Jun 11, 2020 7:52 am
  • Location: Madrid, Spain
  • Real Name: Javier Buckenmeyer

Exporting subs to plain text

PostThu Oct 24, 2024 8:11 am

Hi,

I'm looking for a way to export the text from my subs into plain text. The text should be like normal paragraphs, no line numbers or other info. So i can just copy/paste the text for social media use.

I found a couple suggestions on redit but couldn't get them to work.

Thanks,
Javier
Graphics: Nvidia GeForce GTX 4060 8GB
CPU: I5-13400 @ 2500 Mhz
RAM: 32 GB
OS: Win 11
Offline

DorinDXN

  • Posts: 174
  • Joined: Thu Aug 04, 2022 5:07 pm
  • Real Name: Dorin Godja

Re: Exporting subs to plain text

PostThu Oct 24, 2024 8:44 am

Change the filepath content of this script then copy the script and paste it in

Menu: Workspace \ Console

then hit Enter

Code: Select all
local filePath = "E://Resolve//Forum//Subtitle//subtitle.txt"

local resolve = app:GetResolve()
local projectManager = resolve:GetProjectManager()
local project = projectManager:GetCurrentProject()
local timeline = project:GetCurrentTimeline()

if timeline == nil then
    print("No Active Timeline")
    os.exit()
end

local subtitles = timeline:GetItemListInTrack("subtitle", 1)
local file = io.open(filePath, "w")

for key, value in pairs(subtitles) do
    if key == "__flags" then
        break
    end
    local caption = value:GetName()
    file:write(caption .. "\n")
end

file:close()
print("Subtitles have been saved to " .. filePath)


cheers,
Dorin
DaVinci Resolve Anthem
https://www.youtube.com/watch?v=CcKC8R9ku50
DaVinci Resolve Clips
https://www.youtube.com/playlist?list=PLYgg-7sUX2Jh3dqNJ0AVBTIlDFtufrYyn
Playhead Lock Script
https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=210163
Offline
User avatar

buckenmeyer

  • Posts: 81
  • Joined: Thu Jun 11, 2020 7:52 am
  • Location: Madrid, Spain
  • Real Name: Javier Buckenmeyer

Re: Exporting subs to plain text

PostThu Oct 24, 2024 8:53 am

Hi,

It worked! Can we add a command to combine whole sentences so it doesn't print like this:

¿Cómo saber
cuando te estás
comprando un
zapato de
flamenca si te
queda bien?
El zapato de que
te compres de
baile flamenco
tiene que ser de
piel o de ante,
siempre para que
se ajuste bien a
tu pie
cuando bailes.
Cuando te hayas
probado el
zapato,
ponte de pie.
7 tips para
comprar
zapatos de
flamenca
cuando te pones
de pie y ejerce
expresión sobre
el zapato.
El zapato no
puede apretar ni
por la zona del
dedo gordo ni por
la zona del dedo
meñique.
Esta parte
delantera del
zapato debe
adaptarse
a tu pie.
Flexione a tu pie
y mira que el
talón no
se salga.
Camina pequeños
pasos cortos para
observar que el
zapato te
queda cómodo.
Observa que donde
apoyas el
metataso en el
zapato amortiguá
para que el pie a
la hora de
zapatear
no sufra tanto y
tu metataso
amortigüe
los golpes.
Y recuerda, a la
hora de comprar
un zapato de
flamenco, la
calidad es muy
importante.
Tus pies te van a
durar toda la
vida y tienes que
cuidarlos.
Graphics: Nvidia GeForce GTX 4060 8GB
CPU: I5-13400 @ 2500 Mhz
RAM: 32 GB
OS: Win 11
Offline

DorinDXN

  • Posts: 174
  • Joined: Thu Aug 04, 2022 5:07 pm
  • Real Name: Dorin Godja

Re: Exporting subs to plain text

PostThu Oct 24, 2024 9:16 am

Now you can adjust the newline characters;
the line will break only when a caption from the subtitle ends in one of those characters.
edit this in script, if needed

local newLineChars = {".", "?", "!"}

Code: Select all
local filePath = "E://Resolve//Forum//Subtitle//subtitle.txt"
local newLineChars = {".", "?", "!"}

local resolve = app:GetResolve()
local projectManager = resolve:GetProjectManager()
local project = projectManager:GetCurrentProject()
local timeline = project:GetCurrentTimeline()

if timeline == nil then
    print("No Active Timeline")
    os.exit()
end

local subtitles = timeline:GetItemListInTrack("subtitle", 1)
local file = io.open(filePath, "w")

local function endsWithAny(str, chars)
    for _, char in ipairs(chars) do
        if str:sub(-1) == char then
            return true
        end
    end
    return false
end

for key, value in pairs(subtitles) do
    if key == "__flags" then
        break
    end
    local caption = value:GetName()
    file:write(caption)
    if endsWithAny(caption, newLineChars) then
        file:write("\n")
    end
end

file:close()
print("Subtitles have been saved to " .. filePath)



cheers,
Dorin
DaVinci Resolve Anthem
https://www.youtube.com/watch?v=CcKC8R9ku50
DaVinci Resolve Clips
https://www.youtube.com/playlist?list=PLYgg-7sUX2Jh3dqNJ0AVBTIlDFtufrYyn
Playhead Lock Script
https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=210163
Offline
User avatar

buckenmeyer

  • Posts: 81
  • Joined: Thu Jun 11, 2020 7:52 am
  • Location: Madrid, Spain
  • Real Name: Javier Buckenmeyer

Re: Exporting subs to plain text

PostThu Oct 24, 2024 9:25 am

I need a space before each break because it sticks the words together where the break is...

"¿Cómo sabercuando te estáscomprando unzapato deflamenca si tequeda bien?"

should be

"¿Cómo saber cuando te estás comprando un zapato de flamenca si te queda bien?"

I looked up lua programming and tried changing this: file:write("\32\n") but that didn't work to add a space.
Graphics: Nvidia GeForce GTX 4060 8GB
CPU: I5-13400 @ 2500 Mhz
RAM: 32 GB
OS: Win 11
Offline

DorinDXN

  • Posts: 174
  • Joined: Thu Aug 04, 2022 5:07 pm
  • Real Name: Dorin Godja

Re: Exporting subs to plain text

PostThu Oct 24, 2024 9:28 am

this should work

Code: Select all
local filePath = "E://Resolve//Forum//Subtitle//subtitle.txt"
local newLineChars = {".", "?", "!"}

local resolve = app:GetResolve()
local projectManager = resolve:GetProjectManager()
local project = projectManager:GetCurrentProject()
local timeline = project:GetCurrentTimeline()

if timeline == nil then
    print("No Active Timeline")
    os.exit()
end

local subtitles = timeline:GetItemListInTrack("subtitle", 1)
local file = io.open(filePath, "w")

local function endsWithAny(str, chars)
    for _, char in ipairs(chars) do
        if str:sub(-1) == char then
            return true
        end
    end
    return false
end

for key, value in pairs(subtitles) do
    if key == "__flags" then
        break
    end
    local caption = value:GetName()
    file:write(caption)
   file:write(" ")
    if endsWithAny(caption, newLineChars) then
        file:write("\n")
    end
end

file:close()
print("Subtitles have been saved to " .. filePath)
DaVinci Resolve Anthem
https://www.youtube.com/watch?v=CcKC8R9ku50
DaVinci Resolve Clips
https://www.youtube.com/playlist?list=PLYgg-7sUX2Jh3dqNJ0AVBTIlDFtufrYyn
Playhead Lock Script
https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=210163
Offline
User avatar

buckenmeyer

  • Posts: 81
  • Joined: Thu Jun 11, 2020 7:52 am
  • Location: Madrid, Spain
  • Real Name: Javier Buckenmeyer

Re: Exporting subs to plain text

PostThu Oct 24, 2024 9:34 am

Excellent!

Thank you, Dorin!

That should be useful to other people too. Print out the text for social on each video.
Graphics: Nvidia GeForce GTX 4060 8GB
CPU: I5-13400 @ 2500 Mhz
RAM: 32 GB
OS: Win 11
Offline

DorinDXN

  • Posts: 174
  • Joined: Thu Aug 04, 2022 5:07 pm
  • Real Name: Dorin Godja

Re: Exporting subs to plain text

PostThu Oct 24, 2024 11:16 am

I'll update here the script:

viewtopic.php?f=21&t=210611

in v1.3 updated already, some control characters like LS (line separator) and PS (paragraph separator) are now replaced with space, to prevent them ending in plain text.

cheers,
Dorin
DaVinci Resolve Anthem
https://www.youtube.com/watch?v=CcKC8R9ku50
DaVinci Resolve Clips
https://www.youtube.com/playlist?list=PLYgg-7sUX2Jh3dqNJ0AVBTIlDFtufrYyn
Playhead Lock Script
https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=210163
Offline
User avatar

KrunoSmithy

  • Posts: 4578
  • Joined: Fri Oct 20, 2023 11:01 pm
  • Warnings: 1
  • Real Name: Kruno Stifter

Re: Exporting subs to plain text

PostThu Oct 24, 2024 6:08 pm

Here is alternative, online resource as well.

Convert Subtitles to Plain Text

https://subtitletools.com/convert-subti ... ext-online
Offline
User avatar

buckenmeyer

  • Posts: 81
  • Joined: Thu Jun 11, 2020 7:52 am
  • Location: Madrid, Spain
  • Real Name: Javier Buckenmeyer

Re: Exporting subs to plain text

PostFri Oct 25, 2024 7:53 am

Ok, thanks.
Graphics: Nvidia GeForce GTX 4060 8GB
CPU: I5-13400 @ 2500 Mhz
RAM: 32 GB
OS: Win 11
Offline
User avatar

PedjaS

  • Posts: 56
  • Joined: Wed Jul 13, 2022 3:54 pm
  • Real Name: Predrag Supurovic

Re: Exporting subs to plain text

PostMon Apr 14, 2025 8:56 pm

There is Open Source Subtitle editor which is good and can export to plain text with options for export customization.

https://github.com/SubtitleEdit/subtitleedit
Offline
User avatar

Igor Riđanović

  • Posts: 1656
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Exporting subs to plain text

PostWed Apr 16, 2025 12:25 am

This is also something you can do as simpler oneline. You save an SRT from Resolve and convert it to a TXT file. Linux or macOS would have some better options, here's a Windows command to do it:
Code: Select all
findstr /V /R "^[0-9][0-9]*$ -->" input.srt | findstr /V /R "^[0-9][0-9]*$" > output.txt
www.metafide.com - DaVinci Resolve™ Apps

Return to DaVinci Resolve

Who is online

Users browsing this forum: Mads Johansen, MediaGary, Mike Manus and 349 guests