forked from vdcrim/AvsP-macros
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Save Image with frame number.py
105 lines (92 loc) · 3.04 KB
/
Save Image with frame number.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
98
99
100
101
102
103
104
105
# GPo 2018, AvsPmod macro save image
"""
# find source file name for the image name and not the avs or script filename
# search for my pattern and find the source filename (sourceFile, videosource... etc)
# finds also ScriptDir() + "My Video.mkv"
# doesn't override any file
#
# My default AvsPmod templates eg 'mkv, ts, etc..':
#
# SourceFile = ScriptDir() + [***]
# SourceFile = Exist(SourceFile) ? SourceFile : ***
# video=LWLibavVideoSource(SourceFile, cache=False)
# audio=LWLibavAudioSource(SourceFile, cache=False)
# audioDub(video, audio)
"""
import os
import sys
# enable Input for filename if source file not found
# else filename is tab name (script name)
doMessage=True
sourceFile=''
fileName=''
# save as jpg
fnExt='.jpg'
# jpg Quality
jpgQ=90
framenr=''
# enable this for frame number, does not override existing files
framenr= '_' + str(avsp.GetFrameNumber())
# for test
#fileName= avsp.GetScriptFilename()
if not fileName:
sep = '"'
txt = avsp.GetText(index=None, clean=False)
i = txt.lower().find('sourcefile : "')
if i < 0:
i = txt.lower().find('videosource("')
if i < 0:
i = txt.lower().find('source("')
if i > -1:
s = txt[i : len(txt)]
#avsp.MsgBox(s, cancel = True)
a = {}
a = s.split(sep)
if len(a) > 1:
fileName = a[1]
else:
i = txt.lower().find('scriptdir')
if i > -1:
s = txt[i : len(txt)]
a = {}
a = s.split(sep)
if len(a) > 1:
fileName = os.path.join(avsp.GetScriptFilename(propose='general', only='dir'), a[1])
# if source not found, remove the avs ext and hopefully the source have the same name
if not fileName:
fileName=os.path.splitext(avsp.GetScriptFilename(propose='general'))[0]# remove '.avs'
fileName = fileName.encode(sys.getfilesystemencoding())
if os.path.isfile(fileName):
sourceFile = fileName
fileName = os.path.splitext(fileName)[0]
if fileName:
fileName += framenr
else:
dir=avsp.GetScriptFilename(propose='general', only='dir')
fn=os.path.splitext(avsp.GetScriptFilename(propose='general', only='base'))[0] + framenr
if dir:
dir = dir.encode(sys.getfilesystemencoding())
fn = fn.encode(sys.getfilesystemencoding())
if doMessage:
tx = avsp.GetTextEntry(message=dir, default=fn, title='Enter Filename to save the Image', types='text', width=300)
if not tx:
return
else:
tx = fn
fileName = os.path.join(dir, tx)
if fileName:
if os.path.isfile(fileName + fnExt):
i = 2
s = fileName
while os.path.isfile(s + fnExt):
s = fileName + ' (' + str(i) + ')'
i += 1
fileName = s + fnExt
else:
fileName += fnExt
#fileName=fileName.encode(sys.getfilesystemencoding())
#avsp.MsgBox(fileName, cancel = True)
fileName=avsp.SaveImage(filename=fileName, framenum=None, index=None, default='', quality=jpgQ)
if fileName and sourceFile:
# for other uses
pass