def freezeLastFrameIfVideoShorter(self, fAudioStream, fVideoStream): # If audio is longer than video, freeze final frame of video until audio is finished. durA = self.getDuration_s( fAudioStream ) durV = self.getDuration_s( fVideoStream ) t = durA - durV if t < 0.05: return fVideoStream fVideoStreamOut = self.tmp_filename('vidFreezeLastFrame.mp4') # https://superuser.com/questions/1250900/freeze-last-frame-of-a-video-with-ffmpeg args = ['ffmpeg', '-f', 'lavfi', '-i', 'nullsrc=s=' + self.getRes(fVideoStream) + ':d=' + str(durA), '-i', fVideoStream, '-filter_complex', '[0:v][1:v]overlay[video]', '-map', '[video]', '-shortest', fVideoStreamOut] subprocess.run(args, check=True) return fVideoStreamOut