diff --git a/SyncNetInstance.py b/SyncNetInstance.py index 497d44f..1b08504 100644 --- a/SyncNetInstance.py +++ b/SyncNetInstance.py @@ -39,7 +39,7 @@ def __init__(self, dropout = 0, num_layers_in_fc_layers = 1024): self.__S__ = S(num_layers_in_fc_layers = num_layers_in_fc_layers).cuda(); - def evaluate(self, opt, videofile): + def evaluate(self, opt, videofile, verbose=True): self.__S__.eval(); @@ -52,11 +52,27 @@ def evaluate(self, opt, videofile): os.makedirs(os.path.join(opt.tmp_dir,opt.reference)) - command = ("ffmpeg -y -i %s -threads 1 -f image2 %s" % (videofile,os.path.join(opt.tmp_dir,opt.reference,'%06d.jpg'))) - output = subprocess.call(command, shell=True, stdout=None) - - command = ("ffmpeg -y -i %s -async 1 -ac 1 -vn -acodec pcm_s16le -ar 16000 %s" % (videofile,os.path.join(opt.tmp_dir,opt.reference,'audio.wav'))) - output = subprocess.call(command, shell=True, stdout=None) + jpg_template = os.path.join(opt.tmp_dir, opt.reference, '%06d.jpg') + wav_path = os.path.join(opt.tmp_dir, opt.reference, 'audio.wav') + + # 1) extract frames + cmd = [ + "ffmpeg", "-loglevel", "error", "-nostats", + "-y", "-i", videofile, + "-vf", "scale=224:224:flags=bilinear,setsar=1", # ← FIXED: added -vf and fixed argument + "-threads", "1", + "-f", "image2", jpg_template + ] + subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False) + + # 2) extract audio + cmd = [ + "ffmpeg", "-loglevel", "error", "-nostats", + "-y", "-i", videofile, + "-async", "1", "-ac", "1", "-vn", + "-acodec", "pcm_s16le", "-ar", "16000", wav_path + ] + subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False) # ========== ========== # Load video @@ -91,7 +107,7 @@ def evaluate(self, opt, videofile): # Check audio and video input length # ========== ========== - if (float(len(audio))/16000) != (float(len(images))/25) : + if (float(len(audio))/16000) != (float(len(images))/25) and verbose : print("WARNING: Audio (%.4fs) and video (%.4fs) lengths are different."%(float(len(audio))/16000,float(len(images))/25)) min_length = min(len(images),math.floor(len(audio)/640)) @@ -123,8 +139,8 @@ def evaluate(self, opt, videofile): # ========== ========== # Compute offset # ========== ========== - - print('Compute time %.3f sec.' % (time.time()-tS)) + if verbose: + print('Compute time %.3f sec.' % (time.time()-tS)) dists = calc_pdist(im_feat,cc_feat,vshift=opt.vshift) mdist = torch.mean(torch.stack(dists,1),1) @@ -140,9 +156,10 @@ def evaluate(self, opt, videofile): fconfm = signal.medfilt(fconf,kernel_size=9) numpy.set_printoptions(formatter={'float': '{: 0.3f}'.format}) - print('Framewise conf: ') - print(fconfm) - print('AV offset: \t%d \nMin dist: \t%.3f\nConfidence: \t%.3f' % (offset,minval,conf)) + if verbose: + print('Framewise conf: ') + print(fconfm) + print('AV offset: \t%d \nMin dist: \t%.3f\nConfidence: \t%.3f' % (offset,minval,conf)) dists_npy = numpy.array([ dist.numpy() for dist in dists ]) return offset.numpy(), conf.numpy(), dists_npy