Skip to content

Commit

Permalink
encoded video listing pane and autoconvert fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaker committed Feb 25, 2023
1 parent 45ed07b commit 7425439
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/cutselectionController.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def takeScreenshotToFile(self,screenshotPath,includes='video'):
def getGlobalOptions(self):
return self.globalOptions


def splitClipIntoNEqualSections(self):
n = self.ui.askInteger('How Many sections would you like to split into?','How Many sections would you like to split into?',initialvalue=10)

Expand Down Expand Up @@ -532,9 +533,11 @@ def loadFiles(self,fileList,asktoSort=False):
self.updateProgressStatistics()

def returnPreviewFrame(self,requestId,timestamp,size,responseImage):
print('returnPreviewFrame',requestId,timestamp,size)
self.ui.updateViewPreviewFrame(requestId,responseImage)

def requestPreviewFrame(self,filename,timestamp,size):
print('requestPreviewFrame',filename,timestamp,size)
self.ffmpegService.requestPreviewFrame(filename,filename,'10%','',size,self.returnPreviewFrame)

def getcurrentFilename(self):
Expand Down
14 changes: 13 additions & 1 deletion src/cutselectionUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tkinter.filedialog import askopenfilenames,askopenfilename
from tkinter import messagebox
from tkinter import simpledialog
from pygubu.widgets.scrolledframe import ScrolledFrame

import os
import threading
import signal
Expand All @@ -16,6 +16,10 @@
from .modalWindows import PerfectLoopScanModal,YoutubeDLModal,TimestampModal,VoiceActivityDetectorModal,Tooltip,CutSpecificationPlanner
from .timeLineSelectionFrameUI import TimeLineSelectionFrameUI

from pygubu.widgets.scrolledframe import ScrolledFrame



fastSeekLock = threading.RLock()

