Handle media pool clip markers

鬼猫猫小于 1 分钟

Handle media pool clip markers

Python
#!/usr/bin/env python

"""
Sample script to demonstrate following operations to first MediaPool clip in DaVinci Resolve Studio:
1. Add markers
2. Get markers
3. Set customData
4. Delete markers

NOTE: Add one clip (recommended clip duration >= 80 frames) in the MediaPool root bin before running this script.

Example usage: 10_media_pool_marker_operations.py
"""

import os
import sys
from python_get_resolve import GetResolve

resolve = GetResolve()
project = resolve.GetProjectManager().GetCurrentProject()

if not project:
    print("No project is loaded")
    sys.exit()

# Open Media page
resolve.OpenPage("media")

# Get supporting objects
projectManager = resolve.GetProjectManager()
mediaPool = project.GetMediaPool()
rootBin = mediaPool.GetRootFolder()

# Go to root bin
mediaPool.SetCurrentFolder(rootBin)

# Gets clips
clips = rootBin.GetClipList()
if not clips or not clips[0]:
    print("Error: MediaPool root bin doesn't contain any clips, add one clip (recommended clip duration >= 80 frames) and try again!")
    sys.exit()

# Choose first clip in the list
clip = clips[0]

# Get clip frames
framesProperty = clip.GetClipProperty("Frames")
if not framesProperty:
    print("Error: Failed to get clip 'Frames' property !")
    sys.exit()

numFrames = int(framesProperty)

# Add Markers
if (numFrames >= 1):
    isSuccess = clip.AddMarker(1, "Red", "Marker1", "Marker1 at frame 1", 1)
    if isSuccess:
        print("Added marker at FrameId:1")

if (numFrames >= 20):
    isSuccess = clip.AddMarker(20, "Blue", "Marker2", "Marker2 at frame 20", 1, "My Custom Data") # marker with custom data
    if isSuccess:
        print("Added marker at FrameId:20")

if (numFrames >= (50 + 20)):
    isSuccess = clip.AddMarker(50, "Green", "Marker3", "Marker3 at frame 50 (duration 20)", 20) # marker with duration 20 frames
    if isSuccess:
        print("Added marker at FrameId:50")

print("")

# Get all markers for the clip
markers = clip.GetMarkers()
for key, value in markers.items():
    print("Marker at FrameId:%d" % key)
    print(value)

print("")

# Get marker using custom data
markerWithCustomData = clip.GetMarkerByCustomData("My Custom Data")
print("Marker with customData:")
print(markerWithCustomData)

print("")

# Set marker custom data
updatedCustomData = "Updated Custom Data"
isSuccess = clip.UpdateMarkerCustomData(20, updatedCustomData)
if isSuccess:
    print("Updated marker customData at FrameId:20")

print("")

# Get marker custom data
customData = clip.GetMarkerCustomData(20)
print("Marker CustomData at FrameId:20 is:'%s'" % customData)

print("")

# Delete marker using color
isSuccess = clip.DeleteMarkersByColor("Red")
if isSuccess:
    print("Deleted marker with color:'Red'")

# Delete marker using frame number
isSuccess = clip.DeleteMarkerAtFrame(50)
if isSuccess:
    print("Deleted marker at frameNum:50")

# Delete marker using custom data
isSuccess = clip.DeleteMarkerByCustomData(updatedCustomData)
if isSuccess:
    print("Deleted marker with Customdata:'%s'" % updatedCustomData)
Lua
--[[
Sample script to demonstrate following operations to first MediaPool clip in DaVinci Resolve Studio:
1. Add markers
2. Get markers
3. Set customData
4. Delete markers

NOTE: Add one clip (recommended clip duration >= 80 frames) in the MediaPool root bin before running this script.
--]]

local function GetFirstClipInMediaPool()
    -- Get supporting objects
    resolve = Resolve()
    projectManager = resolve:GetProjectManager()
    mediaPool = project:GetMediaPool()
    rootBin = mediaPool:GetRootFolder()

    -- Go to root bin
    mediaPool:SetCurrentFolder(rootBin)

    -- Get clips
    clips = rootBin:GetClipList()
    if not clips or (next(clips) == nil) then
        print("Error: MediaPool root bin doesn't contain any clips, add one clip (recommended clip duration >= 80 frames) and try again!")
        os.exit()
    end

    return clips[1]
