Skip to content

Instantly share code, notes, and snippets.

@djds23
Last active December 28, 2015 23:49
Show Gist options
  • Save djds23/7581975 to your computer and use it in GitHub Desktop.
Save djds23/7581975 to your computer and use it in GitHub Desktop.
Rename footage '.dpx' files from c500 footage if cables are switched leaving the camera.
'''
This is a script to fix c500 footage that got mixed up.
If the SDI cables are switched leaving the camera entering the recorder
then file names will be incorrect. Files that should be numbed even are odd,
and files that are odd should be even.
Luckily those files are also separated into two different folders.
**Run this script in each folder separately before merging the footage **
**If you merge the footage and then run this script, you will overwrite**
**half of your files, only the even frames will be stored and renamed **
to run:
1) move rename.py to the folder of footage
2) navigate to your footage in the terminal
3) once in your folder, type 'ls' to confirm 'rename.py' is in the directory
4) if its there type 'python rename.py', the filenames in your folder should change almost instantly
Odd becomes even:
DAOL----035_0000001.dpx -> DAOL----035_0000000.dpx
Even becomes odd:
DAOL----035_0000000.dpx -> DAOL----035_0000001.dpx
'''
from os import rename, listdir
starttemplate = 'DAOL----035_' #change this variable to whatever your naming convention is
endtemplate = '.dpx' #should be the file extension, change if different
files = listdir('.') #takes the contents of your current directory and puts it in a variable
print files #Just to provide visual feedback that its working.
def renameclause(source_file):
source = source_file
digits = source[12:-4]
if int(digits)%2==0: #checks if even
newdigits = str(int(digits)+1) #creates a string of the digits + 1
while len(newdigits) != 7: #makes sure the files have 7 digits after the number, adjust for naming conventions if needed
newdigits = '0' + newdigits
newfilename = starttemplate + newdigits + endtemplate #creates the new name
rename(source_file, newfilename) #renames file
elif int(digits)%2!=0: #checks if odd
newdigits = str(int(digits)-1) #creates a string of the digits -1
while len(newdigits) != 7: #makes sure the files have 7 digits after the number, adjust for naming conventions if needed
newdigits = '0' + newdigits
newfilename = starttemplate + newdigits + endtemplate #creates the new name
rename(source_file, newfilename) #renames file
for i in files: #loops through files
if '.dpx' not in i: #checks to see if file is needed, change if naming convention dictates,
print 'nevermind' #nevermind
else:
renameclause(i) #performs rename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment