Permalink
Browse files

better cleaning of videos

  • Loading branch information...
sdpython committed Jan 20, 2018
1 parent 5ace0a9 commit 742da6beed7bbb4a9a207198bcd36b3f72a29891
@@ -65,8 +65,7 @@ def test_modify_avideo_blur(self):
exp = os.path.join(temp, "face.mp4")
video_save(vid2, exp)
self.assertExists(exp)
clean_video(vid2)
clean_video(vid)
clean_video([vid2, vid, vide])
def test_modify_avideo(self):
fLOG(
@@ -85,8 +84,7 @@ def test_modify_avideo(self):
im.save(os.path.join(temp, "img2.png"))
video_save(vid2, exp, verbose=__name__ == "__main__")
self.assertExists(exp)
clean_video(vid2)
clean_video(vid)
clean_video([vid2, vid, vide])
if __name__ == "__main__":
@@ -65,7 +65,7 @@ def test_modify_avideo(self):
exp = os.path.join(temp, "people.mp4")
video_save(vid2, exp)
self.assertExists(exp)
clean_video(vid2)
clean_video([vid2, vid, vide])
if __name__ == "__main__":
@@ -150,7 +150,23 @@ def clean_video(video):
"""
if isinstance(video, str):
raise TypeError("Unexpected type (string)")
if hasattr(video, 'reader'):
video.reader.close()
if hasattr(video.audio, 'reader'):
video.audio.reader.close_proc()
if isinstance(video, list):
for v in video:
clean_video(v)
else:
if not hasattr(video, 'close'):
if video.reader:
video.reader.close()
video.reader = None
try:
if video.audio:
video.audio.close()
video.audio = None
except AttributeError:
pass
else:
video.close()
#~ if hasattr(video, 'reader'):
#~ video.reader.close()
#~ if hasattr(video.audio, 'reader'):
#~ video.audio.reader.close_proc()

0 comments on commit 742da6b

Please sign in to comment.