end

local function GetClipFrameCount( clip )
    framesProperty = clip:GetClipProperty("Frames")
    if not framesProperty then
        print("Error: Failed to get clip 'Frames' property !")
        os.exit()
    end

    return tonumber(framesProperty)
end

local function AddMarkers( clip, numFrames )
    if (numFrames >= 1) then
        isSuccess = clip:AddMarker(1, "Red", "Marker1", "Marker1 at frame 1", 1)
        if isSuccess then
            print("Added marker at FrameId:1")
        end
    end

    if (numFrames >= 20) then
        isSuccess = clip:AddMarker(20, "Blue", "Marker2", "Marker2 at frame 20", 1, "My Custom Data") -- marker with custom data
        if isSuccess then
            print("Added marker at FrameId:20")
        end
    end

    if (numFrames >= (50 + 20)) then
        isSuccess = clip:AddMarker(50, "Green", "Marker3", "Marker3 at frame 50 (duration 20)", 20) -- marker with duration 20 frames
        if isSuccess then
            print("Added marker at FrameId:50")
        end
    end
end

local function PrintMarkerInfo( markerInfo )
    print("color:'" .. markerInfo["color"] .. "'  duration:" .. markerInfo["duration"] .. "  note:'" .. markerInfo["note"] .. "'  name:'" .. markerInfo["name"] .. "'  customData:'" .. markerInfo["customData"] .. "'")
end

local function PrintAllClipMarkers( clip )
    markers = clip:GetMarkers()
    for key, value in pairs(markers) do
        print("Marker at FrameId:" .. key)
        PrintMarkerInfo(value)
    end
end


resolve = Resolve()
project = resolve:GetProjectManager():GetCurrentProject()

if not project then
    print("No project is loaded")
    os.exit()
end

-- Open Media page
resolve:OpenPage("media")

-- Get first media pool clip
clip = GetFirstClipInMediaPool()

-- Get clip frames
numFrames = GetClipFrameCount(clip)

-- Add Markers
AddMarkers(clip, numFrames)

print("")

-- Get all markers for the clip
PrintAllClipMarkers(clip)

print("")

-- Get marker using custom data
markerWithCustomData = clip:GetMarkerByCustomData("My Custom Data")
print("Marker with customData:")
PrintMarkerInfo(markerWithCustomData)

print("")

-- Set marker custom data
updatedCustomData = "Updated Custom Data"
isSuccess = clip:UpdateMarkerCustomData(20, updatedCustomData)
if isSuccess then
    print("Updated marker customData at FrameId:20")
end

print("")

-- Get marker custom data
customData = clip:GetMarkerCustomData(20)
print("Marker CustomData at FrameId:20 is:'" .. customData .. "'")

print("")

-- Delete marker using color
isSuccess = clip:DeleteMarkersByColor("Red")
if isSuccess then
    print("Deleted marker with color:'Red'")
end

-- Delete marker using frame number
isSuccess = clip:DeleteMarkerAtFrame(50)
if isSuccess then
    print("Deleted marker at frameNum:50")
end

-- Delete marker using custom data
isSuccess = clip:DeleteMarkerByCustomData(updatedCustomData)
if isSuccess then
    print("Deleted marker with Customdata:'" .. updatedCustomData .. "'")
end
JavaScript
/**
 * Sample script to demonstrate following operations to first MediaPool clip in DaVinci Resolve Studio:
 * 1. Add markers
 * 2. Get markers
 * 3. Set customData
 * 4. Delete markers
 *
 * NOTE: Add one clip (recommended clip duration >= 80 frames) in the MediaPool root bin before running this script.
 */

const WorkflowIntegration = require('./WorkflowIntegration.node');

// Configurable variables
PLUGIN_ID = "com.blackmagicdesign.resolve.sampleplugin"; // update it to your unique plugin Id as mentioned in the manifest.xml file

