spacepaste

  1.  
  2. def freezeLastFrameIfVideoShorter(self, fAudioStream, fVideoStream):
  3. # If audio is longer than video, freeze final frame of video until audio is finished.
  4. durA = self.getDuration_s( fAudioStream )
  5. durV = self.getDuration_s( fVideoStream )
  6. t = durA - durV
  7. if t < 0.05:
  8. return fVideoStream
  9. fVideoStreamOut = self.tmp_filename('vidFreezeLastFrame.mp4')
  10. # https://superuser.com/questions/1250900/freeze-last-frame-of-a-video-with-ffmpeg
  11. args = ['ffmpeg',
  12. '-f', 'lavfi',
  13. '-i', 'nullsrc=s=' + self.getRes(fVideoStream) + ':d=' + str(durA),
  14. '-i', fVideoStream,
  15. '-filter_complex', '[0:v][1:v]overlay[video]',
  16. '-map', '[video]',
  17. '-shortest',
  18. fVideoStreamOut]
  19. subprocess.run(args, check=True)
  20. return fVideoStreamOut
  21.