Skip to content

Commit

Permalink
Add autoResumeAfterSeek option
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaker committed Feb 18, 2023
1 parent 695a1a9 commit f6726e1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/cutselectionController.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ def seekTo(self,seconds,centerAfter=False):
if self.currentTotalDuration is not None:
self.ui.updateSummary( self.player.filename,self.player.duration,self.player.video_params,self.player.container_fps,self.player.estimated_vf_fps)

self.player.command('seek',str(seconds),'absolute','exact')
self.player.command('async', 'seek',str(seconds),'absolute','exact')
if centerAfter:
self.ui.centerTimelineOnCurrentPosition()


def getTotalDuration(self):
if self.currentTotalDuration is None:
Expand Down
45 changes: 24 additions & 21 deletions src/cutselectionUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from .modalWindows import PerfectLoopScanModal,YoutubeDLModal,TimestampModal,VoiceActivityDetectorModal,Tooltip,CutSpecificationPlanner
from .timeLineSelectionFrameUI import TimeLineSelectionFrameUI

fastSeekLock = threading.RLock()

def format_timedelta(value, time_format="{days} days, {hours2}:{minutes2}:{seconds2}"):

if hasattr(value, 'seconds'):
Expand Down Expand Up @@ -649,29 +651,30 @@ def stepForwards(self):
self.controller.stepForwards()

def fastSeek(self,centerAfter=False):
potential_seekpoints = [x for x in self.seekpoints if abs(x-(self.getCurrentPlaybackPosition()/self.getTotalDuration()))>0.2 ]

if len(potential_seekpoints) == 0:
self.seekpoints = [i/1000 for i in range(1000)]
print('RESET SEEKPOINTS')

potential_seekpoints = [x for x in self.seekpoints if abs(x-(self.getCurrentPlaybackPosition()/self.getTotalDuration()))>0.2 ]
fn = self.getcurrentFilename()
ranges = self.getRangesForClip(fn)
while 1:
point = random.choice(potential_seekpoints)
self.seekpoints.remove(point)
clear = True
for s,e in ranges:
if s<=point<=e:
clear = False
with fastSeekLock:
potential_seekpoints = [x for x in self.seekpoints if abs(x-(self.getCurrentPlaybackPosition()/self.getTotalDuration()))>0.2 ]

if len(potential_seekpoints) == 0:
self.seekpoints = [i/1000 for i in range(1000)]
print('RESET SEEKPOINTS')

potential_seekpoints = [x for x in self.seekpoints if abs(x-(self.getCurrentPlaybackPosition()/self.getTotalDuration()))>0.2 ]
fn = self.getcurrentFilename()
ranges = self.getRangesForClip(fn)
while 1:
point = random.choice(potential_seekpoints)
self.seekpoints.remove(point)
clear = True
for s,e in ranges:
if s<=point<=e:
clear = False
break
if clear:
break
if clear:
break

self.seekTo(point*self.getTotalDuration(),centerAfter=centerAfter)

return point*self.getTotalDuration()
self.seekTo(point*self.getTotalDuration(),centerAfter=centerAfter)
return point*self.getTotalDuration()

def videoMousewheel(self,evt):
ctrl = evt and ((evt.state & 0x4) != 0)
Expand Down
33 changes: 22 additions & 11 deletions src/timeLineSelectionFrameUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __enter__(self):
def __exit__(self ,type, value, traceback):
pass


@contextmanager
def acquire_timeout(lock, timeout):
result = lock.acquire(timeout=timeout)
Expand Down Expand Up @@ -318,7 +317,7 @@ def __init__(self, master, controller, globalOptions={}, *args, **kwargs):

self.image_handle_left_light = tk.PhotoImage(file = os.path.join("resources",'slider_left_light.gif'))
self.image_handle_right_light = tk.PhotoImage(file = os.path.join("resources",'slider_right_light.gif'))

self.lastRandomSubclipPos = -1

def stepBackwards(self,e):
self.controller.stepBackwards()
Expand All @@ -329,11 +328,16 @@ def stepForwards(self,e):
def acceptAndRandomJump(self,e):
target = self.controller.fastSeek(centerAfter=True)
self.keyboardBlockAtTime(e,pos=target)
self.lastRandomSubclipPos = target
self.setUiDirtyFlag()

