Looking for help with Lua scripting reading clips IN fr#

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

Robert Niessner

  • Posts: 5375
  • Joined: Thu Feb 21, 2013 9:51 am
  • Location: Graz, Austria

Looking for help with Lua scripting reading clips IN fr#

PostWed Nov 13, 2024 11:56 am

A little background:

I have been working on a remaster of an indie feature film shot decades ago in SD for almost three years now. Around 800 clips, shot on two cameras, some very long takes (like 8 min.)
The source footage is a progressive 4:3 23.976p packed into 29.97 interlaced with synced timecode.
I got the edit as Premiere Pro project (16:9 23.976p), the clips got a 3:2 pulldown treatment and cropped at the top & bottom.

Later on (already in the middle of the project) I decided to move the project over to Resolve, for its much better color grading abilities. Export via FCP XML. -> Resolve 17.4.6


Only after a while a realized that the pulldown settings did not translate over to Resolve and while Premiere Pro does a very good job to auto recognized the correct pattern, Resolve has no auto feature at all. So I had to sit through hundreds of clips and test through A/B/C/D/E patterns - and the worst: no preview for the settings. That means open the clip attributes, change the pattern, close the window, check if it is the correct pattern. If not, rinse and repeat. That means a few thousand times to go through this, while in After Effects for example it gets this right in 98% of all clips.

Well, ok then. Super easy, barely an inconvenience...

The next trap was that all the new remastered clips have not retained their timecode. Which makes it impossible to easily exchange and re-link.
So after importing the HD 23.976 clip to Resolve I set the timecode start to the same as the SD clip.
Only to find out that because of the 3:2 pulldown the timecode you retrieve from the SD clip does not match the timecode from the HD clip, because Resolve shows me a 23.976 timecode but based on the 29.97 timecode (or smthng like that).

Well, ok then. Super easy, barely an inconvenience...

Position playhead at the IN point of the source clip. Press F for Match Frame.
Switch from timecode to frames in the source viewer.
Only to find out that "Copy Timecode" does not work when this is set to show frame #
So I have to memorize the frame #
Then I open the HD clip in the source viewer and enter that frame #
Now with the source clip on the timeline still selected, I can initiate a replace command.
That does the job.

So to reduce the manual steps for this I started to create a Lua script.
But it seems there is no way in the API for Resolve 17.4.6 to correctly readout the timecode of the IN point of clip in the timeline. I only get the timecode from the playhead at its current position.

Code: Select all
item:GetStart()
seems not to work as expected.

The release notes for DVR 19.02 said:
• Scripting API support to get and set per-clip custom metadata.
• Scripting API support to get and set source start and end frames.
• Scripting API support to get and set source start and end timecode.


So it looks like that I am stuck with my script as long as I am on DVR 17.4.6 - is that a correct assumption or is there any known workaround?
Saying "Thx for help!" is not a crime.
--------------------------------
Robert Niessner
LAUFBILDkommission
Graz / Austria
--------------------------------
Blackmagic Camera Blog (German):
http://laufbildkommission.wordpress.com

Read the blog in English via Google Translate:
http://tinyurl.com/pjf6a3m
Offline
User avatar

Robert Niessner

  • Posts: 5375
  • Joined: Thu Feb 21, 2013 9:51 am
  • Location: Graz, Austria

Re: Looking for help with Lua scripting reading clips IN fr#

PostWed Nov 13, 2024 2:44 pm

Ok, found out that
Code: Select all
GetLeftOffset()

does that job for what I want.

But how to write the result into the clipboard buffer?
And it also seems there is no way to paste that onto the timecode of the source viewer, or is it?
Saying "Thx for help!" is not a crime.
--------------------------------
Robert Niessner
LAUFBILDkommission
Graz / Austria
--------------------------------
Blackmagic Camera Blog (German):
http://laufbildkommission.wordpress.com

Read the blog in English via Google Translate:
http://tinyurl.com/pjf6a3m
Offline
User avatar

KrunoSmithy

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

Re: Looking for help with Lua scripting reading clips IN fr#

PostWed Nov 13, 2024 5:19 pm

I don't have a lot of experiance with such footage restoration or scripting, but resolve 17.4.6 is pretty old release at this point with tones of stuff added and improved since than, maybe you would have a better luck with updated version.

sshot-971.jpg
sshot-971.jpg (44.16 KiB) Viewed 244 times


sshot-972.jpg
sshot-972.jpg (72.69 KiB) Viewed 244 times


Also, Fusion, including your version should have node called fields, which could have been useful, perhaps.

sshot-973.jpg
sshot-973.jpg (14.49 KiB) Viewed 244 times


There is also Revival OFX category of filters for some restoration work if you need it, and there is always various third party plug ins as well. Just putting it out there.

Sorry I can't help with script question.
Offline
User avatar

Robert Niessner

  • Posts: 5375
  • Joined: Thu Feb 21, 2013 9:51 am
  • Location: Graz, Austria

Re: Looking for help with Lua scripting reading clips IN fr#

PostWed Nov 13, 2024 10:20 pm

Thanks Kruno, but DVR 17 already has the neural engine. And if you look closer at your screenshots you will see that there is not auto function for 3:2 pull-down removal. The auto recognition is meant for field order. But here are no fields because the pull-down removal is meant to restore the existing true progressive frames. That is not deinterlacing.
Also the Revival OFX has nothing in for that type of source material.

