Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-08-06· OpenAIAi2 WildChat-4.8M (AI2)

in DaVinci Resolve this Lua script fails to create a compound clip, why is that? --…

  1. User

    in DaVinci Resolve this Lua script fails to create a compound clip, why is that?

    -- Function to convert frames to timecode string function framesToTimecode(frames, fps) local total_seconds = frames / fps local hours = math.floor(total_seconds / 3600) total_seconds = total_seconds % 3600 local minutes = math.floor(total_seconds / 60) local seconds = math.floor(total_seconds % 60) local frame_number = math.floor(frames % fps) return string.format("%02d:%02d:%02d:%02d", hours, minutes, seconds, frame_number) end

    -- Initialize Resolve objects local resolve = Resolve() local projectManager = resolve:GetProjectManager() local project = projectManager:GetCurrentProject() local timeline = project:GetCurrentTimeline() local markers = timeline:GetMarkers()

    -- Get the frame rate local timelineFps = tonumber(project:GetSetting("timelineFrameRate"))

    if not timelineFps then print("Unable to retrieve timeline frame rate.") return end

    if not markers or next(markers) == nil then print("No markers found on the current timeline.") return end

    -- Loop through all markers for frameId, marker in pairs(markers) do local start_frame = frameId local duration_frames = marker.duration

    if not duration_frames or duration_frames == 0 then
        print("Skipping marker '" .. (marker.name or "Unnamed") .. "' at frame " .. start_frame .. " with no duration.")
        goto continue
    end
    
    local end_frame = start_frame + duration_frames
    local name = marker.name or "Compound Clip"
    
    print("Processing marker '" .. name .. "' from frame " .. start_frame .. " to " .. end_frame)
    
    local itemsToInclude = {}
    local trackTypes = {"video", "audio"}  -- Process both video and audio tracks
    
    for _, trackType in ipairs(trackTypes) do
        local trackCount = timeline:GetTrackCount(trackType)
        for trackIndex = 1, trackCount do
            local clips = timeline:GetItemListInTrack(trackType, trackIndex)
            if clips then
                for _, clip in ipairs(clips) do
                    local clipStartFrame = clip:GetStart()
                    local clipEndFrame = clip:GetEnd()
    
                    if clipEndFrame > start_frame and clipStartFrame < end_frame then
                        -- The clip overlaps with the marker's range
                        table.insert(itemsToInclude, clip)
                    end
                end
            else
                print("No clips found in track " .. trackIndex .. " of type " .. trackType)
            end
        end
    end
    
    if #itemsToInclude == 0 then
        print("No clips found within marker range. Skipping marker '" .. name .. "'.")
        goto continue
    end
    
    -- Create compound clip from the list of timeline items
    local compoundClip = timeline:CreateCompoundClip(itemsToInclude)
    if compoundClip then
        -- Set the name of the compound clip
        local setNameResult = compoundClip:SetName(name)
        if not setNameResult then
            print("Failed to set name for compound clip.")
        else
            print("Compound clip '" .. name .. "' created.")
        end
    else
        print("Failed to create compound clip for marker: " .. name)
    end
    
    ::continue::
    

    end

  2. Assistant

    When troubleshooting a Lua script in DaVinci Resolve that fails to create a compound clip, several potential issues should be considered:

    1. API Methods and Returns: Ensure that the methods you are using are accurately spelled and documented in the DaVinci Resolve Developer API. For example, check if CreateCompoundClip is available and works as expected in your version of DaVinci Resolve.

    2. Timeline and Clip Objects: Verify that the objects you are working with are indeed what you expect them to be. Use logging to inspect itemsToInclude before attempting to create a compound clip. There might be issues with how clips are gathered or stored in this table.

    3. Error Handling: Check return values or presence of more logs after failures. It is sometimes beneficial to have more descriptive error messages based on API documentation if available. The message "Failed to create compound clip for marker" is a generic catch-all and may not provide all the context needed.

    4. Compound Clip Limitations: Ensure that the clips you are trying to combine into a compound clip are not subject to limitations, such as unsupported clip types or configurations.

    5. Version Compatibility: API functionality can differ between versions of DaVinci Resolve. Make sure that the functionality you are using is supported in your current version.

    6. Framework Dependencies: Ensure that there are no missing dependencies or incorrect set-ups of Resolve, ProjectManager, and Timeline objects.

    7. Debugging Informations: Incorporate additional print statements to debug the frame indices being processed, the clips being included in itemsToInclude, and check whether timeline:GetItemListInTrack is indeed retrieving the expected clips.

    Here is a general troubleshooting approach using added debug prints:

    -- ... previously existing code ...
    
        for _, trackType in ipairs(trackTypes) do
            local trackCount = timeline:GetTrackCount(trackType)
            print("Track count for type " .. trackType .. ": " .. trackCount)
            for trackIndex = 1, trackCount do
                local clips = timeline:GetItemListInTrack(trackType, trackIndex)
                if clips then
                    print("Found " .. #clips .. " clips in track " .. trackIndex .. " of type " .. trackType)
                    for _, clip in ipairs(clips) do
                        local clipStartFrame = clip:GetStart()
                        local clipEndFrame = clip:GetEnd()
                        print("Checking clip from frame " .. clipStartFrame .. " to " .. clipEndFrame)
    
                        if clipEndFrame > start_frame and clipStartFrame < end_frame then
                            print("Clip overlaps with marker range, including in compound clip.")
                            table.insert(itemsToInclude, clip)
                        end
                    end
                else
                    print("No clips found in track " .. trackIndex .. " of type " .. trackType)
                end
            end
        end
    
        print("Total items to include in compound clip: " .. #itemsToInclude)
        
    -- ... continued code ...
    

    By incorporating these print statements, you can better inspect which clips are processed, included, or neglected, pinpointing possible discrepancies in metadata or configuration.