-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MJPEG stream decoding problem #107
Comments
I get a |
That's odd. I was just able to run Be sure you're quoting the URL as the ampersand gets caught by the shell and that would lead to the 401 you're experiencing. Honestly, I tried several MJPEG streams from public webcams all over the net with the same issue. |
That was a bit silly of me... Anyways, I can confirm the behaviour. The error is raised when we try to flush the stream in this loop. A frame has already been decoded when the exception is thrown. Options to take here:
I'm leaning towards 2 immediately. |
This is for situations in which flushing the stream results in an error after the first frame, and so you never get the frames. E.g. MJPEG webcams in #107
With the current master, I can do:
|
Hi, Mike. Pardon my ignorance, but I would like to be sure I understand the issue correctly. Is the issue that the packet does not contain enough data to decode the second frame which causes the error to be raised in that loop? Would using decode_one on other codecs effectively drop additional frames that may be in the same packet? Thanks for your time and help with this. I really appreciate it! |
In general, I'm not 100% on the implications of the changes I made, and I see there is an error in the example I provided you. Since we reset the packet buffers after we decode from them, continuing to decode one from your MJPEG results in the same frame coming out infinitely. The example should really be:
PyAV would extract as many frames as it could from each packet, just in case there were multiple frames in there. Otherwise, a buffer will eventually fill up and error. In this case, for whatever reason, that flushing procedure results in an exception being raised. In MJPEG you can safely assume there is only one frame per packet. It will actually be a complete JPEG. In other codecs... not so much. In general, we should consider if we should mutate a packet after consuming frames from it. I honestly don't know enough to make that decision now. But this commit as is should work for you. |
That's good information, thanks. I'm typically in the 'immutable camp', so I'd not mutate the packet after partially decoding it, if at all possible. I can take a stab at looking at this a little deeper as well. Should I close the issue, or would you like to keep it open for a more permanent fix or refactor? |
Lets leave it open until we manage to reformulate our new questions into a new issue. |
I have the same problem, but I find a fix like this in stream.pyx simpler: Why not like this? |
I just wanted to add that I have been using my fix successfully for a while now. I'd make a case for this because the fact that the current implementation fails to read mjpeg and only works when running the decode process via decode_one on the user side seems cumbersome. Decode should just work regardless of the codec used. The condition (codec==mjpeg) is easy to check for during decoding so why bother the lib user about this implementation detail? If its desired I'll create a PR. |
I agree with you that if the codec will only ever have a single frame per packet, to not bother trying for more. (I'd check again, but) MJPEG does seem to be that way. I wonder if there is already a flag or something on the codec descriptor... |
Hello,
I am struggling trying to open a MJPEG stream off an IP camera that opens without issue using ffplay. This happens with any MJPEG stream in my experience thus far.
I am receiving
AVError: [Errno 1094995529] Invalid data found when processing input
when callingdecode()
on thePacket
instance. I am using the libav from ffmpeg 2.6.3 on MacOSX.Not 100% sure if this is a bug or just operator error. The URL in my example is a demo URL from an IP camera manufacturer that displays the same problem.
Any thoughts?
For example:
outputs:
The text was updated successfully, but these errors were encountered: