Created
February 16, 2025 19:59
-
-
Save dodderss/a671665118add04cc094118fdce8af7c to your computer and use it in GitHub Desktop.
Davinci Resolve timecode conversion from WAV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import subprocess | |
import re | |
import os | |
# Edit the following variables as needed | |
usesExtraHour = True | |
systemTimebase = 44100 | |
fps = 24 | |
def get_ffmpeg_metadata(wavfile): | |
result = subprocess.run( | |
["ffmpeg", "-i", wavfile, "-f", "ffmetadata", "-"], | |
capture_output=True, text=True, check=True | |
) | |
return result.stdout | |
def parse_chapters(metadata): | |
chapters = [] | |
timebase = 1/systemTimebase # Defined in metadata | |
for i, match in enumerate(re.finditer(r'START=(\d+)', metadata), start=1): | |
start_frames = int(match.group(1)) | |
seconds = start_frames * timebase | |
frames = round((seconds % 1) * fps) | |
if usesExtraHour: | |
hours = int(seconds // 3600) + 1 | |
else: | |
hours = int(seconds // 3600) | |
timecode = f"{hours:02}:{int((seconds % 3600) // 60):02}:{int(seconds % 60):02}:{frames:02}" | |
print(f"Chapter {i}: {timecode}") | |
chapters.append((i, timecode)) | |
return chapters | |
def generate_edl(timecodes, output_file): | |
with open(output_file, "w") as edl: | |
edl.write("TITLE: Markers\n") | |
edl.write("FCM: NON-DROP FRAME\n\n") | |
for i, (idx, tc) in enumerate(timecodes, start=2): | |
edl.write(f"{i:03} 001 V C {tc} {tc} {tc} {tc}\n") | |
edl.write(f" |C:ResolveColorBlue |M:Marker {idx} |D:1\n\n") | |
def main(): | |
print("Timecode Converter v1.0\n") | |
print("Selected Settings:\n\033[1mFPS = 24\nTimebase = 44100\nExtra Hour = True\n\033[0m") | |
if len(sys.argv) != 2: | |
print("Usage: python3 convert.py input.wav") | |
sys.exit(1) | |
wavfile = sys.argv[1] | |
output_edl = os.path.splitext(wavfile)[0] + ".edl" | |
try: | |
print(f"Reading metadata from {wavfile}...\n") | |
metadata = get_ffmpeg_metadata(wavfile) | |
timecodes = parse_chapters(metadata) | |
generate_edl(timecodes, output_edl) | |
print(f"\nEDL file generated: {output_edl}") | |
print("\nTo open this in Resolve,\n(1) Right click on your timeline in the Media Pool\n(2) Go to Timelines \033[1m(in the context menu)\033[0m, Import\n(3) Click \033[1mTimeline markers from EDL\n\033[0m(4) Select the generated EDL file\n(5) Markers should be imported") | |
except Exception as e: | |
print(f"Error: {e}") | |
sys.exit(1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment