├── .gitignore ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── Makefile ├── README.md ├── _config.yml ├── docs ├── feed.xml └── index.md └── examples ├── lua ├── 1_sorted_timeline_from_folder.lua ├── 2_compositions_from_timeline_clips.lua ├── 3_grade_and_render_all_timelines.lua ├── 4_display_project_and_folder_tree.lua ├── 5_get_project_information.lua ├── 6_get_current_media_thumbnail.lua └── 7_add_subclips_to_timeline.lua └── python ├── 1_sorted_timeline_from_folder.py ├── 2_compositions_from_timeline_clips.py ├── 3_grade_and_render_all_timelines.py ├── 4_display_project_and_folder_tree.py ├── 5_get_project_information.py ├── 6_get_current_media_thumbnail.py ├── 7_add_subclips_to_timeline.py └── python_get_resolve.py /.gitignore: -------------------------------------------------------------------------------- 1 | _site 2 | .sass-cache 3 | .jekyll-metadata 4 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.7.1 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # Hello! This is where you manage which Jekyll version is used to run. 4 | # When you want to use a different version, change it below, save the 5 | # file and run `bundle install`. Run Jekyll with `bundle exec`, like so: 6 | # 7 | # bundle exec jekyll serve 8 | # 9 | # This will help ensure the proper Jekyll version is running. 10 | # Happy Jekylling! 11 | gem "jekyll", "~> 3.9.0" 12 | 13 | # This is the default theme for new Jekyll sites. You may change this to anything you like. 14 | gem "minima", "~> 2.0" 15 | 16 | # If you want to use GitHub Pages, remove the "gem "jekyll"" above and 17 | # uncomment the line below. To upgrade, run `bundle update github-pages`. 18 | # gem "github-pages", group: :jekyll_plugins 19 | 20 | # If you have any plugins, put them here! 21 | group :jekyll_plugins do 22 | gem 'jekyll-theme-primer' 23 | gem 'jekyll-theme-slate' 24 | gem "jekyll-feed", "~> 0.6" 25 | end 26 | 27 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 28 | # and associated library. 29 | install_if -> { RUBY_PLATFORM =~ %r!mingw|mswin|java! } do 30 | gem "tzinfo", "~> 1.2" 31 | gem "tzinfo-data" 32 | end 33 | 34 | # Performance-booster for watching directories on Windows 35 | gem "wdm", "~> 0.1.0", :install_if => Gem.win_platform? 36 | 37 | # kramdown v2 ships without the gfm parser by default. If you're using 38 | # kramdown v1, comment out this line. 39 | gem "kramdown-parser-gfm" 40 | 41 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | addressable (2.7.0) 5 | public_suffix (>= 2.0.2, < 5.0) 6 | colorator (1.1.0) 7 | concurrent-ruby (1.1.7) 8 | em-websocket (0.5.2) 9 | eventmachine (>= 0.12.9) 10 | http_parser.rb (~> 0.6.0) 11 | eventmachine (1.2.7) 12 | faraday (1.1.0) 13 | multipart-post (>= 1.2, < 3) 14 | ruby2_keywords 15 | ffi (1.13.1) 16 | forwardable-extended (2.6.0) 17 | http_parser.rb (0.6.0) 18 | i18n (0.9.5) 19 | concurrent-ruby (~> 1.0) 20 | jekyll (3.9.0) 21 | addressable (~> 2.4) 22 | colorator (~> 1.0) 23 | em-websocket (~> 0.5) 24 | i18n (~> 0.7) 25 | jekyll-sass-converter (~> 1.0) 26 | jekyll-watch (~> 2.0) 27 | kramdown (>= 1.17, < 3) 28 | liquid (~> 4.0) 29 | mercenary (~> 0.3.3) 30 | pathutil (~> 0.9) 31 | rouge (>= 1.7, < 4) 32 | safe_yaml (~> 1.0) 33 | jekyll-feed (0.15.1) 34 | jekyll (>= 3.7, < 5.0) 35 | jekyll-github-metadata (2.13.0) 36 | jekyll (>= 3.4, < 5.0) 37 | octokit (~> 4.0, != 4.4.0) 38 | jekyll-sass-converter (1.5.2) 39 | sass (~> 3.4) 40 | jekyll-seo-tag (2.7.1) 41 | jekyll (>= 3.8, < 5.0) 42 | jekyll-theme-primer (0.5.4) 43 | jekyll (> 3.5, < 5.0) 44 | jekyll-github-metadata (~> 2.9) 45 | jekyll-seo-tag (~> 2.0) 46 | jekyll-theme-slate (0.1.1) 47 | jekyll (~> 3.5) 48 | jekyll-seo-tag (~> 2.0) 49 | jekyll-watch (2.2.1) 50 | listen (~> 3.0) 51 | kramdown (2.3.0) 52 | rexml 53 | kramdown-parser-gfm (1.1.0) 54 | kramdown (~> 2.0) 55 | liquid (4.0.3) 56 | listen (3.2.1) 57 | rb-fsevent (~> 0.10, >= 0.10.3) 58 | rb-inotify (~> 0.9, >= 0.9.10) 59 | mercenary (0.3.6) 60 | minima (2.5.1) 61 | jekyll (>= 3.5, < 5.0) 62 | jekyll-feed (~> 0.9) 63 | jekyll-seo-tag (~> 2.1) 64 | multipart-post (2.1.1) 65 | octokit (4.18.0) 66 | faraday (>= 0.9) 67 | sawyer (~> 0.8.0, >= 0.5.3) 68 | pathutil (0.16.2) 69 | forwardable-extended (~> 2.6) 70 | public_suffix (4.0.6) 71 | rb-fsevent (0.10.4) 72 | rb-inotify (0.10.1) 73 | ffi (~> 1.0) 74 | rexml (3.2.4) 75 | rouge (3.24.0) 76 | ruby2_keywords (0.0.2) 77 | safe_yaml (1.0.5) 78 | sass (3.7.4) 79 | sass-listen (~> 4.0.0) 80 | sass-listen (4.0.0) 81 | rb-fsevent (~> 0.9, >= 0.9.4) 82 | rb-inotify (~> 0.9, >= 0.9.7) 83 | sawyer (0.8.2) 84 | addressable (>= 2.3.5) 85 | faraday (> 0.8, < 2.0) 86 | thread_safe (0.3.6) 87 | tzinfo (1.2.7) 88 | thread_safe (~> 0.1) 89 | tzinfo-data (1.2020.3) 90 | tzinfo (>= 1.0.0) 91 | wdm (0.1.1) 92 | 93 | PLATFORMS 94 | ruby 95 | 96 | DEPENDENCIES 97 | jekyll (~> 3.9.0) 98 | jekyll-feed (~> 0.6) 99 | jekyll-theme-primer 100 | jekyll-theme-slate 101 | kramdown-parser-gfm 102 | minima (~> 2.0) 103 | tzinfo (~> 1.2) 104 | tzinfo-data 105 | wdm (~> 0.1.0) 106 | 107 | BUNDLED WITH 108 | 2.1.4 109 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: dev 2 | 3 | dev: 4 | bundle exec jekyll serve --livereload 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unofficial DaVinci Resolve Scripting Documentation 2 | 3 | [API documentation](https://deric.github.io/DaVinciResolve-API-Docs/) is generated from this repository. 4 | 5 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | # Welcome to Jekyll! 2 | # 3 | # This config file is meant for settings that affect your whole blog, values 4 | # which you are expected to set up once and rarely edit after that. If you find 5 | # yourself editing this file very often, consider using Jekyll's data files 6 | # feature for the data you need to update frequently. 7 | # 8 | # For technical reasons, this file is *NOT* reloaded automatically when you use 9 | # 'bundle exec jekyll serve'. If you change this file, please restart the server process. 10 | 11 | # Site settings 12 | # These are used to personalize your new site. If you look in the HTML files, 13 | # you will see them accessed via {{ site.title }}, {{ site.email }}, and so on. 14 | # You can create any custom variable you would like, and they will be accessible 15 | # in the templates via {{ site.myvariable }}. 16 | title: Unofficial DaVinci Resolve Scripting Documentation 17 | email: barton.tomas@gmail.com 18 | description: >- # this means to ignore newlines until "baseurl:" 19 | Write an awesome description for your new site here. You can edit this 20 | line in _config.yml. It will appear in your document head meta (for 21 | Google search results) and in your feed.xml site description. 22 | baseurl: "" # the subpath of your site, e.g. /blog 23 | url: "https://deric.github.io/DaVinciResolve-API-Docs" # the base hostname & protocol for your site, e.g. http://example.com 24 | encoding: UTF-8 25 | 26 | # Build settings 27 | markdown: kramdown 28 | source: docs 29 | theme: jekyll-theme-slate 30 | plugins: 31 | # - jekyll-feed 32 | 33 | # Exclude from processing. 34 | # The following items will not be processed, by default. Create a custom list 35 | # to override the default setting. 36 | # exclude: 37 | # - Gemfile 38 | # - Gemfile.lock 39 | # - node_modules 40 | # - vendor/bundle/ 41 | # - vendor/cache/ 42 | # - vendor/gems/ 43 | # - vendor/ruby/ -------------------------------------------------------------------------------- /docs/feed.xml: -------------------------------------------------------------------------------- 1 | Jekyll2020-10-18T17:34:37+02:00http://localhost:4000/feed.xmlUnofficial DaVinci Resolve Scripting DocumentationWrite an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description. -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | # Feel free to add content and custom Front Matter to this file. 3 | # To modify the layout, see https://jekyllrb.com/docs/themes/#overriding-theme-defaults 4 | 5 | layout: page 6 | --- 7 | 8 | 9 | # Unofficial DaVinci Resolve Scripting Documentation 10 | 11 | ## About This Document 12 | This document is a formatted copy of the official BlackmagicDesign DaVinci Resolve scripting documentation. 13 | 14 | 15 | WARNING: Keep in mind that this document might contain errors and might not be up to date with the current Resolve version. 16 | If in doubt, always consult the official Resolve documentation provided by BlackmagicDesign. 17 | 18 | 19 | In this package, you will find a brief introduction to the Scripting API for DaVinci Resolve Studio. This package contains folders containing the basic import 20 | modules for scripting access (`DaVinciResolve.py`) and some representative [examples](https://github.com/deric/DaVinciResolve-API-Docs/tree/main/examples). 21 | 22 | From v16.2.0 onwards, the nodeIndex parameters accepted by `SetLUT()` and `SetCDL()` are 1-based instead of 0-based, i.e. 1 <= nodeIndex <= total number of nodes. 23 | 24 | ## Overview 25 | 26 | As with Blackmagic Design Fusion scripts, user scripts written in Lua and Python programming languages are supported. By default, scripts can be invoked from the Console window in the Fusion page, 27 | or via command line. This permission can be changed in Resolve Preferences, to be only from Console, or to be invoked from the local network. Please be aware of the security implications when 28 | allowing scripting access from outside of the Resolve application. 29 | 30 | ## Basic Resolve API 31 | 32 | Deprecated methods are marked with ~~strikethrough~~. 33 | 34 | ### Resolve 35 | 36 | |--- 37 | | Method | Return Type | Comment 38 | |--- 39 | | `Fusion()` | `Fusion` | Returns the Fusion object. Starting point for Fusion scripts. 40 | | `GetMediaStorage()` | `MediaStorage` | Returns media storage object to query and act on media locations. 41 | | `GetProjectManager()`| `ProjectManager` | Returns project manager object for currently open database. 42 | | `OpenPage(pageName)` | `None` | Switches to indicated page in DaVinci Resolve. Input can be one of (`"media", "cut", "edit", "fusion", "color", "fairlight", "deliver"`). 43 | |=== 44 | 45 | 46 | 47 | ### ProjectManager 48 | 49 | |--- 50 | | Method | Return Type | Comment 51 | |--- 52 | |`CreateProject(projectName)` |`Project` | Creates and returns a project if projectName (text) is unique, and None if it is not. 53 | |`DeleteProject(projectName)` |`Bool` | Delete project in the current folder if not currently loaded. 54 | |`LoadProject(projectName)` |`Project` | Loads and returns the project with name = projectName (text) if there is a match found, and None if there is no matching Project. 55 | |`GetCurrentProject()` |`Project` | Returns the currently loaded Resolve project. 56 | |`SaveProject()` |`Bool` | Saves the currently loaded project with its own name. Returns True if successful. 57 | |`CloseProject(project)` |`Bool` | Closes the specified project without saving. 58 | |`CreateFolder(folderName)` |`Bool` | Creates a folder if folderName (text) is unique. 59 | |`GetProjectListInCurrentFolder()` |`[project names...]` | Returns a list of project names in current folder. 60 | |`GetFolderListInCurrentFolder()` |`[folder names...]` | Returns a list of folder names in current folder. 61 | |`GotoRootFolder()` |`Bool` | Opens root folder in database. 62 | |`GotoParentFolder()` |`Bool` | Opens parent folder of current folder in database if current folder has parent. 63 | |`OpenFolder(folderName)` |`Bool` | Opens folder under given name. 64 | |`ImportProject(filePath)` |`Bool` | Imports a project under given file path. Returns true in case of success. 65 | |`ExportProject(projectName, filePath)` |`Bool` | Exports a project based on given name into provided file path. Returns true in case of success. 66 | |`RestoreProject(filePath)` |`Bool` | Restores a project under given backup file path. Returns true in case of success. 67 | |~~`GetProjectsInCurrentFolder()`~~ |`{project names...}` | Returns a dict of project names in current folder. 68 | |~~`GetFoldersInCurrentFolder()`~~ |`{folder names...}` | Returns a dict of folder names in current folder. 69 | |=== 70 | 71 | ### Project 72 | 73 | |--- 74 | | Method | Return Type | Comment 75 | |--- 76 | |`GetMediaPool()` |`MediaPool` | Returns the Media Pool object. 77 | |`GetTimelineCount()` |`int` | Returns the number of timelines currently present in the project. 78 | |`GetTimelineByIndex(idx)` |`Timeline` | Returns timeline at the given index, 1 <= idx <= project.GetTimelineCount() 79 | |`GetCurrentTimeline()` |`Timeline` | Returns the currently loaded timeline. 80 | |`SetCurrentTimeline(timeline)` |`Bool` | Sets given timeline as current timeline for the project. Returns True if successful. 81 | |`GetName()` |`string` | Returns project name. 82 | |`SetName(projectName)` |`Bool` | Sets project name if given projectname (text) is unique. 83 | |`GetPresetList()` |`[presets...]` | Returns a list of presets and their information. 84 | |`SetPreset(presetName)` |`Bool` | Sets preset by given presetName (string) into project. 85 | |`GetRenderJobList()` |`[render jobs...]` | Returns a list of render jobs and their information. 86 | |`GetRenderPresetList()` |`[presets...]` | Returns a list of render presets and their information. 87 | |`StartRendering(index1, index2, ...)` |`Bool` | Starts rendering for given render jobs based on their indices. 88 | |`StartRendering([idxs...], isInteractiveMode = False)`|`Bool` | Starts rendering for given render jobs based on their indices. Optional field `isInteractiveMode`. It is Bool Type and it defaults to False. `isInteractiveMode` indicates whether there should be display of error dialog during rendering. 89 | |`StartRendering(isInteractiveMode = False)` |`Bool` | Starts rendering for all render jobs. Optional field `isInteractiveMode`. It is Bool Type and it defaults to False. `isInteractiveMode` indicates whether there should be display of error dialog during rendering. 90 | |`StopRendering()` |`None` | Stops rendering for all render jobs. 91 | |`IsRenderingInProgress()` |`Bool` | Returns true is rendering is in progress. 92 | |`AddRenderJob()` |`Bool` | Adds render job to render queue. 93 | |`DeleteRenderJobByIndex(idx)` |`Bool` | Deletes render job based on given job index (int). 94 | |`DeleteAllRenderJobs()` |`Bool` | Deletes all render jobs. 95 | |`LoadRenderPreset(presetName)` |`Bool` | Sets a preset as current preset for rendering if presetName (text) exists. 96 | |`SaveAsNewRenderPreset(presetName)` |`Bool` | Creates a new render preset by given name if presetName(text) is unique. 97 | |`SetRenderSettings({settings})` |`Bool` | Sets given settings for rendering. Settings is a dict, with support for the keys: `"SelectAllFrames", "MarkIn", "MarkOut", "TargetDir", "CustomName"`. 98 | |`GetRenderJobStatus(idx)` |`{status info}` | Returns a dict with job status and completion percentage of the job by given job index (int). 99 | |`GetSetting(settingName)` |`string` | Returns value of project setting (indicated by settingName, string). Check the section below for more information. 100 | |`SetSetting(settingName, settingValue)` |`Bool` | Sets a project setting (indicated by settingName, string) to the value (settingValue, string). Check the section below for more information. 101 | |`GetRenderFormats()` |`{render formats..}`| Returns a dict (format -> file extension) of available render formats. 102 | |`GetRenderCodecs(renderFormat)` |`{render codecs...}`| Returns a dict (codec description -> codec name) of available codecs for given render format (string). 103 | |`GetCurrentRenderFormatAndCodec()` |`{format, codec}` | Returns a dict with currently selected format 'format' and render codec 'codec'. 104 | |`SetCurrentRenderFormatAndCodec(format, codec)` |`Bool` | Sets given render format (string) and render codec (string) as options for rendering. 105 | |~~`GetPresets()`~~ |`{presets...}` | Returns a dict of presets and their information. 106 | |~~`GetRenderJobs()`~~ |`{render jobs...}` | Returns a dict of render jobs and their information. 107 | |~~`GetRenderPresets()`~~ |`{presets...}` | Returns a dict of render presets and their information. 108 | |=== 109 | 110 | 111 | ### MediaStorage 112 | 113 | 114 | |--- 115 | | Method | Return Type | Comment 116 | |--- 117 | |`GetMountedVolumeList()` | `[paths...]` | Returns a list of folder paths corresponding to mounted volumes displayed in Resolve’s Media Storage. 118 | |`GetSubFolderList(folderPath)` | `[paths...]` | Returns a list of folder paths in the given absolute folder path. 119 | |`GetFileList(folderPath)` | `[paths...]` | Returns a list of media and file listings in the given absolute folder path. Note that media listings may be logically consolidated entries. 120 | |`RevealInStorage(path)` | `None` | Expands and displays a given file/folder path in Resolve’s Media Storage. 121 | |`AddItemListToMediaPool(item1, item2, ...)` | `[clips...]` | Adds specified file/folder paths from Media Storage into current Media Pool folder. Input is one or more file/folder paths. Returns a list of the MediaPoolItems created. 122 | |`AddItemListToMediaPool([items...])` | `[clips...]` | Adds specified file/folder paths from Media Storage into current Media Pool folder. Input is an array of file/folder paths. Returns a list of the MediaPoolItems created. 123 | |~~`GetMountedVolumes()`~~ |`{paths...}` | Returns a dict of folder paths corresponding to mounted volumes displayed in Resolve’s Media Storage. 124 | |~~`GetSubFolders(folderPath)`~~ |`{paths...}` | Returns a dict of folder paths in the given absolute folder path. 125 | |~~`GetFiles(folderPath)`~~ |`{paths...}` | Returns a dict of media and file listings in the given absolute folder path. Note that media listings may be logically consolidated entries. 126 | |~~`AddItemsToMediaPool(item1, item2, ...)`~~ |`{clips...}` | Adds specified file/folder paths from Media Storage into current Media Pool folder. Input is one or more file/folder paths. Returns a dict of the MediaPoolItems created. 127 | |~~`AddItemsToMediaPool([items...])`~~ |`{clips...}` | Adds specified file/folder paths from Media Storage into current Media Pool folder. Input is an array of file/folder paths. Returns a dict of the MediaPoolItems created. 128 | |=== 129 | 130 | 131 | ### MediaPool 132 | 133 | |--- 134 | | Method | Return Type | Comment 135 | |--- 136 | |`GetRootFolder()` |`Folder` |Returns the root Folder of Media Pool 137 | |`AddSubFolder(folder, name)` |`Folder` |Adds a new subfolder under specified Folder object with the given name. 138 | |`CreateEmptyTimeline(name)` |`Timeline` |Adds a new timeline with given name. 139 | |`AppendToTimeline(clip1, clip2, ...)` |`Bool` |Appends specified MediaPoolItem objects in the current timeline. Returns True if successful. 140 | |`AppendToTimeline([clips])` |`Bool` |Appends specified MediaPoolItem objects in the current timeline. Returns True if successful. 141 | |`AppendToTimeline([{clipInfo}, ...])` |`Bool` |Appends list of clipInfos specified as a dict of "mediaPoolItem", "startFrame" (int), "endFrame" (int). 142 | |`CreateTimelineFromClips(name, clip1, clip2,...)`|`Timeline` |Creates a new timeline with specified name, and appends the specified MediaPoolItem objects. 143 | |`CreateTimelineFromClips(name, [clips])` |`Timeline` |Creates a new timeline with specified name, and appends the specified MediaPoolItem objects. 144 | |`CreateTimelineFromClips(name, [{clipInfo}])` |`Timeline` |Creates a new timeline with specified name, appending the list of clipInfos specified as a dict of "mediaPoolItem", "startFrame" (int), "endFrame" (int). 145 | |`ImportTimelineFromFile(filePath)` |`Timeline` |Creates timeline based on parameters within given file. 146 | |`GetCurrentFolder()` |`Folder` |Returns currently selected Folder. 147 | |`SetCurrentFolder(Folder)` |`Bool` |Sets current folder by given Folder. 148 | |`DeleteClips([clips])` |`Bool` |Deletes the specified clips in the media pool 149 | |`DeleteFolders([subfolders])` |`Bool` |Deletes the specified subfolders in the media pool 150 | |`MoveClips([clips], targetFolder)` |`Bool` |Moves specified clips to target folder. 151 | |`MoveFolders([folders], targetFolder)` |`Bool` |Moves specified folders to target folder. 152 | |=== 153 | 154 | ### Folder 155 | 156 | |--- 157 | | Method | Return Type | Comment 158 | |--- 159 | | `GetClipList()` |`[clips...]` |Returns a list of clips (items) within the folder. 160 | | `GetName()` |`string` |Returns user-defined name of the folder. 161 | | `GetSubFolderList()` |`[folders...]` |Returns a list of subfolders in the folder. 162 | |~~`GetClips()`~~ |`{clips...}` | Returns a dict of clips (items) within the folder. 163 | |~~`GetSubFolders()`~~ |`{folders...}` | Returns a dict of subfolders in the folder. 164 | |=== 165 | 166 | 167 | ### MediaPoolItem 168 | 169 | |--- 170 | | Method | Return Type | Comment 171 | |--- 172 | |`GetMetadata(metadataType)` |`{metadata}` | Returns a dict (metadata type -> metadata value). If parameter is not specified returns all set metadata parameters. 173 | |`SetMetadata(metadataType, metadataValue)` |`Bool` | Sets metadata by given type and value. Returns True if successful. 174 | |`GetMediaId()` |`string` | Returns a unique ID name related to MediaPoolItem. 175 | |`AddMarker(frameId, color, name, note, duration)` |`Bool` | Creates a new marker at given frameId position and with given marker information. 176 | |`GetMarkers()` |`{markers...}` | Returns a dict (frameId -> {information}) of all markers and dicts with their information. Example of output format: `{96.0: {'color': 'Green', 'duration': 1.0, 'note': '', 'name': 'Marker 1'}, ...}`. In the above example - there is one `Green` marker at offset 96 (position of the marker). 177 | |`DeleteMarkersByColor(color)` |`Bool` | Delete all markers of the specified color from the media pool item. "All" as argument deletes all color markers. 178 | |`DeleteMarkerAtFrame(frameNum)` |`Bool` | Delete marker at frame number from the media pool item. 179 | |`AddFlag(color)` |`Bool` | Adds a flag with given color (text). 180 | |`GetFlagList()` |`[colors...]` | Returns a list of flag colors assigned to the item. 181 | |`ClearFlags(color)` |`Bool` | Clears the flag of specified color from an item. If "All" argument is provided, all flags will be cleared. 182 | |~~`GetFlags()`~~ | `{colors...}` | Returns a dict of flag colors assigned to the item. 183 | |`GetClipColor()` |`string` | Returns an item color as a string. 184 | |`SetClipColor(colorName)` |`Bool` | Sets color of an item based on the colorName (string). 185 | |`ClearClipColor()` |`Bool` | Clears clip color of an item. 186 | |`GetClipProperty(propertyName)` |`{clipProperties}` | Returns a dict (property name -> property value) of an item. If no argument is provided, all clip properties will be returned. Check the section below for more information. 187 | |`SetClipProperty(propertyName, propertyValue)` |`Bool` | Sets into given propertyName (string) propertyValue (string). Check the section below for more information. 188 | |=== 189 | 190 | 191 | ### Timeline 192 | 193 | |--- 194 | | Method | Return Type | Comment 195 | |--- 196 | |`GetName()` |`string` | Returns user-defined name of the timeline. 197 | |`SetName(timelineName)` |`Bool` | Sets timeline name is timelineName (text) is unique. 198 | |`GetStartFrame()` |`int` | Returns frame number at the start of timeline. 199 | |`GetEndFrame()` |`int` | Returns frame number at the end of timeline. 200 | |`GetTrackCount(trackType)` |`int` | Returns a number of track based on specified track type ("audio", "video" or "subtitle"). 201 | |`GetItemListInTrack(trackType, index)` |`[items...]` | Returns a list of Timeline items on the video or audio track (based on trackType) at specified index. 1 <= index <= GetTrackCount(trackType). 202 | |`AddMarker(frameId, color, name, note, duration)` |`Bool` | Creates a new marker at given frameId position and with given marker information. 203 | |`GetMarkers()` |`{markers...}` | Returns a dict (frameId -> {information}) of all markers and dicts with their information. Example of output format: `{96.0: {'color': 'Green', 'duration': 1.0, 'note': '', 'name': 'Marker 1'}, ...}` In the above example - there is one 'Green' marker at offset 96 (position of the marker) 204 | |`DeleteMarkersByColor(color)` |`Bool` | Delete all markers of the specified color from the timeline. "All" as argument deletes all color markers. 205 | |`DeleteMarkerAtFrame(frameNum)` |`Bool` | Delete marker at frame number from the timeline. 206 | |`ApplyGradeFromDRX(path, gradeMode, item1, item2, ...)` |`Bool` | Loads a still from given file path (string) and applies grade to Timeline Items with gradeMode (int): 0 - "No keyframes", 1 - "Source Timecode aligned", 2 - "Start Frames aligned". 207 | |`ApplyGradeFromDRX(path, gradeMode, [items])` |`Bool` | Loads a still from given file path (string) and applies grade to Timeline Items with gradeMode (int): 0 - "No keyframes", 1 - "Source Timecode aligned", 2 - "Start Frames aligned". 208 | |`GetCurrentTimecode()` |`string` | Returns a string representing a timecode for current position of the timeline, while on Cut, Edit, Color and Deliver page. 209 | |`GetCurrentVideoItem()` |`item` | Returns current video timeline item. 210 | |`GetCurrentClipThumbnailImage()` |`{thumbnailData}` | Returns a dict (keys "width", "height", "format" and "data") with data containing raw thumbnail image data (RGB 8-bit image data encoded in base64 format) for current media in the Color Page. Example is provided in 6_get_current_media_thumbnail.py in Example folder. 211 | |`GetTrackName(trackType, trackIndex)` |`string` | Returns name of specified track. trackType is one of "audio", "video" and "subtitle". Valid trackIndex is in the range 1 <= trackIndex <= GetTrackCount(trackType). 212 | |`SetTrackName(trackType, trackIndex, name)` |`Bool` | Sets name of specified track. trackType is one of "audio", "video" and "subtitle". Valid trackIndex is in the range 1 <= trackIndex <= GetTrackCount(trackType). 213 | |~~`GetItemsInTrack(trackType, index)`~~ |`{items...}` | Returns a dict of Timeline items on the video or audio track (based on trackType) at specified 214 | |=== 215 | 216 | ### TimelineItem 217 | 218 | |--- 219 | | Method | Return Type | Comment 220 | |--- 221 | |`GetName()` |`string` | Returns a name of the item. 222 | |`GetDuration()` |`int` | Returns a duration of item. 223 | |`GetEnd()` |`int` | Returns a position of end frame. 224 | |`GetFusionCompCount()` |`int` | Returns the number of Fusion compositions associated with the timeline item. 225 | |`GetFusionCompByIndex(compIndex)` |`fusionComp` | Returns Fusion composition object based on given index. 1 <= compIndex <= timelineItem.GetFusionCompCount() 226 | |`GetFusionCompNameList()` |`[names...]` | Returns a list of Fusion composition names associated with the timeline item. 227 | |`GetFusionCompByName(compName)` |`fusionComp` | Returns Fusion composition object based on given name. 228 | |`GetLeftOffset()` |`int` | Returns a maximum extension by frame for clip from left side. 229 | |`GetRightOffset()` |`int` | Returns a maximum extension by frame for clip from right side. 230 | |`GetStart()` |`int` | Returns a position of first frame. 231 | |`AddMarker(frameId, color, name, note, duration)` |`Bool` | Creates a new marker at given frameId position and with given marker information. 232 | |`GetMarkers()` |`{markers...}` | Returns a dict (frameId -> {information}) of all markers and dicts with their information. Example of output format: `{96.0: {'color': 'Green', 'duration': 1.0, 'note': '', 'name': 'Marker 1'}, ...}`. In the above example - there is one 'Green' marker at offset 96 position of the marker) 233 | |`DeleteMarkersByColor(color)` |`Bool` | Delete all markers of the specified color from the timeline item. "All" as argument deletes all color markers. 234 | |`DeleteMarkerAtFrame(frameNum)` |`Bool` | Delete marker at frame number from the timeline item. 235 | |`AddFlag(color)` |`Bool` | Adds a flag with given color (text). 236 | |`GetFlagList()` |`[colors...]` | Returns a list of flag colors assigned to the item. 237 | |`ClearFlags(color)` |`Bool` | Clears the flag of specified color from an item. If "All" argument is provided, all flags will be cleared. 238 | |`GetClipColor()` |`string` | Returns an item color as a string. 239 | |`SetClipColor(colorName)` |`Bool` | Sets color of an item based on the colorName (string). 240 | |`ClearClipColor()` |`Bool` | Clears clip color of an item. 241 | |`AddFusionComp()` |`fusionComp` | Adds a new Fusion composition associated with the timeline item. 242 | |`ImportFusionComp(path)` |`fusionComp` | Imports Fusion composition from given file path by creating and adding a new composition for the item. 243 | |`ExportFusionComp(path, compIndex)` |`Bool` | Exports Fusion composition based on given index into provided file name path. 244 | |`DeleteFusionCompByName(compName)` |`Bool` | Deletes Fusion composition by provided name. 245 | |`LoadFusionCompByName(compName)` |`fusionComp` | Loads Fusion composition by provided name and sets it as active composition. 246 | |`RenameFusionCompByName(oldName, newName)` |`Bool` | Renames Fusion composition by provided name with new given name. 247 | |`AddVersion(versionName, versionType)` |`Bool` | Adds a new Version associated with the timeline item. versionType: 0 - local, 1 - remote. 248 | |`DeleteVersionByName(versionName, versionType)` |`Bool` | Deletes Version by provided name. versionType: 0 - local, 1 - remote. 249 | |`LoadVersionByName(versionName, versionType)` |`Bool` | Loads Version by provided name and sets it as active Version. versionType: 0 - local, 1 - remote. 250 | |`RenameVersionByName(oldName, newName, versionType)` |`Bool` | Renames Version by provided name with new given name. versionType: 0 - local, 1 - remote. 251 | |`GetMediaPoolItem()` |`MediaPoolItem` | Returns a corresponding to the timeline item media pool item if it exists. 252 | |`GetVersionNameList(versionType)` |`[names...]` | Returns a list of version names by provided versionType: 0 - local, 1 - remote. 253 | |`GetStereoConvergenceValues()` |`{keyframes...}` | Returns a dict (offset -> value) of keyframe offsets and respective convergence values. 254 | |`GetStereoLeftFloatingWindowParams()` |`{keyframes...}` | For the LEFT eye -> returns a dict (offset -> dict) of keyframe offsets and respective floating window params. Value at particular offset includes the left, right, top and bottom floating window values. 255 | |`GetStereoRightFloatingWindowParams()` | `{keyframes...}` | For the RIGHT eye -> returns a dict (offset -> dict) of keyframe offsets and respective floating window params. Value at particular offset includes the left, right, top and bottom floating window values. 256 | |`SetLUT(nodeIndex, lutPath)` |`Bool` | Sets LUT on the node mapping the node index provided, 1 <= nodeIndex <= total number of nodes. The lutPath can be a relative path or absolute path. The operation will be successful for valid lut paths that Resolve has already discovered. 257 | |`SetCDL([CDL map])` |`Bool` | Keys of map are: "NodeIndex", "Slope", "Offset", "Power", "Saturation", where 1 <= NodeIndex <= total number of nodes. Example python code - `SetCDL({"NodeIndex" : "1", "Slope" : "0.5 0.4 0.2", "Offset" : "0.4 0.3 0.2", "Power" : "0.6 0.7 0.8", "Saturation" : "0.65"})` 258 | |`AddTake(mediaPoolItem, startFrame, endFrame)` |`Bool` | Adds a new take to take selector. It will initialise this timeline item as take selector if it's not already one. Arguments startFrame and endFrame are optional, and if not specified the entire clip will be added. 259 | |`GetSelectedTakeIndex()` |`int` | Returns the index of currently selected take, or 0 if the clip is not a take selector. 260 | |`GetTakesCount()` |`int` | Returns the number of takes in take selector, or 0 if the clip is not a take selector. 261 | |`GetTakeByIndex(idx)` |`{takeInfo...}` | Returns a dict (keys "startFrame", "endFrame" and "mediaPoolItem") with take info for specified index. 262 | |`DeleteTakeByIndex(idx)` |`Bool` | Deletes a take by index, 1 <= idx <= number of takes. 263 | |`SelectTakeByIndex(idx)` |`Bool` | Selects a take by index, 1 <= idx <= number of takes. 264 | |`FinalizeTake()` |`Bool` | Finalizes take selection. 265 | |`CopyGrades([tgtTimelineItems])` |`Bool` | Copies grade to all the items in tgtTimelineItems list. Returns true on success and false if any error occured. 266 | |~~`GetFusionCompNames()`~~ |`{names...}` | Returns a dict of Fusion composition names associated with the timeline item. 267 | |~~`GetFlags()`~~ |`{colors...}` | Returns a dict of flag colors assigned to the item. 268 | |~~`GetVersionNames(versionType)`~~ |`{names...}` | Returns a dict of version names by provided versionType: 0 - local, 1 - remote. 269 | |=== 270 | 271 | 272 | ## Using a script 273 | 274 | DaVinci Resolve needs to be running for a script to be invoked. 275 | 276 | For a Resolve script to be executed from an external folder, the script needs to know of the API location. 277 | You may need to set the these environment variables to allow for your Python installation to pick up the appropriate dependencies as shown below: 278 | 279 | Mac OS X: 280 | 281 | ```bash 282 | RESOLVE_SCRIPT_API="/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/" 283 | RESOLVE_SCRIPT_LIB="/Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so" 284 | PYTHONPATH="$PYTHONPATH:$RESOLVE_SCRIPT_API/Modules/" 285 | ``` 286 | 287 | Windows: 288 | 289 | ```bash 290 | RESOLVE_SCRIPT_API="%PROGRAMDATA%\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\" 291 | RESOLVE_SCRIPT_LIB="C:\Program Files\Blackmagic Design\DaVinci Resolve\fusionscript.dll" 292 | PYTHONPATH="%PYTHONPATH%;%RESOLVE_SCRIPT_API%\Modules\" 293 | ``` 294 | 295 | Linux: 296 | ```bash 297 | RESOLVE_SCRIPT_API="/opt/resolve/Developer/Scripting/" 298 | RESOLVE_SCRIPT_LIB="/opt/resolve/libs/Fusion/fusionscript.so" 299 | PYTHONPATH="$PYTHONPATH:$RESOLVE_SCRIPT_API/Modules/" 300 | ``` 301 | (Note: For standard ISO Linux installations, the path above may need to be modified to refer to /home/resolve instead of /opt/resolve) 302 | 303 | 304 | As with Fusion scripts, Resolve scripts can also be invoked via the menu and the Console. 305 | 306 | On startup, DaVinci Resolve scans the Utility Scripts directory and enumerates the scripts found in the Script application menu. Placing your script in this folder and invoking it from this menu is 307 | the easiest way to use scripts. The Utility Scripts folder is located in: 308 | ---- 309 | Mac OS X: /Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Comp/ 310 | Windows: %APPDATA%\Blackmagic Design\DaVinci Resolve\Fusion\Scripts\Comp\ 311 | Linux: /opt/resolve/Fusion/Scripts/Comp/ (or /home/resolve/Fusion/Scripts/Comp/ depending on installation) 312 | ---- 313 | 314 | The interactive Console window allows for an easy way to execute simple scripting commands, to query or modify properties, and to test scripts. The console accepts commands in Python 2.7, Python 3.6 315 | and Lua and evaluates and executes them immediately. For more information on how to use the Console, please refer to the DaVinci Resolve User Manual. 316 | 317 | This example Python script creates a simple project: 318 | 319 | 320 | ```python 321 | #!/usr/bin/env python 322 | import DaVinciResolveScript as dvr_script 323 | resolve = dvr_script.scriptapp("Resolve") 324 | fusion = resolve.Fusion() 325 | projectManager = resolve.GetProjectManager() 326 | projectManager.CreateProject("Hello World") 327 | ``` 328 | 329 | The resolve object is the fundamental starting point for scripting via Resolve. As a native object, it can be inspected for further scriptable properties - using table iteration and "getmetatable" 330 | in Lua and dir, help etc in Python (among other methods). A notable scriptable object above is fusion - it allows access to all existing Fusion scripting functionality. 331 | 332 | 333 | ## Running DaVinci Resolve in headless mode 334 | 335 | DaVinci Resolve can be launched in a headless mode without the user interface using the -nogui command line option. When DaVinci Resolve is launched using this option, the user interface is disabled. 336 | However, the various scripting APIs will continue to work as expected. 337 | 338 | 339 | 340 | ## List and Dict Data Structures 341 | Beside primitive data types, Resolve's Python API mainly uses list and dict data structures. Lists are denoted by [ ... ] and dicts are denoted by { ... } above. 342 | As Lua does not support list and dict data structures, the Lua API implements "list" as a table with indices, e.g. { [1] = listValue1, [2] = listValue2, ... }. 343 | Similarly the Lua API implements "dict" as a table with the dictionary key as first element, e.g. { [dictKey1] = dictValue1, [dictKey2] = dictValue2, ... }. 344 | 345 | 346 | ## Looking up Project and Clip properties 347 | 348 | This section covers additional notes for the functions "Project:GetSetting", "Project:SetSetting", "MediaPoolItem:GetClipProperty" and "MediaPoolItem:SetClipProperty". These functions are used to get 349 | and set properties otherwise available to the user through the Project Settings and the Clip Attributes dialogs. 350 | 351 | The functions follow a key-value pair format, where each property is identified by a key (the settingName or propertyName parameter) and possesses a value (typically a text value). Keys and values are 352 | designed to be easily correlated with parameter names and values in the Resolve UI. Explicitly enumerated values for some parameters are listed below. 353 | 354 | Some properties may be read only - these include intrinsic clip properties like date created or sample rate, and properties that can be disabled in specific application contexts (e.g. custom colorspaces 355 | in an ACES workflow, or output sizing parameters when behavior is set to match timeline) 356 | 357 | ### Getting Values 358 | Invoke `Project:GetSetting` or "MediaPoolItem:GetClipProperty" with the appropriate property key. To get a snapshot of all queryable properties (keys and values), you can call "Project:GetSetting" or 359 | "MediaPoolItem:GetClipProperty" without parameters (or with a NoneType or a blank property key). Using specific keys to query individual properties will be faster. Note that getting a property using an 360 | invalid key will return a trivial result. 361 | 362 | ### Setting Values 363 | Invoke "Project:SetSetting" or "MediaPoolItem:SetClipProperty" with the appropriate property key and a valid value. When setting a parameter, please check the return value to ensure the success of the 364 | operation. You can troubleshoot the validity of keys and values by setting the desired result from the UI and checking property snapshots before and after the change. 365 | 366 | The following Project properties have specifically enumerated values: 367 | 368 | superScale:: 369 | The property value is an enumerated integer between 0 and 3 with these meanings: 0=Auto, 1=no scaling, and 2, 3 and 4 represent the Super Scale multipliers 2x, 3x and 4x. + 370 | Affects: 371 | * x = Project:GetSetting('superScale') and Project:SetSetting('superScale', x) 372 | 373 | timelineFrameRate:: 374 | The property value is one of the frame rates available to the user in project settings under "Timeline frame rate" option. Drop Frame can be configured for supported frame rates by appending the frame rate with "DF", e.g. "29.97 DF" will enable drop frame and "29.97" will disable drop frame + 375 | Affects: 376 | * x = Project:GetSetting('timelineFrameRate') and Project:SetSetting('timelineFrameRate', x) 377 | 378 | 379 | The following Clip properties have specifically enumerated values: 380 | superScale:: The property value is an enumerated integer between 1 and 3 with these meanings: 1=no scaling, and 2, 3 and 4 represent the Super Scale multipliers 2x, 3x and 4x. 381 | Affects: 382 | * x = MediaPoolItem:GetClipProperty('Super Scale') and MediaPoolItem:SetClipProperty('Super Scale', x) 383 | -------------------------------------------------------------------------------- /examples/lua/1_sorted_timeline_from_folder.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Example DaVinci Resolve script: 3 | Based on a given media folder path, this script creates a new project, a default timeline and appends clips into the timeline sorted by name 4 | 5 | Inputs: 6 | - project name 7 | - project framerate 8 | - project width, in pixels 9 | - project height, in pixels 10 | - path to media 11 | --]] 12 | 13 | if table.getn(arg) < 5 then 14 | print("input parameters for scripts are [project name] [framerate] [width] [height] [path to media]") 15 | os.exit() 16 | end 17 | 18 | projectName = arg[1] 19 | framerate = arg[2] 20 | width = arg[3] 21 | height = arg[4] 22 | mediaPath = arg[5] 23 | 24 | --[[ 25 | Create project and set parameters: 26 | --]] 27 | resolve = Resolve() 28 | projectManager = resolve:GetProjectManager() 29 | project = projectManager:CreateProject(projectName) 30 | 31 | if not project then 32 | print("Unable to create a project '"..projectName.."'") 33 | os.exit() 34 | end 35 | 36 | project:SetSetting("timelineFrameRate", tostring(framerate)) 37 | project:SetSetting("timelineResolutionWidth", tostring(width)) 38 | project:SetSetting("timelineResolutionHeight", tostring(height)) 39 | 40 | --[[ 41 | Add folder contents to Media Pool: 42 | --]] 43 | mediapool = project:GetMediaPool() 44 | rootFolder = mediapool:GetRootFolder() 45 | clips = resolve:GetMediaStorage():AddItemsToMediaPool(mediaPath) 46 | 47 | --[[ 48 | Create timeline: 49 | --]] 50 | timelineName = "Timeline 1" 51 | timeline = mediapool:CreateEmptyTimeline(timelineName) 52 | if not timeline then 53 | print("Unable to create timeline '"..timelineName.."'") 54 | os.exit() 55 | end 56 | 57 | --[[ 58 | Sort by name 59 | --]] 60 | table.sort(clips, function(a,b) return a:GetClipProperty("File Name")["File Name"] < b:GetClipProperty("File Name")["File Name"] end) 61 | 62 | for clipIndex in pairs(clips) do 63 | mediapool:AppendToTimeline(clips[clipIndex]) 64 | end 65 | 66 | projectManager:SaveProject() 67 | 68 | print("'"..projectName.."' has been added") 69 | -------------------------------------------------------------------------------- /examples/lua/2_compositions_from_timeline_clips.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Example DaVinci Resolve script: 3 | Add composition to currently open timeline to timeline clips what do not have any compositions yet 4 | 5 | Get currently open project 6 | --]] 7 | resolve = Resolve() 8 | projectManager = resolve:GetProjectManager() 9 | project = projectManager:GetCurrentProject() 10 | 11 | if not project then 12 | print("No project is loaded") 13 | os.exit() 14 | end 15 | 16 | --[[ 17 | Get current timeline. If no current timeline try to load it from timeline list 18 | --]] 19 | 20 | timeline = project:GetCurrentTimeline() 21 | if not timeline then 22 | if project:GetTimelineCount() > 0 then 23 | timeline = project:GetTimelineByIndex(1) 24 | project:SetCurrentTimeline(timeline) 25 | end 26 | end 27 | 28 | if not timeline then 29 | print("Current project has no timelines") 30 | os.exit() 31 | end 32 | 33 | --[[ 34 | Add compositions for all clips in timeline 35 | --]] 36 | timelineVideoTrackCount = timeline:GetTrackCount("video") 37 | 38 | for index = 1, timelineVideoTrackCount, 1 do 39 | local clips = timeline:GetItemsInTrack("video", index) 40 | for clipIdx in pairs(clips) do 41 | if clips[clipIdx]:GetFusionCompCount() < 1 then 42 | clips[clipIdx]:AddFusionComp() 43 | end 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /examples/lua/3_grade_and_render_all_timelines.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Example DaVinci Resolve script: 3 | Load a still from DRX file, apply the still to all clips in all timelines. Set render format and codec, add render jobs for all timelines, render to specified path and wait for rendering completion. 4 | Once render is complete, delete all jobs 5 | --]] 6 | 7 | local function sleep(n) 8 | os.execute("sleep " .. tonumber(n)) 9 | end 10 | 11 | local function TableConcat(t1,t2) 12 | for i=1, #t2 do 13 | t1[#t1+1] = t2[i] 14 | end 15 | return t1 16 | end 17 | 18 | local function AddTimelineToRender( project, timeline, presetName, targetDirectory, renderFormat, renderCodec ) 19 | project:SetCurrentTimeline(timeline) 20 | project:LoadRenderPreset(presetName) 21 | 22 | if not project:SetCurrentRenderFormatAndCodec(renderFormat, renderCodec) then 23 | return false 24 | end 25 | 26 | local renderSettings = {} 27 | renderSettings["SelectAllFrames"] = 1 28 | renderSettings["TargetDir"] = targetDirectory 29 | 30 | project:SetRenderSettings(renderSettings) 31 | return project:AddRenderJob() 32 | end 33 | 34 | local function RenderAllTimelines( resolve, presetName, targetDirectory, renderFormat, renderCodec ) 35 | projectManager = resolve:GetProjectManager() 36 | project = projectManager:GetCurrentProject() 37 | if not project then 38 | return false 39 | end 40 | 41 | resolve:OpenPage("Deliver") 42 | local timelineCount = project:GetTimelineCount() 43 | 44 | for index = 1, timelineCount, 1 do 45 | if not AddTimelineToRender(project, project:GetTimelineByIndex(index), presetName, targetDirectory, renderFormat, renderCodec) then 46 | return false 47 | end 48 | end 49 | 50 | return project:StartRendering() 51 | end 52 | 53 | local function IsRenderingInProgress( resolve ) 54 | projectManager = resolve:GetProjectManager() 55 | project = projectManager:GetCurrentProject() 56 | if not project then 57 | return false 58 | end 59 | 60 | return project:IsRenderingInProgress() 61 | end 62 | 63 | local function WaitForRenderingCompletion( resolve ) 64 | while IsRenderingInProgress(resolve) do 65 | sleep(1) 66 | end 67 | end 68 | 69 | local function ApplyDRXToAllTimelineClips( timeline, path, gradeMode ) 70 | gradeMode = gradeMode or 0 71 | 72 | local clips = {} 73 | 74 | local trackCount = timeline:GetTrackCount("video") 75 | for index = 1, trackCount, 1 do 76 | TableConcat(clips, timeline:GetItemsInTrack("video", index)) 77 | end 78 | 79 | return timeline:ApplyGradeFromDRX(path, tonumber(gradeMode), clips) 80 | end 81 | 82 | local function ApplyDRXToAllTimelines( resolve, path, gradeMode ) 83 | gradeMode = gradeMode or 0 84 | 85 | projectManager = resolve:GetProjectManager() 86 | project = projectManager:GetCurrentProject() 87 | if not project then 88 | return false 89 | end 90 | 91 | local timelineCount = project:GetTimelineCount() 92 | 93 | for index = 1, timelineCount, 1 do 94 | local timeline = project:GetTimelineByIndex(index) 95 | project:SetCurrentTimeline(timeline) 96 | if not ApplyDRXToAllTimelineClips(timeline, path, gradeMode) then 97 | return false 98 | end 99 | end 100 | return true 101 | end 102 | 103 | local function DeleteAllRenderJobs( resolve ) 104 | projectManager = resolve:GetProjectManager() 105 | project = projectManager:GetCurrentProject() 106 | project:DeleteAllRenderJobs() 107 | return 108 | end 109 | 110 | --[[ 111 | Inputs: 112 | - DRX file to import grade still and apply it for clips 113 | - grade mode (0, 1 or 2) 114 | - preset name for rendering 115 | - render path 116 | - render format 117 | - render codec 118 | --]] 119 | 120 | if table.getn(arg) < 6 then 121 | print("input parameters for scripts are [drx file path] [grade mode] [render preset name] [render path] [render format] [render codec]") 122 | os.exit() 123 | end 124 | 125 | drxPath = arg[1] 126 | gradeMode = arg[2] 127 | renderPresetName = arg[3] 128 | renderPath = arg[4] 129 | renderFormat = arg[5] 130 | renderCodec = arg[6] 131 | 132 | --[[ 133 | Get currently open project 134 | --]] 135 | resolve = Resolve() 136 | 137 | if not ApplyDRXToAllTimelines(resolve, drxPath, gradeMode) then 138 | print("Unable to apply a still from drx file to all timelines") 139 | os.exit() 140 | end 141 | 142 | if not RenderAllTimelines(resolve, renderPresetName, renderPath, renderFormat, renderCodec) then 143 | print("Unable to set all timelines for rendering") 144 | os.exit() 145 | end 146 | 147 | WaitForRenderingCompletion(resolve) 148 | 149 | DeleteAllRenderJobs(resolve) 150 | 151 | print("Rendering is completed.") 152 | -------------------------------------------------------------------------------- /examples/lua/4_display_project_and_folder_tree.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Example DaVinci Resolve script: 3 | Draw folder and project tree from project manager window. 4 | --]] 5 | 6 | local function DisplayProjectsWithinFolder( projectManager, folderString, projectString ) 7 | folderString = folderString or "- " 8 | projectString = projectString or " " 9 | 10 | folderString = " "..folderString 11 | projectString = " "..projectString 12 | 13 | local projects = projectManager:GetProjectsInCurrentFolder() 14 | for projectIndex in pairs(projects) do 15 | print(projectString..projects[projectIndex]) 16 | end 17 | 18 | local folders = projectManager:GetFoldersInCurrentFolder() 19 | for folderIndex in pairs(folders) do 20 | print(folderString..folders[folderIndex]) 21 | if projectManager:OpenFolder(folders[folderIndex]) then 22 | DisplayProjectsWithinFolder(projectManager, folderString, projectString) 23 | projectManager:GotoParentFolder() 24 | end 25 | end 26 | end 27 | 28 | local function DisplayProjectTree( resolve ) 29 | projectManager = resolve:GetProjectManager() 30 | projectManager:GotoRootFolder() 31 | print("- Root folder") 32 | DisplayProjectsWithinFolder(projectManager) 33 | end 34 | 35 | resolve = Resolve() 36 | 37 | DisplayProjectTree(resolve) 38 | -------------------------------------------------------------------------------- /examples/lua/5_get_project_information.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Example DaVinci Resolve script: 3 | Display project information: timeline, clips within timelines and media pool structure. 4 | --]] 5 | 6 | local function DisplayTimelineTrack( timeline, trackType, displayShift ) 7 | local trackCount = timeline:GetTrackCount(trackType) 8 | for index = 1, trackCount, 1 do 9 | print(displayShift.."- "..trackType.." "..index) 10 | clips = timeline:GetItemsInTrack(trackType, index) 11 | for clipIndex in pairs(clips) do 12 | print(displayShift.." "..clips[clipIndex]:GetName()) 13 | end 14 | end 15 | end 16 | 17 | local function DisplayTimelineInfo( timeline, displayShift ) 18 | print(displayShift.."- "..timeline:GetName()) 19 | displayShift = " "..displayShift 20 | DisplayTimelineTrack(timeline , "video", displayShift) 21 | DisplayTimelineTrack(timeline , "audio", displayShift) 22 | DisplayTimelineTrack(timeline , "subtitle", displayShift) 23 | return 24 | end 25 | 26 | local function DisplayTimelinesInfo( project ) 27 | print("- Timelines") 28 | local timelineCount = project:GetTimelineCount() 29 | 30 | for index = 1, timelineCount, 1 do 31 | DisplayTimelineInfo(project:GetTimelineByIndex(index), " ") 32 | end 33 | end 34 | 35 | local function DisplayFolderInfo( folder, displayShift ) 36 | print(displayShift.."- "..folder:GetName()) 37 | local clips = folder:GetClips() 38 | for clipIndex in pairs(clips) do 39 | print(displayShift.." "..clips[clipIndex]:GetClipProperty("File Name")["File Name"]) 40 | end 41 | 42 | displayShift = " "..displayShift 43 | 44 | local folders = folder:GetSubFolders() 45 | for folderIndex in pairs(folders) do 46 | DisplayFolderInfo(folders[folderIndex], displayShift) 47 | end 48 | end 49 | 50 | local function DisplayMediaPoolInfo( project ) 51 | mediaPool = project:GetMediaPool() 52 | print("- Media pool") 53 | DisplayFolderInfo(mediaPool:GetRootFolder(), " ") 54 | end 55 | 56 | local function DisplayProjectInfo( project ) 57 | print("-----------") 58 | print("Project '"..project:GetName().."':") 59 | print(" Framerate " .. project:GetSetting("timelineFrameRate")) 60 | print(" Resolution " .. project:GetSetting("timelineResolutionWidth") .. "x" .. project:GetSetting("timelineResolutionHeight")) 61 | 62 | DisplayTimelinesInfo(project) 63 | print("") 64 | DisplayMediaPoolInfo(project) 65 | end 66 | 67 | 68 | resolve = Resolve() 69 | projectManager = resolve:GetProjectManager() 70 | project = projectManager:GetCurrentProject() 71 | 72 | DisplayProjectInfo(project) 73 | -------------------------------------------------------------------------------- /examples/lua/6_get_current_media_thumbnail.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Example DaVinci Resolve script: 3 | Retrieve current media thumbnail from the color page 4 | --]] 5 | 6 | resolve = Resolve() 7 | projectManager = resolve:GetProjectManager() 8 | project = projectManager:GetCurrentProject() 9 | timeline = project:GetCurrentTimeline() 10 | currentMediaThumbnail = timeline:GetCurrentClipThumbnailImage() 11 | width = currentMediaThumbnail["width"] 12 | height = currentMediaThumbnail["height"] 13 | format = currentMediaThumbnail["format"] 14 | imageBase64str = currentMediaThumbnail["data"] 15 | print(" Width of the thumbnail is " .. width .. ", Height is " .. height .. ", Format is " .. format .. "\n Thumbnail image data in base64 is " .. imageBase64str) 16 | -- Need to decode the image from base 64 to retrieve the image just like the python example. 17 | -------------------------------------------------------------------------------- /examples/lua/7_add_subclips_to_timeline.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Example DaVinci Resolve script: 3 | Adds subclips [frame 0 .. 23] to current timeline for all media pool root folder clips 4 | --]] 5 | 6 | resolve = Resolve() 7 | projectManager = resolve:GetProjectManager() 8 | project = projectManager:GetCurrentProject() 9 | mediaPool = project:GetMediaPool() 10 | rootFolder = mediaPool:GetRootFolder() 11 | clips = rootFolder:GetClips() 12 | 13 | for clipIndex in pairs(clips) do 14 | clip = clips[clipIndex] 15 | videoCodec = clip:GetClipProperty()["Video Codec"] 16 | if videoCodec ~= "" then 17 | subClip = {} 18 | subClip["mediaPoolItem"] = clip 19 | subClip["startFrame"] = 0 20 | subClip["endFrame"] = 23 21 | 22 | if mediaPool:AppendToTimeline({ subClip }) then 23 | print("added subclip (first 24 frames) of \"" .. clip:GetName() .. "\" to current timeline.") 24 | end 25 | end 26 | end 27 | 28 | -------------------------------------------------------------------------------- /examples/python/1_sorted_timeline_from_folder.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | """ 5 | Example DaVinci Resolve script: 6 | Based on a given media folder path, this script creates a new project, a default timeline and appends clips into the timeline sorted by name 7 | Example usage: 1_sorted_timeline_from_folder.py project1 24 1920 1080 /Users/username/Movies 8 | """ 9 | 10 | from python_get_resolve import GetResolve 11 | import sys 12 | 13 | # Inputs: 14 | # - project name 15 | # - project framerate 16 | # - project width, in pixels 17 | # - project height, in pixels 18 | # - path to media 19 | if len(sys.argv) < 6: 20 | print("input parameters for scripts are [project name] [framerate] [width] [height] [path to media]") 21 | sys.exit() 22 | 23 | projectName = sys.argv[1] 24 | framerate = sys.argv[2] 25 | width = sys.argv[3] 26 | height = sys.argv[4] 27 | mediaPath = sys.argv[5] 28 | 29 | # Create project and set parameters: 30 | resolve = GetResolve() 31 | projectManager = resolve.GetProjectManager() 32 | project = projectManager.CreateProject(projectName) 33 | 34 | if not project: 35 | print("Unable to create a project '" + projectName + "'") 36 | sys.exit() 37 | 38 | project.SetSetting("timelineFrameRate", str(framerate)) 39 | project.SetSetting("timelineResolutionWidth", str(width)) 40 | project.SetSetting("timelineResolutionHeight", str(height)) 41 | 42 | # Add folder contents to Media Pool: 43 | mediapool = project.GetMediaPool() 44 | rootFolder = mediapool.GetRootFolder() 45 | clips = resolve.GetMediaStorage().AddItemListToMediaPool(mediaPath) 46 | 47 | # Create timeline: 48 | timelineName = "Timeline 1" 49 | timeline = mediapool.CreateEmptyTimeline(timelineName) 50 | if not timeline: 51 | print("Unable to create timeline '" + timelineName + "'") 52 | sys.exit() 53 | 54 | # Sort by name 55 | clips = sorted(clips, key = lambda clip : clip.GetClipProperty("File Name")["File Name"]) 56 | 57 | for clip in clips: 58 | mediapool.AppendToTimeline(clip) 59 | 60 | projectManager.SaveProject() 61 | 62 | print("'" + projectName + "' has been added") 63 | -------------------------------------------------------------------------------- /examples/python/2_compositions_from_timeline_clips.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | """ 5 | Example DaVinci Resolve script: 6 | Add composition to currently open timeline to timeline clips what do not have any compositions yet 7 | Example usage: 2_compositions_from_timeline_clips.py 8 | """ 9 | 10 | from python_get_resolve import GetResolve 11 | import sys 12 | 13 | # Get currently open project 14 | resolve = GetResolve() 15 | projectManager = resolve.GetProjectManager() 16 | project = projectManager.GetCurrentProject() 17 | 18 | if not project: 19 | print("No project is loaded") 20 | sys.exit() 21 | 22 | # Get current timeline. If no current timeline try to load it from timeline list 23 | timeline = project.GetCurrentTimeline() 24 | if not timeline: 25 | if project.GetTimelineCount() > 0: 26 | timeline = project.GetTimelineByIndex(1) 27 | project.SetCurrentTimeline(timeline) 28 | 29 | if not timeline: 30 | print("Current project has no timelines") 31 | sys.exit() 32 | 33 | # add compositions for all clips in timeline 34 | timelineVideoTrackCount = timeline.GetTrackCount("video") 35 | 36 | for i in range(int(timelineVideoTrackCount)): 37 | clips = timeline.GetItemListInTrack("video", i + 1) 38 | for clip in clips: 39 | if clip.GetFusionCompCount() < 1: 40 | clip.AddFusionComp() 41 | -------------------------------------------------------------------------------- /examples/python/3_grade_and_render_all_timelines.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example DaVinci Resolve script: 5 | Load a still from DRX file, apply the still to all clips in all timelines. Set render format and codec, add render jobs for all timelines, render to specified path and wait for rendering completion. 6 | Once render is complete, delete all jobs 7 | Example usage: 3_grade_and_render_all_timelines.py /Users/username/Pictures/Still_1.1.1.dpx 0 "ProRes Master" /Users/username/Movies/Render mov ProRes422HQ 8 | """ 9 | 10 | from python_get_resolve import GetResolve 11 | import sys 12 | import time 13 | 14 | def AddTimelineToRender( project, timeline, presetName, targetDirectory, renderFormat, renderCodec ): 15 | project.SetCurrentTimeline(timeline) 16 | project.LoadRenderPreset(presetName) 17 | 18 | if not project.SetCurrentRenderFormatAndCodec(renderFormat, renderCodec): 19 | return False 20 | 21 | project.SetRenderSettings({"SelectAllFrames" : 1, "TargetDir" : targetDirectory}) 22 | return project.AddRenderJob() 23 | 24 | def RenderAllTimelines( resolve, presetName, targetDirectory, renderFormat, renderCodec ): 25 | projectManager = resolve.GetProjectManager() 26 | project = projectManager.GetCurrentProject() 27 | if not project: 28 | return False 29 | 30 | resolve.OpenPage("Deliver") 31 | timelineCount = project.GetTimelineCount() 32 | 33 | for index in range (0, int(timelineCount)): 34 | if not AddTimelineToRender(project, project.GetTimelineByIndex(index + 1), presetName, targetDirectory, renderFormat, renderCodec): 35 | return False 36 | return project.StartRendering() 37 | 38 | def IsRenderingInProgress( resolve ): 39 | projectManager = resolve.GetProjectManager() 40 | project = projectManager.GetCurrentProject() 41 | if not project: 42 | return False 43 | 44 | return project.IsRenderingInProgress() 45 | 46 | def WaitForRenderingCompletion( resolve ): 47 | while IsRenderingInProgress(resolve): 48 | time.sleep(1) 49 | return 50 | 51 | def ApplyDRXToAllTimelineClips( timeline, path, gradeMode = 0 ): 52 | trackCount = timeline.GetTrackCount("video") 53 | 54 | for index in range (1, int(trackCount) + 1): 55 | clips = timeline.GetItemListInTrack("video", index) 56 | if not timeline.ApplyGradeFromDRX(path, int(gradeMode), clips): 57 | return False 58 | 59 | return True 60 | 61 | def ApplyDRXToAllTimelines( resolve, path, gradeMode = 0 ): 62 | projectManager = resolve.GetProjectManager() 63 | project = projectManager.GetCurrentProject() 64 | if not project: 65 | return False 66 | timelineCount = project.GetTimelineCount() 67 | 68 | for index in range (0, int(timelineCount)): 69 | timeline = project.GetTimelineByIndex(index + 1) 70 | project.SetCurrentTimeline( timeline ) 71 | if not ApplyDRXToAllTimelineClips(timeline, path, gradeMode): 72 | return False 73 | return True 74 | 75 | def DeleteAllRenderJobs( resolve ): 76 | projectManager = resolve.GetProjectManager() 77 | project = projectManager.GetCurrentProject() 78 | project.DeleteAllRenderJobs() 79 | return 80 | 81 | # Inputs: 82 | # - DRX file to import grade still and apply it for clips 83 | # - grade mode (0, 1 or 2) 84 | # - preset name for rendering 85 | # - render path 86 | # - render format 87 | # - render codec 88 | if len(sys.argv) < 7: 89 | print("input parameters for scripts are [drx file path] [grade mode] [render preset name] [render path] [render format] [render codec]") 90 | sys.exit() 91 | 92 | drxPath = sys.argv[1] 93 | gradeMode = sys.argv[2] 94 | renderPresetName = sys.argv[3] 95 | renderPath = sys.argv[4] 96 | renderFormat = sys.argv[5] 97 | renderCodec = sys.argv[6] 98 | 99 | # Get currently open project 100 | resolve = GetResolve() 101 | 102 | if not ApplyDRXToAllTimelines(resolve, drxPath, gradeMode): 103 | print("Unable to apply a still from drx file to all timelines") 104 | sys.exit() 105 | 106 | if not RenderAllTimelines(resolve, renderPresetName, renderPath, renderFormat, renderCodec): 107 | print("Unable to set all timelines for rendering") 108 | sys.exit() 109 | 110 | WaitForRenderingCompletion(resolve) 111 | 112 | DeleteAllRenderJobs(resolve) 113 | 114 | print("Rendering is completed.") 115 | -------------------------------------------------------------------------------- /examples/python/4_display_project_and_folder_tree.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example DaVinci Resolve script: 5 | Draw folder and project tree from project manager window. 6 | Example usage: 4_display_project_and_folder_tree.py 7 | """ 8 | 9 | from python_get_resolve import GetResolve 10 | 11 | def DisplayProjectsWithinFolder( projectManager, folderString = "- ", projectString = " " ): 12 | folderString = " " + folderString 13 | projectString = " " + projectString 14 | 15 | projects = sorted(projectManager.GetProjectListInCurrentFolder()) 16 | for projectName in projects: 17 | print(projectString + projectName) 18 | 19 | folders = sorted(projectManager.GetFolderListInCurrentFolder()) 20 | for folderName in folders: 21 | print(folderString + folderName) 22 | if projectManager.OpenFolder(folderName): 23 | DisplayProjectsWithinFolder(projectManager, folderString, projectString) 24 | projectManager.GotoParentFolder() 25 | return 26 | 27 | def DisplayProjectTree( resolve ): 28 | projectManager = resolve.GetProjectManager() 29 | projectManager.GotoRootFolder() 30 | print("- Root folder") 31 | DisplayProjectsWithinFolder(projectManager) 32 | return 33 | 34 | # Get currently open project 35 | resolve = GetResolve() 36 | 37 | DisplayProjectTree(resolve) 38 | -------------------------------------------------------------------------------- /examples/python/5_get_project_information.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example DaVinci Resolve script: 5 | Display project information: timeline, clips within timelines and media pool structure. 6 | Example usage: 5_get_project_information.py 7 | """ 8 | 9 | from python_get_resolve import GetResolve 10 | 11 | def DisplayTimelineTrack( timeline, trackType, displayShift ): 12 | trackCount = timeline.GetTrackCount(trackType) 13 | for index in range (1, int(trackCount) + 1): 14 | print(displayShift + "- " + trackType + " " + str(index)) 15 | clips = timeline.GetItemListInTrack(trackType, index) 16 | for clip in clips: 17 | print(displayShift + " " + clip.GetName()) 18 | return 19 | 20 | def DisplayTimelineInfo( timeline, displayShift ): 21 | print(displayShift + "- " + timeline.GetName()) 22 | displayShift = " " + displayShift 23 | DisplayTimelineTrack(timeline , "video", displayShift) 24 | DisplayTimelineTrack(timeline , "audio", displayShift) 25 | DisplayTimelineTrack(timeline , "subtitle", displayShift) 26 | return 27 | 28 | def DisplayTimelinesInfo( project ): 29 | print("- Timelines") 30 | timelineCount = project.GetTimelineCount() 31 | 32 | for index in range (0, int(timelineCount)): 33 | DisplayTimelineInfo(project.GetTimelineByIndex(index + 1), " ") 34 | return 35 | 36 | def DisplayFolderInfo( folder, displayShift ): 37 | print(displayShift + "- " + folder.GetName()) 38 | clips = folder.GetClipList() 39 | for clip in clips: 40 | print(displayShift + " " + clip.GetClipProperty("File Name")["File Name"]) 41 | 42 | displayShift = " " + displayShift 43 | 44 | folders = folder.GetSubFolderList() 45 | for folder in folders: 46 | DisplayFolderInfo(folder, displayShift) 47 | return 48 | 49 | def DisplayMediaPoolInfo( project ): 50 | mediaPool = project.GetMediaPool() 51 | print("- Media pool") 52 | DisplayFolderInfo(mediaPool.GetRootFolder(), " ") 53 | return 54 | 55 | def DisplayProjectInfo( project ): 56 | print("-----------") 57 | print("Project '" + project.GetName() +"':") 58 | print(" Framerate " + project.GetSetting("timelineFrameRate")) 59 | print(" Resolution " + project.GetSetting("timelineResolutionWidth") + "x" + project.GetSetting("timelineResolutionHeight")) 60 | 61 | DisplayTimelinesInfo(project) 62 | print("") 63 | DisplayMediaPoolInfo(project) 64 | return 65 | 66 | # Get currently open project 67 | resolve = GetResolve() 68 | projectManager = resolve.GetProjectManager() 69 | project = projectManager.GetCurrentProject() 70 | 71 | DisplayProjectInfo(project) 72 | -------------------------------------------------------------------------------- /examples/python/6_get_current_media_thumbnail.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example DaVinci Resolve script: 5 | Display current media thumbnail from the color page using open cv plugin 6 | This example is dependent on opencv2 and numpy, which can be installed using: pip install opencv-python numpy 7 | Example usage: 6_get_current_media_thumbnail.py 8 | """ 9 | 10 | from python_get_resolve import GetResolve 11 | import array 12 | import base64 13 | import cv2 14 | import numpy as np 15 | 16 | # Decode from base64 image string and return cv2 matrix image in BGR format for display 17 | def readb64(base64_string, width, height): 18 | nparr = np.fromstring(base64.b64decode(base64_string), np.uint8) 19 | nparr = nparr.reshape(int(height), int(width), 3) 20 | return cv2.cvtColor(nparr, cv2.COLOR_RGB2BGR) 21 | 22 | if __name__ == "__main__": 23 | resolve = GetResolve() 24 | projectManager = resolve.GetProjectManager() 25 | project = projectManager.GetCurrentProject() 26 | 27 | timeline = project.GetCurrentTimeline() 28 | currentMediaThumbnail = timeline.GetCurrentClipThumbnailImage() 29 | 30 | if (currentMediaThumbnail is None) or (len(currentMediaThumbnail) == 0): 31 | print("There is no current media thumbnail") 32 | 33 | width = currentMediaThumbnail["width"] 34 | height = currentMediaThumbnail["height"] 35 | format = currentMediaThumbnail["format"] # Currently we only have RBG 8 bit format 36 | 37 | print("Width of the thumbnail is " + str(width) + ", Height is " + str(height) + ", Format is " + str(format)) 38 | 39 | imgstring = currentMediaThumbnail["data"] 40 | cvimg = readb64(imgstring, width, height) 41 | cv2.imshow("Current Media Thumbnail", cvimg) 42 | cv2.waitKey() 43 | -------------------------------------------------------------------------------- /examples/python/7_add_subclips_to_timeline.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example DaVinci Resolve script: 5 | Adds subclips [frame 0 .. 23] to current timeline for all media pool root folder clips 6 | Example usage: 7_add_subclips_to_timeline.py 7 | """ 8 | 9 | from python_get_resolve import GetResolve 10 | 11 | if __name__ == "__main__": 12 | resolve = GetResolve() 13 | projectManager = resolve.GetProjectManager() 14 | project = projectManager.GetCurrentProject() 15 | mediaPool = project.GetMediaPool() 16 | rootFolder = mediaPool.GetRootFolder() 17 | clips = rootFolder.GetClipList() 18 | 19 | for clip in clips: 20 | if clip.GetClipProperty()["Video Codec"] != "": 21 | subClip = { 22 | "mediaPoolItem": clip, 23 | "startFrame": 0, 24 | "endFrame": 23, 25 | } 26 | 27 | if mediaPool.AppendToTimeline([ subClip ]): 28 | print("added subclip (first 24 frames) of \"" + clip.GetName() + "\" to current timeline.") 29 | 30 | -------------------------------------------------------------------------------- /examples/python/python_get_resolve.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | This file serves to return a DaVinci Resolve object 5 | """ 6 | 7 | import sys 8 | 9 | def GetResolve(): 10 | try: 11 | # The PYTHONPATH needs to be set correctly for this import statement to work. 12 | # An alternative is to import the DaVinciResolveScript by specifying absolute path (see ExceptionHandler logic) 13 | import DaVinciResolveScript as bmd 14 | except ImportError: 15 | if sys.platform.startswith("darwin"): 16 | expectedPath="/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules/" 17 | elif sys.platform.startswith("win") or sys.platform.startswith("cygwin"): 18 | import os 19 | expectedPath=os.getenv('PROGRAMDATA') + "\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\Modules\\" 20 | elif sys.platform.startswith("linux"): 21 | expectedPath="/opt/resolve/libs/Fusion/Modules/" 22 | 23 | # check if the default path has it... 24 | print("Unable to find module DaVinciResolveScript from $PYTHONPATH - trying default locations") 25 | try: 26 | import imp 27 | bmd = imp.load_source('DaVinciResolveScript', expectedPath+"DaVinciResolveScript.py") 28 | except ImportError: 29 | # No fallbacks ... report error: 30 | print("Unable to find module DaVinciResolveScript - please ensure that the module DaVinciResolveScript is discoverable by python") 31 | print("For a default DaVinci Resolve installation, the module is expected to be located in: "+expectedPath) 32 | sys.exit() 33 | 34 | return bmd.scriptapp("Resolve") 35 | --------------------------------------------------------------------------------