2015-03-16 8 views
1

Привет я добавил простой GUI в сценарииНеожиданный выход в Python при использовании MoviePy

A python script to automatically summarize soccer videos based on the crowd's reactions

Сценарий GUI является следующий

from Tkinter import * 

from tkFileDialog import askopenfilename 
from soccer_reacts import video_edit 

class MyFrame(Frame): 
def __init__(self): 

    master = Tk() 
    Label(master, text="Please Insert Video Path With Browse", width=30).grid(row=0) 
    Frame.__init__(self) 
    self.master.title("Video Editor") 

    self.master.geometry('{}x{}'.format(300, 200)) 
    self.master.rowconfigure(5, weight=1) 
    self.master.columnconfigure(5, weight=1) 
    self.grid(sticky=W+E+N+S) 

    self.button = Button(self, text="Browse", command=self.load_file, width=15) 
    self.button.grid(row=1, column=0, sticky=W) 
    self.button2 = Button(self, text="Start", command=self.vid_reactions, width=15) 
    self.button2.grid(row=2, column=0, sticky=W) 

def load_file(self): 
    fname = askopenfilename(filetypes=(("MP4 files", "*.mp4"),("All files", "*.*"))) 
    if fname: 
     self.fname = fname 

def vid_reactions(self): 
    print("[*]Starting operation") 
    print("[*]File : "+self.fname) 
    video_edit(self.fname) 
    print("[*]Operation Finished") 



if __name__ == "__main__": 
MyFrame().mainloop() 

End это новый код сокращений футбола

import numpy as np # for numerical operations 
from moviepy.editor import VideoFileClip, concatenate 


def video_edit(file_name): 
clip = VideoFileClip(file_name) 
cut = lambda i: clip.audio.subclip(i,i+1).to_soundarray(fps=22000) 
volume = lambda array: np.sqrt(((1.0*array)**2).mean()) 
volumes = [volume(cut(i)) for i in range(0,int(clip.audio.duration-2))] 
averaged_volumes = np.array([sum(volumes[i:i+10])/10 
          for i in range(len(volumes)-10)]) 

increases = np.diff(averaged_volumes)[:-1]>=0 
decreases = np.diff(averaged_volumes)[1:]<=0 
peaks_times = (increases * decreases).nonzero()[0] 
peaks_vols = averaged_volumes[peaks_times] 
peaks_times = peaks_times[peaks_vols>np.percentile(peaks_vols,90)] 

final_times=[peaks_times[0]] 
for t in peaks_times: 
    if (t - final_times[-1]) < 60: 
     if averaged_volumes[t] > averaged_volumes[final_times[-1]]: 
      final_times[-1] = t 
    else: 
     final_times.append(t) 

final = concatenate([clip.subclip(max(t-5,0),min(t+5, clip.duration)) 
        for t in final_times]) 
final.to_videofile(file_name) # low quality is the default 

Когда я запускаю новый код, выход представляет собой файл mp4, с t он звучал в матче , но без видео. Я проверил все изменения, которые я сделал, и я не могу найти что-то неправильно. Может ли кто-нибудь помочь?

ответ

0

Я не знаю почему, но изменения последней строки из final.to_videofile (имя_файла) к final.write_videofile ('The result.mp4') было решение