I have several long term projects running where I just do not dare to update. Probably later in 2025 I will update to 19.3 or whatever will turn out as the most stable version and stay on that for the next 3 years.
Saying "Thx for help!" is not a crime.
--------------------------------
Robert Niessner
LAUFBILDkommission
Graz / Austria
--------------------------------
Blackmagic Camera Blog (German):
http://laufbildkommission.wordpress.com

Read the blog in English via Google Translate:
http://tinyurl.com/pjf6a3m
Offline
User avatar

Robert Niessner

  • Posts: 5375
  • Joined: Thu Feb 21, 2013 9:51 am
  • Location: Graz, Austria

Re: Looking for help with Lua scripting reading clips IN fr#

PostThu Nov 14, 2024 10:48 am

I've got a working script so far:

Code: Select all
-- Funktion zum Festlegen einer festen Position des Fensters in der Mitte des Bildschirms
function position_window(win, screenWidth, screenHeight, width, height)
    local posX = (screenWidth / 2) - (width / 2)
    local posY = (screenHeight / 2) - (height / 2)
    win:SetGeometry(posX, posY, width, height)
end

-- Hauptfunktion zum Anzeigen der Frame-Nummer
function show_frame_number_window()
    local ui = fu.UIManager
    local disp = bmd.UIDispatcher(ui)

    -- Projekt und Timeline abrufen
    local projectManager = resolve:GetProjectManager()
    local project = projectManager:GetCurrentProject()
    local timeline = project:GetCurrentTimeline()

    -- Prüfen, ob ein Timeline-Item ausgewählt ist
    local selectedClip = timeline:GetCurrentVideoItem()
    if not selectedClip then
        print("Kein Clip in der Timeline ausgewählt.")
        return
    end

    -- Frame-Nummer aus dem Clip-Offset abrufen
    local frameNumber = selectedClip:GetLeftOffset()

    -- Erstelle das Fenster ohne feste Position
    local win = disp:AddWindow({
        ID = 'FrameWin',
        WindowTitle = 'Frame Number Display',
        ui:VGroup{
            ui:HGroup{
                ui:Label{Text = "Frame Number:", MinimumSize = {90, 20}, MaximumSize = {90, 20}}, -- Beschriftung leicht vergrößert
                ui:LineEdit{ID = 'FrameOutput', ReadOnly = true, Text = tostring(frameNumber), MinimumSize = {120, 20}, MaximumSize = {120, 20}}  -- Größe des Textfeldes erhöht
            },
            ui:HGroup{
                ui:Button{ID = 'CopyButton', Text = 'Kopieren', MinimumSize = {90, 30}, MaximumSize = {90, 30}}, -- Größe des Kopieren-Buttons
                ui:Button{ID = 'CloseButton', Text = 'Schließen', MinimumSize = {90, 30}, MaximumSize = {90, 30}} -- Größe des Schließen-Buttons
            }
        }
    })

    -- Fenstergröße und -position festlegen
    local windowWidth = 300
    local windowHeight = 120
    position_window(win, 1920, 1080, windowWidth, windowHeight)  -- Fenster zentrieren

    -- Event-Handling für den Kopieren-Button
    win.On.CopyButton.Clicked = function()
        local frameText = win:GetItems().FrameOutput.Text
        bmd.setclipboard(frameText) -- Kopiere den Framewert in die Zwischenablage
        print("Frame Number copied to clipboard: " .. frameText)
    end

    -- Event-Handling für den Schließen-Button
    win.On.CloseButton.Clicked = function()
        disp:ExitLoop()  -- Beenden der Schleife und Fenster schließen
        win:Hide()
    end

    -- Schließen-Event (Klick auf das X in der Ecke des Fensters)
    win.On.FrameWin.Close = function()
        disp:ExitLoop()
        win:Hide()
    end

    -- Zeige das Fenster an und starte die Event-Schleife
    win:Show()
    disp:RunLoop()
    win:Hide()
end

-- Starten der Hauptfunktion
show_frame_number_window()



But alas - some many things can't be scripted in Resolve yet.

I will expand the script later for using keyboard shortcuts via os.execute() by either invoking external AutoIt or AutoHotkey to reach my goals.

But man, this turned out to be so much more elaborate and time-consuming than I thought.
Saying "Thx for help!" is not a crime.
--------------------------------
Robert Niessner
LAUFBILDkommission
Graz / Austria
--------------------------------
Blackmagic Camera Blog (German):
http://laufbildkommission.wordpress.com

Read the blog in English via Google Translate:
http://tinyurl.com/pjf6a3m
Offline
User avatar

Robert Niessner

  • Posts: 5375
  • Joined: Thu Feb 21, 2013 9:51 am
  • Location: Graz, Austria

Re: Looking for help with Lua scripting reading clips IN fr#

PostThu Nov 14, 2024 10:57 am

There is also a bug in Resolve (at least in 17.4.6) with Copy and Paste management in the timecode input of the source viewer when set to show Source Frames.

Let's say you want to get the frame # 142 via match frame from your source clip. Now go to the media pool, double click the remastered clip to open in the source viewer which will show frame # 0.
When you now select the timecode input you can't paste 142 into that text input because it has more than one digit. If you move over to frame # 100 then you can paste 142 because the number in the input has equal digits.
Saying "Thx for help!" is not a crime.
--------------------------------
Robert Niessner
LAUFBILDkommission
Graz / Austria
--------------------------------
Blackmagic Camera Blog (German):
http://laufbildkommission.wordpress.com

Read the blog in English via Google Translate:
http://tinyurl.com/pjf6a3m

Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot], David Cherniack, Gary Hango, Jordan40, pperquin, Robert John and 273 guests