← All DaVinci Resolve API guides
DaVinci Resolve APIIntermediateAudio

How to Append an Audio File to a DaVinci Resolve Timeline with Python

ImportMedia plus AppendToTimeline with mediaType 2, recordFrame, and trackIndex

Import an audio file into the Media Pool and place it on a specific Timeline audio track at an exact frame position using a clip-info dictionary.

API

Resolve Scripting API

Language

Python

Resolve

19–20+

Requires

Running Resolve

Syntax

result = api_method()

Parameters

  • The relevant arguments are shown in the complete working example below. Validate paths, object types, and required project state before calling the API method.

Returns

Always validate the returned object, list, identifier, or boolean before continuing to the next automation step.

Complete working Python exampleuse it as a starting point for your own script
import os
import sys
from pathlib import Path


def import_resolve_module():
    try:
        import DaVinciResolveScript as dvr
        return dvr
    except ImportError:
        search_paths = [
            os.environ.get("RESOLVE_SCRIPT_API", ""),
            os.environ.get("RESOLVE_MODULES", ""),
            r"C:\\ProgramData\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\Modules",
            "/opt/resolve/Developer/Scripting/Modules",
            "/opt/BlackmagicDesign/DaVinciResolve/Developer/Scripting/Modules",
            "/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules",
            str(Path.home() / "Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules"),
        ]
        for path in search_paths:
            if path and os.path.isdir(path) and path not in sys.path:
                sys.path.append(path)
        import DaVinciResolveScript as dvr
        return dvr


def safe_call(obj, name, *args, **kwargs):
    try:
        fn = getattr(obj, name, None)
        if callable(fn):
            return fn(*args, **kwargs)
    except Exception:
        return None
    return None


def get_project_and_timeline():
    dvr = import_resolve_module()
    resolve = dvr.scriptapp("Resolve")
    if not resolve:
        raise RuntimeError("DaVinci Resolve API is unavailable")

    project_manager = safe_call(resolve, "GetProjectManager")
    project = safe_call(project_manager, "GetCurrentProject") if project_manager else None
    if not project:
        raise RuntimeError("No DaVinci Resolve project is open")

    timeline = safe_call(project, "GetCurrentTimeline")
    if not timeline:
        raise RuntimeError("No active Timeline")

    return resolve, project, timeline


def ensure_audio_track(timeline, track_index: int) -> None:
    count = int(safe_call(timeline, "GetTrackCount", "audio") or 0)
    while count < track_index:
        if not safe_call(timeline, "AddTrack", "audio"):
            raise RuntimeError(f"Could not create audio track A{count + 1}")
        count += 1


def import_first_media_item(media_pool, file_path: str):
    imported = safe_call(media_pool, "ImportMedia", [file_path]) or []
    if not imported:
        raise RuntimeError(f"File was not imported: {file_path}")
    return imported[0]


def append_audio(media_pool, timeline, file_path: str, record_frame: int, track_index: int = 1):
    ensure_audio_track(timeline, track_index)
    media_item = import_first_media_item(media_pool, file_path)
    clip_info = {
        "mediaPoolItem": media_item,
        "startFrame": 0,
        "recordFrame": int(record_frame),
        "trackIndex": int(track_index),
        "mediaType": 2,
    }
    result = safe_call(media_pool, "AppendToTimeline", [clip_info])
    if not result:
        raise RuntimeError("AppendToTimeline did not add the audio clip")
    return result[0] if isinstance(result, list) else result


resolve, project, timeline = get_project_and_timeline()
media_pool = safe_call(project, "GetMediaPool")
item = append_audio(media_pool, timeline, r"D:\\media\\music.wav", record_frame=0, track_index=1)
print("Added audio item:", safe_call(item, "GetName") or item)

Guide

What the example does

The script imports an audio file into the Media Pool and passes a clip-info dictionary to AppendToTimeline. In that dictionary mediaType is set to 2, identifying the placement as audio.

How recordFrame works

recordFrame is the destination position in Timeline frames. If your source timing is expressed in seconds, convert seconds to frames with the current Timeline FPS before constructing the clip-info dictionary.

How trackIndex is handled

trackIndex selects the destination audio track. Before appending the clip, the helper creates missing audio tracks so Resolve is never asked to target an index that is not present.

How the example works

1

Connect to Resolve

Establish a Resolve Scripting API connection and stop early if the application object is unavailable.

2

Validate the current context

Check the active project, Timeline, Media Pool, source paths, or Render Queue state required by this specific operation.

3

Run the core API operation

Execute the operation demonstrated in this guide: how to append an audio file to a davinci resolve timeline with python.

4

Validate the result

Check the returned value before the workflow continues. Resolve methods often signal an unavailable object or failed operation with None, False, or an empty result.

Resolve API notes

  • The source file must exist and use a format supported by DaVinci Resolve.
  • mediaType 2 represents audio in an AppendToTimeline clip-info dictionary.
  • recordFrame is expressed in Timeline frames, not seconds.
  • Add endFrame to clip_info when you need to constrain the source duration explicitly.

Common errors

Resolve API is unavailable

Reason: Resolve is closed or Python cannot import/use DaVinciResolveScript.

Fix: Start Resolve and verify the Developer/Scripting/Modules path from the same Python interpreter used by the script.

The method returns None or False

Reason: A required project, Timeline, clip, preset, path, or application state is missing.

Fix: Validate each input and add explicit result checks after important Resolve API calls.

The script only works on one workstation

Reason: Paths or environment assumptions are hard-coded for a single operating system or machine.

Fix: Move paths into configuration and support the required Windows, Linux, and macOS locations explicitly.

Next step

Continue only after the current operation has returned the expected Resolve object or result.

Related API guides