-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoveAroundUtils.py
97 lines (72 loc) · 2.97 KB
/
moveAroundUtils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
path1=r'Y:\MLGroup\shock_test\Group 250 frames to label - C&Y\All 250 frames'
path2=r'Y:\MLGroup\shock_test\Group frames combined ~ 920'
filesList=glob.glob(path1+'/*.png')
allFiles=glob.glob(path2+'/*.png')
allFiles=[os.path.basename(s) for s in allFiles]
filesList=[os.path.basename(s) for s in filesList]
nonUsed=set(allFiles)-set(filesList)
nonUsedOld=[path2+'/'+s for s in nonUsed]
nonUsedNew=[newPath+'/'+s for s in nonUsed]
[os.rename(s) for s in filesList]
newPath='Y:/MLGroup/shock_test/Group 250 frames to label - C&Y/TooChoseFromForCris'
for i,j in enumerate(nonUsedOld):
print(nonUsedOld[i], nonUsedNew[i])
os.rename(nonUsedOld[i], nonUsedNew[i])
if str(aid) in s]
# manipulation for file names
import os
import time
import glob
path = input('path to csv files (eg. C:\\Users\\) :') #C:\Users\Windows\Desktop
path='D:\highspeed_vids\EMX1_for_Tom'
path = os.path.normpath(path)
os.chdir(path)
# rename all the pole video
pole=glob.glob(path + '/**/*pole*.mp4', recursive=True)
for k in range(len(pole)):
rena=os.path.dirname(pole[k])+'\\'
os.rename(pole[k], rena+'00-00-00.000.mp4')
# rename all the files with their n+2 parent directory spltit[-3]
l_dir=[]
files = glob.glob(path + '/**/*.mp4', recursive=True)
for i in range(len(files)):
ldir=os.path.abspath(os.path.dirname(files[i]))
split=files[i].split(os.sep)
rename=ldir+'\\'+split[-3]+'_'+'_'+split[-1]
#rename=ldir+'\\'+str(os.path.getctime(files[i]))+split[-3]+'_'+'_'+split[-1]
os.rename(files[i], rename)
# move all the baseline files to baseline dir
os.makedirs('baseline')
baselinefiles=glob.glob(path + '/**/*baseline*.mp4', recursive=True)
for j in range(len(baselinefiles)):
ren=os.path.join(path, 'baseline')+'\\'
os.rename(baselinefiles[j], ren+os.path.basename(baselinefiles[j]))
# need to modify this to go one more directory up
os.makedirs('outputs')
outputfiles=glob.glob(path + '/**/*output*.mp4', recursive=True)
for j in range(len(outputfiles)):
ren=os.path.join(path, 'outputs')
ldir=os.path.abspath(os.path.dirname(outputfiles[j]))
split=outputfiles[j].split(os.sep)
rename=ren+'\\'+split[-3]+'_'+split[-1]
os.rename(outputfiles[j], rename)
# here have a line processing or calling sweep
#to test subprocess concate
#subprocess.call('ffmpeg -r 10 -i frame%03d.png -r ntsc '+str(out_movie), shell=True
# https://github.com/kkroening/ffmpeg-python
# correct potential error
# rename all the files with their n+2 parent directory spltit[-3]
l_dir=[]
files = glob.glob(path + '/**/*.mp4', recursive=True)
for i in range(len(files)):
ldir=os.path.abspath(os.path.dirname(files[i]))
rename=ldir+'\\'+files[i].split('_')[-1]
#rename=ldir+'\\'+str(os.path.getctime(files[i]))+split[-3]+'_'+'_'+split[-1]
os.rename(files[i], rename)
# remove the files if needed
outputfiles=glob.glob(path + '/**/*output*.mp4', recursive=True)
for j in range(len(outputfiles)):
os.remove(outputfiles[j])
outputfiles=glob.glob(path + '/**/mylist.txt', recursive=True)
for j in range(len(outputfiles)):
os.remove(outputfiles[j])