// Main function to perform all actions
function main(pluginId) {
    // Check pluginId
    if (!pluginId) {
        alert("Error: 'pluginId' is empty, update it to some valid value and try again!");
        return false;
    }

    // Initialize
    isInitialized = WorkflowIntegration.Initialize(pluginId);
    if (!isInitialized) {
        alert("Error: Failed to initialize!");
        return;
    }

    // Get resolve object
    resolve = WorkflowIntegration.GetResolve();
    if (!resolve) {
        alert("Error: Failed to get resolve object!");
        return;
    }

    // Open Media page
    resolve.OpenPage("media");

    // Get supporting objects
    projectManager = resolve.GetProjectManager();
    project = projectManager.GetCurrentProject();
    mediaPool = project.GetMediaPool();
    rootBin = mediaPool.GetRootFolder();

    // Go to root bin
    mediaPool.SetCurrentFolder(rootBin);

    // Gets clips
    clips = rootBin.GetClipList();
    if (!clips || !clips[0]) {
        alert("Error: MediaPool root bin doesn't contain any clips, add one clip (recommended clip duration >= 80 frames) and try again!");
        return;
    }

    // Choose first clip in the list
    clip = clips[0];

    // Get clip frames
    framesProperty = clip.GetClipProperty("Frames");
    if (!framesProperty) {
        alert("Error: Failed to get clip 'Frames' property !");
        return;
    }
    numFrames = parseInt(framesProperty);

    // Add Markers
    if (numFrames >= 1) {
        isSuccess = clip.AddMarker(/*markerPos*/ 1, /*color*/ "Red", /*markerName*/ "Marker1", /*note*/ "Marker1 at frame 1", /*duration*/ 1);
        if (isSuccess) {
            console.log("Added marker at FrameId:1");
        }
    }

    if (numFrames >= 20) {
        isSuccess = clip.AddMarker(/*markerPos*/ 20, /*color*/ "Blue", /*markerName*/ "Marker2", /*note*/ "Marker2 at frame 20", /*duration*/ 1, /*customData*/ "My Custom Data"); // marker with custom data
        if (isSuccess) {
            console.log("Added marker at FrameId:20");
        }
    }

    if (numFrames >= (50 + 20)) {
        isSuccess = clip.AddMarker(/*markerPos*/ 50, /*color*/ "Green", /*markerName*/ "Marker3", /*note*/ "Marker3 at frame 50 (duration 20)", /*duration*/ 20); // marker with duration 20 frames
        if (isSuccess) {
            console.log("Added marker at FrameId:50");
        }
    }

    // Get all markers for the clip
    markers = clip.GetMarkers();
    for (let [frameId, markerInfo] of Object.entries(markers)) {
        console.log("Marker at FrameId:" + frameId);
        console.log(markerInfo);
    }

    // Get marker using custom data
    markerWithCustomData = clip.GetMarkerByCustomData("My Custom Data");
    console.log("Marker with customData:");
    console.log(markerWithCustomData);

    // Set marker custom data
    updatedCustomData = "Updated Custom Data";
    isSuccess = clip.UpdateMarkerCustomData(20, updatedCustomData);
    if (isSuccess) {
        console.log("Updated marker customData at FrameId:20");
    }

    // Get marker custom data
    customData = clip.GetMarkerCustomData(20);
    console.log(`Marker CustomData at FrameId:20 is:'${customData}'`);

    // Delete marker using color
    isSuccess = clip.DeleteMarkersByColor("Red");
    if (isSuccess) {
        console.log("Deleted marker with color:'Red'");
    }

    // Delete marker using frame number
    isSuccess = clip.DeleteMarkerAtFrame(50)
    if (isSuccess) {
        console.log("Deleted marker at frameNum:50");
    }

    // Delete marker using custom data
    isSuccess = clip.DeleteMarkerByCustomData(updatedCustomData)
    if (isSuccess) {
        console.log(`Deleted marker with customData:'${updatedCustomData}'`);
    }

    // Done
    // WorkflowIntegration.CleanUp(); // Call CleanUp() during plugin app quit only
}

// Run main function
main(PLUGIN_ID);
上次编辑于:
贡献者: muyanru,Yanru Mu