def format_timedelta(value, time_format="{days} days, {hours2}:{minutes2}:{seconds2}"):
Expand Down Expand Up @@ -467,11 +471,19 @@ def __init__(self, master=None, controller=None,globalOptions={},*args, **kwargs

self.frameVideoControls.pack(expand="false", fill="x", side="top")




self.frameVideoPlayerAndControls.pack(expand="true", fill="both", side="right")




self.frameUpperFrame.config(height="200", width="200")
self.frameUpperFrame.pack(expand="true", fill="both", side="top")



self.frameTimeLineFrame = TimeLineSelectionFrameUI(self.frameCutSelection, self, globalOptions=self.globalOptions)


Expand Down
4 changes: 4 additions & 0 deletions src/mergeSelectionController.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def getFilteredClips(self):
return self.filterController.getClipsWithFilters()

def requestPreviewFrame(self,rid,filename,timestamp,filterexp,size,callback):
print('requestPreviewFrame',rid,filename,timestamp)
self.ffmpegService.requestPreviewFrame(rid,filename,timestamp,filterexp,size,callback)

def encode(self,requestId,mode,seq,options,filenamePrefix,statusCallback):
Expand All @@ -106,6 +107,9 @@ def encode(self,requestId,mode,seq,options,filenamePrefix,statusCallback):
def cancelEncodeRequest(self,requestId):
self.ffmpegService.cancelEncodeRequest(requestId)

def registerComplete(self,filename,clip=None):
self.controller.registerComplete(filename,clip=clip)

def deleteCustomProfile(self,profileName):
return ''

Expand Down
52 changes: 40 additions & 12 deletions src/mergeSelectionUi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import tkinter as tk
import tkinter.ttk as ttk
from pathvalidate import sanitize_filepath
from pygubu.widgets.scrolledframe import ScrolledFrame
import os
import string
Expand All @@ -18,6 +19,9 @@
from .modalWindows import AdvancedEncodeFlagsModal
import platform




try:
from tkinterdnd2 import Tk as TkinterDnDTk
from tkinterdnd2 import COPY, DND_FILES
Expand Down Expand Up @@ -71,7 +75,7 @@ def format_timedelta(value, time_format="{days} days, {hours2}:{minutes2}:{secon

class EncodeProgress(ttk.Frame):

def __init__(self, master=None, *args, encodeRequestId=None,controller=None, targetSize=0.0, **kwargs):
def __init__(self, master=None, *args, encodeRequestId=None,controller=None, targetSize=0.0, clip=None, **kwargs):
ttk.Frame.__init__(self, master)

self.frameEncodeProgressWidget = self
Expand All @@ -80,6 +84,7 @@ def __init__(self, master=None, *args, encodeRequestId=None,controller=None, tar
self.cancelled = False
self.controller = controller
self.config(padding='2', relief='raised')
self.clip = clip

self.frameEncodeProgressWidget.columnconfigure(0, weight=1)
self.frameEncodeProgressWidget.columnconfigure(1, weight=1)
Expand Down Expand Up @@ -339,6 +344,7 @@ def updateStatus(self,status,percent,finalFilename=None,requestStatus=None, enco

if finalFilename is not None:
self.finalFilename = finalFilename
self.controller.registerComplete(self.finalFilename,clip=self.clip)

if percent is not None:
if percent<self.lastProgress:
Expand Down Expand Up @@ -397,6 +403,7 @@ class SequencedVideoEntry(ttk.Frame):
def __init__(self, master,controller,sourceClip, *args,direction='LEFT_RIGHT',**kwargs):
ttk.Frame.__init__(self, master)

self.sourceClip = sourceClip
self.rid=sourceClip.rid
self.s=sourceClip.s
self.e=sourceClip.e
Expand Down Expand Up @@ -505,6 +512,9 @@ def __init__(self, master,controller,sourceClip, *args,direction='LEFT_RIGHT',**
elif direction == 'UP_DOWN':
self.frameSequenceVideoEntry.pack(expand='false', fill='y', side='top')

def getpreviewImg(self):
return self.sourceClip.previewImage

def muteToggle(self):
self.muted = not self.muted
if self.muted:
Expand Down Expand Up @@ -564,6 +574,7 @@ def remove(self):
self.controller.removeSequencedClip(self)

def setPreviewImage(self,photoImage):
print('setPreviewImage',self.rid)
self.previewImage=photoImage
self.canvasSequencePreview.config(image=self.previewImage)

Expand Down Expand Up @@ -687,6 +698,7 @@ def __init__(self, master,controller,filename,rid,s,e,filterexp,filteraudioexp,f
self.frameInputCutWidget.pack(anchor='nw', expand='false', fill='y', side='left')

def setPreviewImage(self,photoImage):
print('setPreviewImage',self.rid)
self.previewImage=photoImage
self.canvasInputCutPreview.config(image=self.previewImage)

Expand Down Expand Up @@ -1734,8 +1746,21 @@ def valueChange(self,*args):

try:
self.filenamePrefixValue = self.filenamePrefixVar.get()
except:
pass
testpath = self.filenamePrefixValue+'.bin'
sanitisedPath = sanitize_filepath(testpath)

pre,post = os.path.split(testpath)

if testpath != sanitisedPath or pre != '':
self.entryFilenamePrefix.config(style='error.TEntry')
else:
self.entryFilenamePrefix.config(style='')
except Exception as e:
try:
self.entryFilenamePrefix.config(style='error.TEntry')
except Exception as ie:
pass


try:
tempoutputFormatValue = self.outputFormatVar.get()
Expand Down Expand Up @@ -1848,6 +1873,8 @@ def valueChange(self,*args):

self.updatedPredictedDuration()

def registerComplete(self,filename,clip=None):
self.controller.registerComplete(filename,clip=clip)

def toggleBoringMode(self,boringMode):
if self.syncModal is not None and self.syncModal.isActive:
Expand All @@ -1862,7 +1889,7 @@ def cancelAllEncodes(self):
epw.cancelEncodeRequest()

def encodeCurrent(self):

clip=None
minSize = self.maximumSizeValue * (1-self.globalOptions.get('allowableTargetSizeUnderrun',0))

nullfilter = ''
Expand All @@ -1876,12 +1903,12 @@ def encodeCurrent(self):
encodeSequence = []
self.encodeRequestId+=1

for clip in self.sequencedClips:
for clip in self.sequencedClips:
definition = (clip.rid,clip.filename,clip.s,clip.e,nullfilter,nullfilter,nullfilter,clip.getSpeed())
encodeSequence.append(definition)

if len(encodeSequence)>0:
encodeProgressWidget = EncodeProgress(self.labelframeEncodeProgress,encodeRequestId=self.encodeRequestId,controller=self)
encodeProgressWidget = EncodeProgress(self.labelframeEncodeProgress,encodeRequestId=self.encodeRequestId,controller=self,clip=clip)
self.encoderProgress.append(encodeProgressWidget)
outputPrefix = self.filenamePrefixValue
if self.automaticFileNamingValue:
Expand Down Expand Up @@ -1943,7 +1970,7 @@ def encodeCurrent(self):
}
options.update(self.advancedFlags)

encodeProgressWidget = EncodeProgress(self.labelframeEncodeProgress,encodeRequestId=self.encodeRequestId,controller=self,targetSize=self.maximumSizeValue)
encodeProgressWidget = EncodeProgress(self.labelframeEncodeProgress,encodeRequestId=self.encodeRequestId,controller=self,targetSize=self.maximumSizeValue,clip=clip)
self.encoderProgress.append(encodeProgressWidget)
outputPrefix = self.filenamePrefixValue
if self.automaticFileNamingValue:
Expand Down Expand Up @@ -1997,7 +2024,7 @@ def encodeCurrent(self):
}
options.update(self.advancedFlags)

encodeProgressWidget = EncodeProgress(self.labelframeEncodeProgress,encodeRequestId=self.encodeRequestId,controller=self,targetSize=self.maximumSizeValue)
encodeProgressWidget = EncodeProgress(self.labelframeEncodeProgress,encodeRequestId=self.encodeRequestId,controller=self,targetSize=self.maximumSizeValue,clip=clip)
self.encoderProgress.append(encodeProgressWidget)

outputPrefix = self.filenamePrefixValue
Expand Down Expand Up @@ -2050,7 +2077,7 @@ def encodeCurrent(self):
}
options.update(self.advancedFlags)

encodeProgressWidget = EncodeProgress(self.labelframeEncodeProgress,encodeRequestId=self.encodeRequestId,controller=self,targetSize=self.maximumSizeValue)
encodeProgressWidget = EncodeProgress(self.labelframeEncodeProgress,encodeRequestId=self.encodeRequestId,controller=self,targetSize=self.maximumSizeValue,clip=clip)
self.encoderProgress.append(encodeProgressWidget)
outputPrefix = self.filenamePrefixValue
if self.automaticFileNamingValue:
Expand Down Expand Up @@ -2185,6 +2212,7 @@ def updateProfileSpecs(self):


def previewFrameCallback(self,requestId,timestamp,size,imageData):
print('previewFrameCallback',requestId)
photoImage = tk.PhotoImage(data=imageData)
for sv in self.selectableVideos.values():
if sv.rid==requestId:
Expand Down Expand Up @@ -2412,7 +2440,7 @@ def clearAllColumns(self):
removedClip.destroy()

def addAllClipsInTimelineOrder(self,minrid=-1,clearProgress=True):
finalrid = minrid
finalrid = int(minrid)
if self.mergeStyleVar.get().split('-')[0].strip() == 'Grid':
self.clearAllColumns()
for ind,clip in enumerate(sorted(self.selectableVideos.values(),key=lambda x:(x.filename,x.s))):
Expand All @@ -2424,8 +2452,8 @@ def addAllClipsInTimelineOrder(self,minrid=-1,clearProgress=True):
else:
self.clearSequence(includeProgress=clearProgress)
for clip in sorted(self.selectableVideos.values(),key=lambda x:(x.filename,x.s)):
finalrid = max(finalrid,clip.rid)
if clip.rid > minrid:
finalrid = max(int(finalrid),int(clip.rid))
if int(clip.rid) > int(minrid):
self.addClipToSequence(clip)
return finalrid

Expand Down
24 changes: 18 additions & 6 deletions src/timeLineSelectionFrameUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def acquire_timeout(lock, timeout):
if result:
lock.release()

jumpRemovelock = Lock()

def format_timedelta(value, time_format="{days} days, {hours2}:{minutes2}:{seconds:02.2F}"):

if hasattr(value, 'seconds'):
Expand Down Expand Up @@ -330,14 +332,24 @@ def acceptAndRandomJump(self,e):
self.keyboardBlockAtTime(e,pos=target)
self.lastRandomSubclipPos = target
self.setUiDirtyFlag()
print('Exit acceptAndRandomJump')

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()
if jumpRemovelock.acquire(blocking=False):
try:
print('Entry rejectAndRandomJump')
tempPos = self.lastRandomSubclipPos
self.keyboardRemoveBlockAtTime(e,pos=tempPos)
self.keyboardRemoveBlockAtTime(e)
target = self.controller.fastSeek(centerAfter=True)
self.lastRandomSubclipPos = target
self.keyboardBlockAtTime(e,pos=target)

print('Exit rejectAndRandomJump')
jumpRemovelock.release()

except Exception as e:
jumpRemovelock.release()

def correctMouseXPosition(self,x):

Expand Down
27 changes: 23 additions & 4 deletions src/webmGeneratorController.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,30 @@ def listdropFiles(self,strdropfiles):
return [x for x in dropfiles if x.strip() != '']

def enterDrop(self,drop):
dropfiles = self.listdropFiles(drop.data)
if len(dropfiles) > 1 or (len(dropfiles) ==1 and os.path.isdir(dropfiles[0]) ):
self.webmMegeneratorUi.showDrop(len(dropfiles))
try:
dropfiles = self.listdropFiles(drop.data)
if len(dropfiles) > 1 or (len(dropfiles) ==1 and os.path.isdir(dropfiles[0]) ):
self.webmMegeneratorUi.showDrop(len(dropfiles))
except Exception as e:
print(e)
self.webmMegeneratorUi.hideDrop()

def registerComplete(self,filename,clip=None):

label = os.path.basename(filename)
filename = os.path.abspath(filename)
img=None
if clip is not None:
img = clip.getpreviewImg()

self.webmMegeneratorUi.registerComplete(label,filename,img=img)

def leaveDrop(self,drop):
self.webmMegeneratorUi.hideDrop()

def toggleCompletedFrame(self):
self.cutselectionUi.toggleCompletedFrame()

def setAutoConvert(self,state):
self.autoConvert = state

Expand All @@ -391,7 +408,9 @@ def loadDrop(self,drop):

print(drop.data)
dropfiles = self.listdropFiles(drop.data)


print(dropfiles)

if len(dropfiles)>0:

if self.globalOptions.get('askToShuffleLoadedFiles',False):
Expand Down
Loading

0 comments on commit 7425439

Please sign in to comment.