Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaker authored Sep 4, 2020
1 parent 1c32e7e commit e8cd5de
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 90 deletions.
35 changes: 28 additions & 7 deletions cutselectionController.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def __init__(self,ui,initialFiles,videoManager,ffmpegService,ytdlService):

self.currentLoopCycleStart = None
self.currentLoopCycleEnd = None
self.removeAllDownloads = False
self.removeDownloadRun = 0

def updateLoopMode(self,loopMode):
self.loopMode=loopMode
Expand Down Expand Up @@ -117,6 +119,13 @@ def handleMpvDurationChange(self,name,value):
def getIsPlaybackStarted(self):
return self.currentTotalDuration is not None and self.currentTimePos is not None

def jumpClips(self,offset):
try:
nextClipInd = self.files.index(self.currentlyPlayingFileName)+offset
self.playVideoFile(self.files[nextClipInd%len(self.files)],0)
except ValueError as e:
print(e)

def playVideoFile(self,filename,startTimestamp):
self.currentTotalDuration=None
self.currentTimePos=None
Expand Down Expand Up @@ -176,14 +185,25 @@ def getTotalDuration(self):
return self.currentTotalDuration

def removeVideoFile(self,filename):
deleteFile = False
deleteFile = self.removeAllDownloads
_,justFilename = os.path.split(filename)
localNameifDownloaded = os.path.join('tempDownloadedVideoFiles',justFilename)
if os.path.isfile(localNameifDownloaded) and os.path.samefile( filename,localNameifDownloaded ):
response = self.ui.confirmWithMessage('Also remove downloaded video?','Video "{}" was downloaded with youtube-dl, do you also want to delete the temporary file?'.format(justFilename),icon='warning')
print(response)
if response=='yes':
deleteFile=True
fileIsInTempFolder = os.path.isfile(localNameifDownloaded) and os.path.samefile( filename,localNameifDownloaded )

if not deleteFile:
if fileIsInTempFolder:
response = self.ui.confirmWithMessage('Also remove downloaded video?' ,'Video "{}" was downloaded with youtube-dl, do you also want to delete the downloaded temporary file?'.format(justFilename),icon='warning')
print(response)
if response=='yes':
deleteFile=True
self.removeDownloadRun += 1
else:
self.removeDownloadRun = 0

if self.removeDownloadRun>5:
response = self.ui.confirmWithMessage('Delete doownloaded videos for all all future clip removals?' ,'Do you want to delete the downloaded temporary files for all future clip removals?',icon='warning')
if response=='yes':
self.removeAllDownloads=True

self.files = [x for x in self.files if x != filename]
self.videoManager.removeVideo(filename)
Expand All @@ -194,7 +214,8 @@ def removeVideoFile(self,filename):
self.player.command('stop')
self.currentlyPlayingFileName=None
self.updateProgressStatistics()
if deleteFile:

if fileIsInTempFolder and deleteFile:
os.remove(filename)

def returnYTDLDownlaodedVideo(self,filename):
Expand Down
18 changes: 16 additions & 2 deletions cutselectionUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ def __init__(self, master=None, controller=None, *args, **kwargs):

self.frameVideoControls = ttk.Frame(self.frameVideoPlayerAndControls)

self.buttonvideoJumpBack = ttk.Button(self.frameVideoControls,text='<<', style="small.TButton")
self.buttonvideoPrevClip= ttk.Button(self.frameVideoControls,text='Prev Clip', style="small.TButton")
self.buttonvideoPrevClip.config(command=self.prevClip)
self.buttonvideoPrevClip.pack(expand="true", fill='x', side="left")

self.buttonvideoJumpBack = ttk.Button(self.frameVideoControls,text='<< Jump', style="small.TButton")
self.buttonvideoJumpBack.config(command=self.jumpBack)
self.buttonvideoJumpBack.pack(expand="true", fill='x', side="left")

