Closed Happy-hub closed 2 years ago
You're exactly right that its the stderr pipe getting blocked. I certainly had this issue while I was building the showinfo() function up, but thought I'd solved it. Off the top of my head, here's a thought that might lead to a workaround for you:
def _read_showinfo(self):
raw_out = bytes()
raw_info = self._pipe.stderr.readline()
while re.search(self._si_read_key, raw_info) is None:
raw_info = self._pipe.stderr.readline()
raw_out += raw_info
self._si = raw_out.decode()
The _read_showinfo() function reads the stderr a line at a time until it matches the regular expression defined in self._si_read_key = re.compile(rb'(\[Parsed_showinfo).*] n:')
So, I imagine a scenario where the 10th frame of your video input source produces a stderr output in FFmpeg that contains TWO lines that match that expression. If that were the case, I think _read_showinfo() would stop reading at the first match, leaving the stderr pipe unemptied. And that might block the process too?
It's a shot in the dark, (and maybe I'm forgetting everything about how these pipes work) but I'm dealing with some health issues right now and I doubt I'll be tinkering with the code any time soon. If you trace it down and solve it, do pass your fix along! And feel free to ask me anything you need to know, if it isn't obvious in the code.
Hi, sorry for the late response.
Unfortunately, the 10th frame does not produce two lines that match the expression. I ended up writing something quite similar to yours, and it sorta works for me (tested on Dahua and Hikvision cameras) but I'm still not sure how it's different from yours.
Anyways, hope you will get well soon and continue writing amazing scripts. thank you for the response
Hi, thank you for this useful script. I was wondering if you found a way to read frames and their info at the same time.
Currently my code is as follows:
The code seems to work at the beginning, but after about 9 frames, it freezes. I added a print statement each time it reads showinfo.
and the output is as follows:
My assumption is that it tries to read from stderr but it doesn't have anything to read so it blocks for ever. Is there already a solution to this? thanks