Closed ericnjogu closed 4 years ago
Thanks for the report!
Imageio-ffmpeg only supports writing to a file on the file system, because it calls ffmpeg in a subprocess. Therefore imageio cannot write directly to a file-like object (like a socket). What happens is that ffmpeg is used to write the video to a temporary file, and then it's loaded and written to the file object. This happens about here in imageio/core/request.py.
Now, this error looks a bit like ffmpeg needs a filename extension to determine the output format, and the temp file does not have such an extension. This can be reproduced:
import imageio
import imageio_ffmpeg
ims = imageio.mimread("imageio:cockatoo.mp4", memtest="1000MB")
size = ims[0].shape[1], ims[0].shape[0]
gen = imageio_ffmpeg.write_frames("c:/users/almar/desktop/foo_video_no_ext", size)
gen.send(None)
for im in ims:
gen.send(im)
gen.close()
Now how to fix this. The quick version would be to use imageio_ffmpeg
directly.
The longer version would probably be to change Request.get_local_filename()
here to accept an optional argument to allow plugins to specify a file extension.
Thanks for the response @almarklein and sorry for the long delay.
I tried out your suggestion and it appears that imageio_ffmpeg write_frames() only works with string paths. It would be nice to have it accept file like objects too. This way one could write to a socket.
Here's my code - https://github.com/kunadawa/object-detection-visualization/commit/0e142207add039d18e5ebbb1dd79b80b75cf3d84
It would be nice to have it accept file like objects too
I agree, but this is not possible because we're calling ffmpeg
in a subprocess and all we can do is give it a file path. It would likely be possible if we'd use ffmpeg
as a library, but this makes packaging much harder; it was a deliberate choice to use ffmpeg
as a subprocess.
I created https://github.com/imageio/imageio/issues/509 in imageio to fix the issue with the temp file. But then I realized that it won't actually fix your problem: you want to be able to stream video to a file like object, and imageio-ffmpeg
simply cannot do that. I've added a note to the readme that explains this.
I am trying to read a video file and write it to a socket using the code below and it is failing. I would appreciate your help:
The code is failing with the stacktrace below (debug logging turned on):