Expand All @@ -264,10 +268,14 @@ def __init__(self, master=None, controller=None, *args, **kwargs):
self.buttonvideoInterestMark.config(command=self.addNewInterestMarkNow)
self.buttonvideoInterestMark.pack(expand="true", fill='x', side="left")

self.buttonvideoJumpFwd = ttk.Button(self.frameVideoControls,text='>>', style="small.TButton")
self.buttonvideoJumpFwd = ttk.Button(self.frameVideoControls,text='Jump >>', style="small.TButton")
self.buttonvideoJumpFwd.config(command=self.jumpFwd)
self.buttonvideoJumpFwd.pack(expand="true", fill='x', side="left")

self.buttonvideoNextClip= ttk.Button(self.frameVideoControls,text='Next Clip', style="small.TButton")
self.buttonvideoNextClip.config(command=self.nextClip)
self.buttonvideoNextClip.pack(expand="true", fill='x', side="left")


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

Expand Down Expand Up @@ -301,6 +309,12 @@ def __init__(self, master=None, controller=None, *args, **kwargs):
self.frameVideoPlayerFrame.bind("<Motion>", self.videomousePress)
self.frameVideoPlayerFrame.bind("<MouseWheel>", self.videoMousewheel)

def prevClip(self):
self.controller.jumpClips(-1)

def nextClip(self):
self.controller.jumpClips(1)

def updateLoopMode(self,*args):
self.controller.updateLoopMode(self.loopModeVar.get())

Expand Down
2 changes: 1 addition & 1 deletion ffmpegInfoParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VideoInfo:

def getVideoInfo(filename,filters=None):
state=None
stats= dict(filename=filename,duration=0,hasaudio=False)
stats= dict(filename=filename,duration=0,hasaudio=False,fps=24)
if filters is None:
proc = sp.Popen(['ffmpeg','-i',filename],stdout=sp.PIPE,stderr=sp.PIPE)
else:
Expand Down
56 changes: 34 additions & 22 deletions ffmpegService.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import time
import ffmpegInfoParser

filesPlannedForCreation = set()
fileExistanceLock = threading.Lock()

packageglobalStatusCallback=print


def idfunc(s):return s

getShortPathName = idfunc
Expand Down Expand Up @@ -119,13 +123,15 @@ def webmvp8Encoder(inputsList, outputPathName,filenamePrefix, filtercommand, opt


fileN=0
while 1:
fileN+=1
finalOutName = '{}_WmG_{}.webm'.format(filenamePrefix,fileN)
finalOutName = os.path.join(outputPathName,finalOutName)
outLogFilename = os.path.join('tempVideoFiles','encoder_{}.log'.format(fileN))
if not os.path.exists(finalOutName):
break
with fileExistanceLock:
while 1:
fileN+=1
finalOutName = '{}_WmG_{}.webm'.format(filenamePrefix,fileN)
finalOutName = os.path.join(outputPathName,finalOutName)
outLogFilename = os.path.join('tempVideoFiles','encoder_{}.log'.format(fileN))
if not os.path.exists(finalOutName) and finalOutName not in filesPlannedForCreation:
filesPlannedForCreation.add(finalOutName)
break


def encoderStatusCallback(text,percentage):
Expand Down Expand Up @@ -156,7 +162,8 @@ def encoderFunction(br,passNumber,passReason,passPhase=0):
,"-stats","-pix_fmt","yuv420p","-bufsize", "3000k"
,"-threads", str(4),"-crf" ,'4',"-speed", "0"
,"-auto-alt-ref", "1", "-lag-in-frames", "25"
,"-tune","ssim"]
,"-tune","ssim","-deadline","best",'-slices','8'
,"-metadata", 'title={}'.format(filenamePrefix.replace('-',' -') + ' WmG') ]

