Python Scripting with DaVinci Resolve Studio 16 on a Mac

Although DaVinci Resolve scripting capabilities are extremely limited, I found it promising to see that this sort of capability was being developed at BlackMagicDesign.

Learn about Python scripting with DaVinci Resolve Studio 16 in order to automate the repetitive process of reusing your YouTube videos for IGTV.

DaVinci Resolve Python Scripting

Why I Want to Script DaVinci Resolve

My goal was to write a Python script that would repurpose a video for YouTube as an Instagram TV video. If you’re not familiar, IGTV is a vertical video platform, so by placing my horizontal YouTube video on a vertical IGTV background template, I can publish the same video to my Instagram audience.

With full DaVinci Resolve Python scripting capabilities, here is ideally what my video scrip would do.

  1. Create a DaVinci Resolve project
  2. Set project settings such as width, height, and frame rate
  3. Import a rendered video file and IGTV background template (another video file) to the media pool
  4. Add the video file to the timeline on a track above the IGTV background template
  5. Dynamically add a text tile to the timeline on the above track
  6. Load render presets and render the video

While my script can accomplish most of these steps, DaVinci Resolve scripting capabilities are limited. So I had to improvise.

  • DaVinci Resolve scripting does not support dynamic text, so I had to add a track with static text. No getting around this.
  • Additionally, Python scripting only allows you to append clips to a single track (Track 1), so my template had to exist on Track 2 or above.

DaVinci Resolve timeline with multiple tracks

Below find out my scripting setup on my Mac as well as the full text of my Python script.

DaVinci Resolve Python Scripting Setup on a Mac

This tutorial assumes that you have Python 3 installed on your Mac with a virtual environment.

The location of DaVinci Resolve developer stuff is located at /Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer. You can also access this by clicking on Help -> Developer Documentation within DaVinci Resolve.

Either change directory to this path in a terminal, or set the following environment variables according to the README.

RESOLVE_SCRIPT_API="/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/"
RESOLVE_SCRIPT_LIB="/Applications/DaVinci Resolve/DaVinci"

The provided examples in the Scripting/Examples directory are quite helpful, especially the ones highlighted below:


Lastly, I do suggest you read the README.txt as it’s the only official DaVinci Resolve scripting documentation available at this point.

DaVinci Resolve Python Script

This first Python script creates a DaVinci Resolve project, sets settings, and imports the Instagram TV template video file which I designed previously into the media pool. The script also adds the IGTV template clip to the timeline.

from python_get_resolve import GetResolve
import sys

framerate = 30
width = 1080
height = 1920

project_name = 'igtv-template'
igtv_template_path = '/Users/tonyflorida/Movies/igtv/'

# Create project and set parameters
resolve = GetResolve()
project_manager = resolve.GetProjectManager()
project = project_manager.CreateProject(project_name)

if not project:
    print("Unable to create a project")

project.SetSetting("timelineFrameRate", str(framerate))
project.SetSetting("timelineResolutionWidth", str(width))
project.SetSetting("timelineResolutionHeight", str(height))

# Create mediapool and storage objects
mediapool = project.GetMediaPool()
storage = resolve.GetMediaStorage()

# Add video file to media pool
clips = storage.AddItemsToMediaPool(igtv_template_path)
# Create timeline:
timeline_name = "Timeline 1"
timeline = mediapool.CreateEmptyTimeline(timeline_name)
if not timeline:
    print("Unable to create timeline '" + timeline_name + "'")

# Add video file to timeline

While this entire script needs only to be executed once and can easily be configured manually through the DaVinci Resolve interface, this is just for demonstration purposes.

After the addition of a title and a performing manual render through the UI, this is essentially why my template IGTV template looks like.

IGTV template
A basic Instagram TV video template

I made this template project 10 minutes long since that’s the IGTV time limit for small creators at this time.

In order to reuse this template, you must export it via File -> Export Project. I saved my igtv-template.drp file to the igtv subdirectory in my Movies folder.

With the template saved, I wrote the following Python script which copies the template and works out of that project instead.

Essentially, this script goes on to:

  • Load the copied template project
  • Add the video file to the timeline
  • Determine the first and last frame of the video file (MarkIn and MarkOut)
  • Set and load render setting
  • Render out the new video file
from python_get_resolve import GetResolve
import sys
import os
import shutil

if len(sys.argv) < 2:
    print("input parameters for scripts are video_path")
video_path = sys.argv[1]

template_root = '/Users/tonyflorida/Movies/igtv/'
template_file = os.path.join(template_root, 'igtv-template.drp')

video_name = os.path.basename(video_path)
project_name = 'igtv-' +  os.path.splitext(video_name)[0]
project_file = os.path.join(template_root, project_name + '.drp')

# Make a copy of the project template
shutil.copy2(template_file, project_file)

# Load project
resolve = GetResolve()
project_manager = resolve.GetProjectManager()
project = project_manager.LoadProject(project_name)
if not project:
    print("Unable to load project")

# Add video file to Media Pool
mediapool = project.GetMediaPool()
storage = resolve.GetMediaStorage()
clips = storage.AddItemsToMediaPool(video_path)

# Get MarkIn and MarkOut
timeline = project.GetTimelineByIndex(1)
mark_out = timeline.GetItemsInTrack('video', 1)[1].GetEnd()
mark_in = timeline.GetStartFrame()

# Render
target_directory = os.path.dirname(video_path)
render_settings = {"MarkIn":mark_in, "MarkOut":mark_out, "TargetDir":target_directory, "CustomName":project_name}

Please note that I manually created the render preset called igtv-preset by calling the SaveAsNewRenderPreset(presetName)after manually setting the following in the Deliver tab according to the IGTV Help Center:

  • Format: MP4
  • Resolution: Custom
  • Dimensions: 1080 x 1920
  • Frame rate: 30

I saved my Python script as and it can be executed similar to below:

python /Users/tonyflorida/Movies/video.mp4

Don’t Be a Stranger 🙂

If you have any questions about scripting with DaVinci Resolve, please let me know in the comments below. I’m looking forward to future releases of the DaVinci Resolve scripting API, and would love to talk to others in the community who share a similar interest.

Also, you can check out my IGTV videos here, follow me on YouTube, and check out some of my other Python blog posts.

About The Author

With a strong software engineering background, Tony is determined to leverage the internet to positively impact as many people as possible. Discover why Tony quit his dream job to pursue this mission. You can send Tony a message here.

Leave a Comment