@@ -78,22 +78,30 @@ def __init__(self, file=None, clip=None):
78
78
self .start_image = None
79
79
self .end_frame = 1
80
80
self .end_image = None
81
+ self .current_frame = 1
82
+
83
+ self .clip = clip
84
+ self .clip .Open ()
85
+ self .clip_position = self .clip .Position ()
86
+ self .clip .Position (0 )
81
87
82
88
# Keep track of file object
83
- self .file = file
84
- self .file_path = file .absolute_path ()
85
- self .video_length = int (file .data ['video_length' ])
86
- self .fps_num = int (file .data ['fps' ]['num' ])
87
- self .fps_den = int (file .data ['fps' ]['den' ])
88
- self .fps = float (self .fps_num ) / float (self .fps_den )
89
- self .width = int (file .data ['width' ])
90
- self .height = int (file .data ['height' ])
91
- self .sample_rate = int (file .data ['sample_rate' ])
92
- self .channels = int (file .data ['channels' ])
93
- self .channel_layout = int (file .data ['channel_layout' ])
89
+ # self.file = file
90
+ # self.file_path = file.absolute_path()
91
+
92
+ c_info = clip .Reader ().info
93
+ self .fps = c_info .fps .ToInt () #float(self.fps_num) / float(self.fps_den)
94
+ self .fps_num = self .fps #int(file.data['fps']['num'])
95
+ self .fps_den = 1 #int(file.data['fps']['den'])
96
+ self .width = c_info .width #int(file.data['width'])
97
+ self .height = c_info .height #int(file.data['height'])
98
+ self .sample_rate = c_info .sample_rate #int(file.data['sample_rate'])
99
+ self .channels = c_info .channels #int(file.data['channels'])
100
+ self .channel_layout = c_info .channel_layout #int(file.data['channel_layout'])
101
+ self .video_length = int (self .clip .Duration () * self .fps ) + 1 #int(file.data['video_length'])
94
102
95
103
# Open video file with Reader
96
- log .info (self .file_path )
104
+ log .info (self .clip . Reader () )
97
105
98
106
# Add Video Widget
99
107
self .videoPreview = VideoWidget ()
@@ -110,7 +118,7 @@ def __init__(self, file=None, clip=None):
110
118
111
119
try :
112
120
# Add clip for current preview file
113
- self .clip = openshot .Clip (self .file_path )
121
+ # self.clip = openshot.Clip(self.file_path)
114
122
115
123
# Show waveform for audio files
116
124
if not self .clip .Reader ().info .has_video and self .clip .Reader ().info .has_audio :
@@ -123,6 +131,7 @@ def __init__(self, file=None, clip=None):
123
131
self .r .info .video_length = self .video_length
124
132
125
133
self .r .AddClip (self .clip )
134
+
126
135
except :
127
136
log .error ('Failed to load media file into region select player: %s' % self .file_path )
128
137
return
@@ -147,8 +156,8 @@ def __init__(self, file=None, clip=None):
147
156
148
157
# Determine if a start or end attribute is in this file
149
158
start_frame = 1
150
- if 'start' in self .file .data .keys ():
151
- start_frame = (float (self .file .data ['start' ]) * self .fps ) + 1
159
+ # if 'start' in self.file.data.keys():
160
+ # start_frame = (float(self.file.data['start']) * self.fps) + 1
152
161
153
162
# Display start frame (and then the previous frame)
154
163
QTimer .singleShot (500 , functools .partial (self .sliderVideo .setValue , start_frame + 1 ))
@@ -166,7 +175,7 @@ def __init__(self, file=None, clip=None):
166
175
self .sliderVideo .valueChanged .connect (self .sliderVideo_valueChanged )
167
176
self .initialized = True
168
177
169
- get_app ().window .SelectRegionSignal .emit (clip .id )
178
+ get_app ().window .SelectRegionSignal .emit (clip .Id () )
170
179
171
180
def actionPlay_Triggered (self ):
172
181
# Trigger play button (This action is invoked from the preview thread, so it must exist here)
@@ -175,6 +184,7 @@ def actionPlay_Triggered(self):
175
184
def movePlayhead (self , frame_number ):
176
185
"""Update the playhead position"""
177
186
187
+ self .current_frame = frame_number
178
188
# Move slider to correct frame position
179
189
self .sliderIgnoreSignal = True
180
190
self .sliderVideo .setValue (frame_number )
@@ -222,10 +232,16 @@ def sliderVideo_valueChanged(self, new_frame):
222
232
223
233
def accept (self ):
224
234
""" Ok button clicked """
235
+
236
+ self .clip .Position (self .clip_position )
237
+
225
238
self .shutdownPlayer ()
226
239
super (SelectRegion , self ).accept ()
227
240
228
241
def shutdownPlayer (self ):
242
+
243
+ self .clip .Position (self .clip_position )
244
+
229
245
log .info ('shutdownPlayer' )
230
246
231
247
# Stop playback
@@ -237,11 +253,15 @@ def shutdownPlayer(self):
237
253
self .preview_parent .background .wait (5000 )
238
254
239
255
# Close readers
256
+ self .r .RemoveClip (self .clip )
240
257
self .r .Close ()
241
- self .clip .Close ()
258
+ # self.clip.Close()
242
259
self .r .ClearAllCache ()
243
260
244
261
def reject (self ):
262
+
263
+ self .clip .Position (self .clip_position )
264
+
245
265
# Cancel dialog
246
266
self .shutdownPlayer ()
247
267
super (SelectRegion , self ).reject ()
0 commit comments