KhalidShahin

frameio convert to Vegasaur v0.07.py

Jul 24th, 2022 (edited)
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.65 KB | None | 0 0
  1. #Written by Khalid Shahin - July 24, 2022
  2. #YouTube channel: https://www.youtube.com/c/KhalidSMShahin
  3. #email: khalid@evidence.report
  4.  
  5. import sys
  6. import csv
  7. import math
  8. framerate = 23.976
  9.  
  10. files = ["frameio_export.csv"] #The default file to load, this will be replaced if you dragged and dropped files onto the script, or ran this via command line with arguments
  11.  
  12. if len(sys.argv) > 1:   #If files were dragged and dropped onto the program
  13.     files = sys.argv[1:]
  14.  
  15. def addLeadingZeroes(number, numberOfDigits):
  16.     if len(str(number)) > numberOfDigits:
  17.         #return str(number)
  18.         return "000"
  19.     else:
  20.         return "0"*(numberOfDigits-len(str(number))) + str(number)
  21.  
  22. for filename in files:
  23.     rows = []
  24.     outputrows = []
  25.        
  26.     with open(filename, newline='') as csvfile:
  27.         reader = csv.reader(csvfile, delimiter=',', quotechar='"')
  28.  
  29.         for row in reader:
  30.             rows.append(row)
  31.         headers = rows[0]
  32.         print(headers)
  33.  
  34.     timeStamps = []
  35.     timeCodes = []
  36.     for rowIndex in range(len(rows)):
  37.         row = rows[rowIndex]
  38.         if rowIndex > 0:
  39.             comment = row[headers.index("Comment")]
  40.             while comment[0] == '"' and comment[-1] == '"':
  41.                 comment = comment[1:-1]
  42.             #print(comment)
  43.             if row[headers.index("Commenter")]:
  44.                 commenter = row[headers.index("Commenter")]
  45.                 while commenter[0] == '"' and commenter[-1] == '"':
  46.                     commenter = commenter[1:-1]                
  47.                 commenterAndComment = commenter + ": " + comment
  48.             frame = row[headers.index("Frame")]
  49.             #duration = row[headers.index("Duration")]
  50.             timecode = row[headers.index("Timecode")]
  51.             #timeout = row[headers.index("Time Out")]
  52.             if timecode in timeCodes:
  53.                 startingTimeCode = timecode[-2:]
  54.                 directionChange = 1
  55.                 while timecode in timeCodes:                    
  56.                     if float(timecode[-2:]) < math.floor(framerate):
  57.                         trailing = str(int(timecode[-2:])+(1*directionChange))
  58.                     else:
  59.                         trailing = str(int(startingTimeCode)-1)
  60.                         directionChange = -1
  61.                     trailing = addLeadingZeroes(trailing, 2)
  62.                     timecode = timecode[:-3] + ":" + trailing
  63.                     if timecode not in timeCodes:
  64.                         timeCodes.append(timecode)
  65.                         break
  66.             else:
  67.                 timeCodes.append(timecode)
  68.                
  69.             if float(timecode[-2:]) <= framerate:
  70.                 trailingFrameNumber = str(int((1000/framerate)*float(timecode[-2:])))
  71.                 trailingFrameNumber = addLeadingZeroes(trailingFrameNumber, 3)
  72.                                    
  73.                 timecodeConverted = timecode[:-3] + "." + trailingFrameNumber          
  74.                 outputrows.append([timecodeConverted, "", commenterAndComment])
  75.             else:
  76.                 print("Unexpected frame input")
  77.  
  78.     for x in range(len(outputrows)):
  79.         if x < len(outputrows)-1:
  80.             outputrows[x][1] = outputrows[x+1][0]
  81.         else:
  82.             #Last row, for now I'm going to have the same value for out as in, maybe that will be enough
  83.             outputrows[x][1] = outputrows[x][0]
  84.             pass
  85.        
  86.     #print(outputrows)
  87.     f = open(filename[:-4]+"_converted"+".csv", 'w')
  88.     writer = csv.writer(f, delimiter=',', lineterminator='\n', quotechar='"', quoting=csv.QUOTE_ALL)
  89.     for row in outputrows:
  90.         writer.writerow(row)
  91.     f.close()
  92.  
Add Comment
Please, Sign In to add comment