if sizeLimitMax == 0.0:
ffmpegcommand+=["-b:v","0","-qmin","0","-qmax","10"]
Expand Down Expand Up @@ -221,13 +228,15 @@ def mp4x264Encoder(inputsList, outputPathName,filenamePrefix, filtercommand, opt
initialBr = ( ((targetSize_guide)/dur) - ((64 / audio_mp)/dur) )*8

fileN=0
while 1:
fileN+=1
finalOutName = '{}_WmG_{}.mp4'.format(filenamePrefix,fileN)
finalOutName = os.path.join(outputPathName,finalOutName)
outLogFilename = os.path.join('tempVideoFiles','encoder_{}.log'.format(fileN))
if not os.path.exists(finalOutName):
break
with fileExistanceLock:
while 1:
fileN+=1
finalOutName = '{}_WmG_{}.webm'.format(filenamePrefix,fileN)
finalOutName = os.path.join(outputPathName,finalOutName)
outLogFilename = os.path.join('tempVideoFiles','encoder_{}.log'.format(fileN))
if not os.path.exists(finalOutName) and finalOutName not in filesPlannedForCreation:
filesPlannedForCreation.add(finalOutName)
break

def encoderStatusCallback(text,percentage):
statusCallback(text,percentage)
Expand Down Expand Up @@ -316,12 +325,15 @@ def gifEncoder(inputsList, outputPathName,filenamePrefix, filtercommand, options
sizeLimitMin = sizeLimitMax*0.85

fileN=0
while 1:
fileN+=1
finalOutName = '{}_WmG_{}.gif'.format(filenamePrefix,fileN)
finalOutName = os.path.join(outputPathName,finalOutName)
if not os.path.exists(finalOutName):
break
with fileExistanceLock:
while 1:
fileN+=1
finalOutName = '{}_WmG_{}.webm'.format(filenamePrefix,fileN)
finalOutName = os.path.join(outputPathName,finalOutName)
outLogFilename = os.path.join('tempVideoFiles','encoder_{}.log'.format(fileN))
if not os.path.exists(finalOutName) and finalOutName not in filesPlannedForCreation:
filesPlannedForCreation.add(finalOutName)
break

def encoderStatusCallback(text,percentage):
statusCallback(text,percentage)
Expand Down Expand Up @@ -372,7 +384,7 @@ def encoderFunction(width,passNumber,passReason,passPhase=0):

class FFmpegService():

def __init__(self,globalStatusCallback=print(),imageWorkerCount=2,encodeWorkerCount=1,statsWorkerCount=1):
def __init__(self,globalStatusCallback=print(),imageWorkerCount=2,encodeWorkerCount=3,statsWorkerCount=1):


self.cache={}
Expand Down
5 changes: 5 additions & 0 deletions filterSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
],
},

{
"name": "invert",
"filter": "ngeative"
},

