Old 10-17-2018, 10:11 AM   #1
Crazy Maurice
Human being with feelings
 
Join Date: Nov 2016
Posts: 26
Default Import .mov at original timecode! (help needed!)

Hey all,

I'm trying to make a script that will import a mov at its original timecode and I've run into a few issues/thoughts about Reaper.

At the moment I'm working with video at 59.94fps(I think drop frame) which it looks like reaper doesn't fully support so I've been setting it manually in the framerate section for the project. This coupled with the fact positional information in reascript needs to be in seconds makes it slightly harder (when I do the maths in the conversion part videos can end up a second or more out in 59.94). SO I'm just pretending I'm working at 60fps at the moment.

I've used python as it seems like the best thing to do in terms of using shell comands or ffmpeg etc.

Code:
import os
import re
import math
import pyperclip
from contextlib import contextmanager
from reaper_python import *
from sws_python import *
import time
from ffmpy import FFmpeg
import ffmpy
import subprocess
import easygui
import sys
sys.argv=["Main"]
import tkinter

path = easygui.fileopenbox() #open file dialog
#get timecode from video
timecode=os.popen(('ffprobe -v error -select_streams v:0 -show_entries stream_tags=timecode -of default=noprint_wrappers=1:nokey=1 '+path)).read()

#split timecode into seconds and ms
list = timecode.split (':')
hours = list[0]
minutes = list[1]
seconds = list[2]
mseconds = list[3]
totalsec = (int(hours) * 3600 + int(minutes) * 60 + int(seconds))
totalms = (int(mseconds) * 1000.0 / 60)
print("total = ", totalsec + totalms)


RPR_AddMediaItemToTrack(1) #new media item containing video we just selected
pos = 5
TheTrack=RPR_GetTrack(0,0) #get track 1

NewItem=RPR_AddMediaItemToTrack(TheTrack)

state="<ITEM\n"
state+="POSITION " + str(totalsec) + "." + str(totalms) + "\n"
state+="SNAPOFFS 0\n"
state+="LENGTH 5\n"
state+="LOOP 0\n"
state+="ALLTAKES 0\n"
state+="FADEIN 1 0.002 0 1 0 1\n"
state+="FADEOUT 1 0.002 0 1 0 1\n"
state+="SEL 1\n"
state+="NAME \"" + path + "\"\n"
state+="CHANMODE 1\n"
state+="<SOURCE VIDEO\n"
state+="AUDIO 0\n"
state+="FILE \"" + path + "\"\n"
state+=">\n"
state+=">"

RPR_GetSetItemState2(NewItem,state,len(state),True)

#additional way of getting to right timecode is just pasting into 'jump to position'
pyperclip.copy(timecode) #copy timecode to clipboard
#RPR_Main_OnCommand(40069,0) #paste timecode and jump to place in timeline
#RPR_Main_OnCommand(RPR_NamedCommandLookup("_FNG_MOVE_TO_EDIT"), 0) #move the video to edit cursor position (the timecode!)


RPR_Main_OnCommand(40612,0) #set to original item length


#Snap to nearest frame depending on ms?
if totalms > 500:
  RPR_Main_OnCommand(41173,0) #cursor to item
  RPR_Main_OnCommand(RPR_NamedCommandLookup("_RScbc7a25d9ccadb0cf8d7fe45cb538a3032628267"), 0)
  RPR_Main_OnCommand(RPR_NamedCommandLookup("_FNG_MOVE_TO_EDIT"), 0)       
else:
  RPR_Main_OnCommand(41173,0) #cursor to item
  RPR_Main_OnCommand(RPR_NamedCommandLookup("_RS1d83adf86ba8fb23c68262ee1e07f5566d762395"), 0)
  RPR_Main_OnCommand(RPR_NamedCommandLookup("_FNG_MOVE_TO_EDIT"), 0) 

#RPR_Main_OnCommand(41184,0) #snap to nearest frame
RPR_Main_OnCommand(40688,0) #lock item 
RPR_Main_OnCommand(40289,0) #unselect all items
RPR_UpdateArrange()
What I'm wondering is if there's a way to prevent converting the xx:xx:xx:xx timecode into seconds/ms. My way around this for now is to leave out the converting of timecode and just using pyperclip to copy the xx:xx:xx:xx timecode to clipboard and just paste into the 'jump to time' box and having the item snap to it. Works nicely but I have to press ctrl+v and enter rather than just selecting the file and have it turn up at the right spot.

Anyway hope this makes sense!!
Cheers
Crazy Maurice is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.