imageio / imageio-ffmpeg

FFMPEG wrapper for Python
BSD 2-Clause "Simplified" License
225 stars 50 forks source link

FFMPEG reader fails after KeyboardInterrupt #4

Closed sorenrasmussen closed 4 years ago

sorenrasmussen commented 5 years ago

After a manual KeyboardInterrupt ([Ctrl]+[c]), reading a frame with (index > 0) causes an FFMPEG error.

import imageio
reader = imageio.get_reader("imageio:cockatoo.mp4",format="ffmpeg")

#reader.get_data(2) #Initializing the reader by reading some frame here will cause the error to go away

try:
    input("Do a manual KeyboardInterrupt [Ctrl]+[c] (raising an error with code won't trigger the error)")
except:
    print(reader.get_data(1)) #Reading some frame, n>0 fails.
    print(reader.get_data(0)) #Reading frame 0 works fine.

System: Imageio 2.4.1 Python 3.6.5 FFMPEG 3.2.4 Linux 64bit

almarklein commented 5 years ago

I can reproduce this on Windows when I run it from the command line. When I run it in my IDE and invoke a KeyboardInterrupt, the error does not happen. In the latter case I know that only the main thread is interrupted. I therefore suspect that the helper threads for the ffmpeg (one that reads frames and one that reads stderr) are interrupted. We should prevent this from happening.

almarklein commented 5 years ago

Moved this issue to the new imageio_ffmpeg repo.

almarklein commented 5 years ago

I tried this: https://stackoverflow.com/a/39174578/2271927 but the solution for Windows does not seem to work.

almarklein commented 4 years ago

Looking into this now and having a facepalm moment when I realized it's the ffmpeg process stopping because the interrupt propagates to the subprocesses 🤦‍♂

almarklein commented 4 years ago

https://stackoverflow.com/questions/5045771