Closed hmaarrfk closed 2 years ago
This is how Python's generators work. A send is needed to bring the generator to the first yield. See e.g. this example.
def gen():
while True:
bb = yield
print(bb)
g = gen()
g.send(None)
g.send(1)
g.send(2)
g.send(3)
Produces:
1
2
3
If you comment the g.send(None)
it gives: "TypeError: can't send non-None value to a just-started generator".
AFAIK this cannot be avoided, but if it is, I'd love to learn!
are you saying that i:
I will get 2 frames written to my file.
But if i i
I will get 3 frames written to my file?
I think i understand my confusion. THere is the imageio
API which uses append_data
. That API transparently calls send(None)
to avoid this confusion.
The imageio-ffmpeg
API requires the user to call send(None)
to initialize things.
Late reaction - holidays - @hmaarrfk yes indeed. imageio-ffmpeg
provides a raw generator, and these must be initialized, which seems to be a Python quirk.
In the example you suggest to do:
However, it is unclear why one should "seed" the generator. Is this in the case that there are no frames?