1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
"""
Snippets of code that are hard to bring under test, but that can be
used to manually test the behavior of imageip-ffmpeg in certain
use-cases. Some may depend on imageio.
"""
# %% Write a series of large frames
# In earlier versions of imageio-ffmpeg, the ffmpeg process was given a timeout
# to complete, but this timeout must be longer for longer movies. The default
# is now to wait for ffmpeg.
import os
import numpy as np
import imageio_ffmpeg
ims = [
np.random.uniform(0, 255, size=(1000, 1000, 3)).astype(np.uint8) for i in range(10)
]
filename = os.path.expanduser("~/Desktop/foo.mp4")
w = imageio_ffmpeg.write_frames(filename, (1000, 1000), ffmpeg_timeout=0)
w.send(None)
for i in range(200):
w.send(ims[i % 10])
print(i)
w.close()
# %% Behavior of KeyboardInterrupt / Ctrl+C
import os
import imageio_ffmpeg
filename = os.path.expanduser("~/.imageio/images/cockatoo.mp4")
reader = imageio_ffmpeg.read_frames(filename)
meta = reader.__next__()
try:
input("Do a manual KeyboardInterrupt now [Ctrl]+[c]")
# Note: Raising an error with code won't trigger the original error.
except BaseException as err:
print(err)
print("out1", len(reader.__next__()))
print("out2", len(reader.__next__()))
print("closing")
reader.close()
print("closed")
|