{
"name": "posterizeArea",
"filter": "null[vin{fn}],[vin{fn}]split=2[vina{fn}][vinb{fn}],[vina{fn}]crop={w}:{h}:{x}:{y},elbg=codebook_length={strength}:nb_steps={nb_steps}[fg{fn}],[vinb{fn}][fg{fn}]overlay={x}:{y}",
Expand Down
87 changes: 53 additions & 34 deletions mergeSelectionUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def updateStatus(self,status,percent):


class SequencedVideoEntry(ttk.Frame):
def __init__(self, master,controller,sourceClip, *args, **kwargs):
def __init__(self, master,controller,sourceClip, *args,direction='LEFT_RIGHT',**kwargs):
ttk.Frame.__init__(self, master)

self.rid=sourceClip.rid
Expand All @@ -49,34 +49,41 @@ def __init__(self, master,controller,sourceClip, *args, **kwargs):
self.labelSequenceVideoName.config(text='{} ({:0.2f}-{:0.2f}) {:0.2f}s'.format(self.basename,self.s,self.e,self.e-self.s))
self.labelSequenceVideoName.pack(side='top')
self.frameOrderingButtons = ttk.Frame(self.frameSequenceVideoEntry)
self.buttonSequencePushEntryBack = ttk.Button(self.frameOrderingButtons)
self.buttonSequencePushEntryBack.config(text='⯇', width='2')
self.buttonSequencePushEntryBack.config(command=self.moveBack)
self.buttonSequencePushEntryBack.pack(expand='true', fill='both', side='left')

if direction == 'LEFT_RIGHT':
self.buttonSequencePushEntryBack = ttk.Button(self.frameOrderingButtons)
self.buttonSequencePushEntryBack.config(text='⯇', width='2')
self.buttonSequencePushEntryBack.config(command=self.moveBack)
self.buttonSequencePushEntryBack.pack(expand='true', fill='both', side='left')

self.canvasSequencePreview = ttk.Label(self.frameOrderingButtons)
self.canvasSequencePreview.config(image=self.previewImage)

self.canvasSequencePreview.pack(side='left')
self.buttonSequencePushEntryForwards = ttk.Button(self.frameOrderingButtons)
self.buttonSequencePushEntryForwards.config(text='⯈', width='2')
self.buttonSequencePushEntryForwards.config(command=self.moveForwards)
self.buttonSequencePushEntryForwards.pack(expand='true', fill='both', side='left')

if direction == 'LEFT_RIGHT':
self.buttonSequencePushEntryForwards = ttk.Button(self.frameOrderingButtons)
self.buttonSequencePushEntryForwards.config(text='⯈', width='2')
self.buttonSequencePushEntryForwards.config(command=self.moveForwards)
self.buttonSequencePushEntryForwards.pack(expand='true', fill='both', side='left')

self.frameOrderingButtons.config(height='200', width='200')
self.frameOrderingButtons.pack(side='top')

self.buttonSequenceEntryPreview = ttk.Button(self.frameSequenceVideoEntry)
self.buttonSequenceEntryPreview.config(text='Preview')
self.buttonSequenceEntryPreview.config(text='Preview')
self.buttonSequenceEntryPreview.config(command=self.preview)
self.buttonSequenceEntryPreview.pack(expand='true', fill='x', side='top')

self.buttonSequenceEntryREmove = ttk.Button(self.frameSequenceVideoEntry)
self.buttonSequenceEntryREmove.config(text='Remove')
self.buttonSequenceEntryREmove.config(text='Remove')
self.buttonSequenceEntryREmove.config(command=self.remove)
self.buttonSequenceEntryREmove.pack(expand='true', fill='both', side='top')

self.frameSequenceVideoEntry.config(height='200', padding='2', relief='groove', width='200')
self.frameSequenceVideoEntry.pack(expand='false', fill='y', side='left')

if direction == 'LEFT_RIGHT':
self.frameSequenceVideoEntry.pack(expand='false', fill='y', side='left')
elif direction == 'UP_DOWN':
self.frameSequenceVideoEntry.pack(expand='false', fill='y', side='top')

def preview(self):
if self.player is not None:
Expand Down Expand Up @@ -132,10 +139,10 @@ def __init__(self, master,controller):



self.selectColumnBtn = ttk.Button(self,text='Select Column',command=self.selectColumn)
self.selectColumnBtn = ttk.Button(self,text='Select Column',command=self.selectColumn)
self.selectColumnBtn.pack(expand='false', fill='x', side='bottom')

self.removeColumnBtn = ttk.Button(self,text='Remove Column',command=self.removeColumn)
self.removeColumnBtn = ttk.Button(self,text='Remove Column',command=self.removeColumn)
self.removeColumnBtn.pack(expand='false', fill='x', side='bottom')

self.pack(expand='false', fill='y', side='left')
Expand Down Expand Up @@ -175,12 +182,12 @@ def __init__(self, master,controller,filename,rid,s,e,filterexp, *args, **kwargs
self.controller.requestPreviewFrame(self.rid,self.filename,(self.e+self.s)/2,self.filterexp)

self.buttonInputPreview = ttk.Button(self.frameInputCutWidget)
self.buttonInputPreview.config(text='preview')
self.buttonInputPreview.config(text='preview')
self.buttonInputPreview.config(command=self.preview)
self.buttonInputPreview.pack(expand='true', fill='x', side='top')

self.buttonInputCutAdd = ttk.Button(self.frameInputCutWidget)
self.buttonInputCutAdd.config(text='Add to Sequence')
self.buttonInputCutAdd.config(text='Add to Sequence')
self.buttonInputCutAdd.config(command=self.addClipToSequence)
self.buttonInputCutAdd.pack(expand='true', fill='both', side='top')

Expand Down Expand Up @@ -290,7 +297,7 @@ def __init__(self, master=None, *args, **kwargs):

self.gridColumns = []

self.gridSequenceContainerAddColumn = ttk.Button(self.gridSequenceContainer,text='Add Column', command=self.addColumn)
self.gridSequenceContainerAddColumn = ttk.Button(self.gridSequenceContainer,text='Add Column', command=self.addColumn)
self.gridSequenceContainerAddColumn.pack(expand='false', fill='x', padx='5', pady='5', side='bottom')
self.gridSequenceContainer.pack_forget()

Expand Down Expand Up @@ -752,13 +759,22 @@ def requestPreviewFrame(self,rid,filename,timestamp,filterexp):
self.controller.requestPreviewFrame(rid,filename,timestamp,filterexp,(-1,100),self.previewFrameCallback)

def addClipToSequence(self,clip):
self.sequencedClips.append(
SequencedVideoEntry(self.sequenceContainer,self,clip),
)
self.scrolledframeInputCustContainer.xview(mode='moveto',value=0)
self.scrolledframeSequenceContainer.xview(mode='moveto',value=0)
self.scrolledframeInputCustContainer._scrollBothNow()
self.scrolledframeSequenceContainer._scrollBothNow()
if self.mergeStyleVar.get().split('-')[0].strip() == 'Grid':
if self.selectedColumn == None:
pass
else:
self.selectedColumn['clips'].append(
SequencedVideoEntry(self.selectedColumn['column'],self,clip,direction='UP_DOWN'),
)

else:
self.sequencedClips.append(
SequencedVideoEntry(self.sequenceContainer,self,clip),
)
self.scrolledframeInputCustContainer.xview(mode='moveto',value=0)
self.scrolledframeSequenceContainer.xview(mode='moveto',value=0)
self.scrolledframeInputCustContainer._scrollBothNow()
self.scrolledframeSequenceContainer._scrollBothNow()
self.updatedPredictedDuration()

def moveSequencedClip(self,clip,move):
Expand All @@ -778,14 +794,17 @@ def moveSequencedClip(self,clip,move):
self.scrolledframeSequenceContainer._scrollBothNow()

def removeSequencedClip(self,clip):
currentIndex = self.sequencedClips.index(clip)
removedClip = self.sequencedClips.pop(currentIndex)
removedClip.pack_forget()
removedClip.destroy()
self.scrolledframeSequenceContainer.xview(mode='moveto',value=0)
self.scrolledframeInputCustContainer._scrollBothNow()
self.scrolledframeSequenceContainer._scrollBothNow()
self.updatedPredictedDuration()
if self.mergeStyleVar.get().split('-')[0].strip() == 'Grid':
pass
else:
currentIndex = self.sequencedClips.index(clip)
removedClip = self.sequencedClips.pop(currentIndex)
removedClip.pack_forget()
removedClip.destroy()
self.scrolledframeSequenceContainer.xview(mode='moveto',value=0)
self.scrolledframeInputCustContainer._scrollBothNow()
self.scrolledframeSequenceContainer._scrollBothNow()
self.updatedPredictedDuration()

def tabSwitched(self,tabName):
if str(self) == tabName:
Expand Down
Loading

0 comments on commit e8cd5de

Please sign in to comment.