def rejectAndRandomJump(self,e):
self.keyboardRemoveBlockAtTime(e,pos=self.lastRandomSubclipPos)
self.keyboardRemoveBlockAtTime(e)
target = self.controller.fastSeek(centerAfter=True)
self.lastRandomSubclipPos = target
self.keyboardBlockAtTime(e,pos=target)
self.setUiDirtyFlag()

def correctMouseXPosition(self,x):

Expand Down Expand Up @@ -499,9 +503,13 @@ def keyboardCutatTime(self,e):
self.setUiDirtyFlag(specificRID=selectedRange)
self.updateCanvas(withLock=False)

def keyboardRemoveBlockAtTime(self,e):
def keyboardRemoveBlockAtTime(self,e,pos=None):
if self.tempRangeStart is not None:
a,b = sorted([self.tempRangeStart,self.controller.getCurrentPlaybackPosition()])
if pos is None:
pos = self.controller.getCurrentPlaybackPosition()

a,b = sorted([self.tempRangeStart,pos])

ranges = self.controller.getRangesForClip(self.controller.getcurrentFilename())
for rid,(s,e) in list(ranges):
if a<=s<=b and a<=e<=b:
Expand Down Expand Up @@ -629,8 +637,9 @@ def incrementEndpointPosition(self,increment,markerrid,pos):
self.resumeplaybackTimer.cancel()
except(AttributeError):
pass
self.resumeplaybackTimer = threading.Timer(0.8, self.controller.play)
self.resumeplaybackTimer.start()
if self.globalOptions.get('autoResumeAfterSeek',True):
self.resumeplaybackTimer = threading.Timer(0.8, self.controller.play)
self.resumeplaybackTimer.start()

if pos == 's':
startTarget = self.roundToNearestFrame(sts+(increment*0.05))
Expand Down Expand Up @@ -761,8 +770,9 @@ def timelineMousewheel(self,e):
self.resumeplaybackTimer.cancel()
except(AttributeError):
pass
self.resumeplaybackTimer = threading.Timer(0.8, self.controller.play)
self.resumeplaybackTimer.start()
if self.globalOptions.get('autoResumeAfterSeek',True):
self.resumeplaybackTimer = threading.Timer(0.8, self.controller.play)
self.resumeplaybackTimer.start()
targetSeconds = self.roundToNearestFrame(targetSeconds)
self.clipped=self.controller.updatePointForClip(self.controller.getcurrentFilename(),rid,'m',targetSeconds)
self.setUiDirtyFlag(specificRID=rid)
Expand Down Expand Up @@ -930,7 +940,8 @@ def timelineMousePress(self,e):

self.clickTarget = None
self.rangeHeaderClickStart=None
self.controller.play()
if self.globalOptions.get('autoResumeAfterSeek',True):
self.controller.play()


if self.timeline_mousedownstate.get(2,False):
Expand Down Expand Up @@ -1330,10 +1341,10 @@ def canvasPopupRemoveSubClipCallback(self):
lower = self.xCoordToSeconds(self.timeline_canvas_last_right_click_x-self.handleWidth)
upper = self.xCoordToSeconds(self.timeline_canvas_last_right_click_x+self.handleWidth)
for rid,(s,e) in list(ranges):
if s<mid<e:
if s<=mid<=e:
self.controller.removeSubclip((e+s)/2)
break
if lower<e<upper or lower<s<upper:
if lower<=e<=upper or lower<=s<=upper:
self.controller.removeSubclip((e+s)/2)
break
self.timeline_canvas_last_right_click_x=None
Expand Down
2 changes: 1 addition & 1 deletion src/videoManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def cloneSubclip(self,filename,point):
def removeSubclip(self,filename,point):
clipsToRemove=set()
for rid,(s,e) in self.subclips.get(filename,{}).items():
if s<point<e:
if s<=point<=e:
clipsToRemove.add(rid)
for rid in clipsToRemove:
del self.subclips.get(filename,{})[rid]
Expand Down
2 changes: 2 additions & 0 deletions src/webmGeneratorController.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def __init__(self,initialFiles):

'askToShuffleLoadedFiles':False,

'autoResumeAfterSeek':True,

"downloadNameFormat":'%(title)s-%(id)s.%(uploader,creator,channel)s.{passNumber}.%(ext)s',
"defaultMinterpolateFlags":"mi_mode=mci:mc_mode=aobmc:me_mode=bidir:me=epzs:vsbmc=1:scd=fdiff:fps=30",
"defaultProfile":"None",
Expand Down

0 comments on commit f6726e1

Please sign in to comment.