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
Video Decoding from Custom Stream: Way to Set Buffer Size? #150
Comments
I exposed that via Let us know if that does what you are looking for, and I'll figure out where the best place to put that in the API is (likely where I just put it). Cheers! |
Cool! Only downside is I don't think I can get to it for a couple days. Grrrr. Thanks, -kb |
Stupid question: How do I use it? I see the changes in av/stream.pyx, how do I set that in the canonical here-is-how-you-play-a-file example code I started from from https://mikeboers.github.io/PyAV/index.html ? Thanks, -kb |
Light of morning (before hitting the road) it looks like it will just show up as a property. Once I build 1fad83a. src/av/codec.c:286:33: fatal error: libavfilter/avcodec.h: No such file or directory I have /usr/include/libavcodec/avcodec.h A libav vs. ffmpeg issue? On Debian 8. Try "apt-get install libav-tools" (warned ffmpeg will be removed), same error. |
How did you install it before? What version did you have before? Can we see a more complete transcript of how you are attempting to build it? |
I did not succeed in building before. So my working case was, in the directory where I am hacking Python:
My failing case (one of my tries, first one today) was:
|
That is super weird, because the config did find it. Can you run |
|
I think I am have libav installed at the moment (for the doctor output). |
The options at this point are:
Can you find the libav headers, and determine if |
Neither FFmpeg or Libav appear to have that header. Huh. I wonder if it was deprecated (or something else)... |
A file by that name exists, but in a different directory:
Then locate finds /usr/include/libavcodec/avcodec.h Same locate output for both ffmpeg and libav installed cases. |
Um, that was supposed to be a crosshash followed by " updatedb" and got all interpreted... |
I've been editing your posts to wrap your code in triple back-ticks to format it. I also realized that this specific problem is in the filters implementation, which is brand new and not fully tested across platforms, so I'm not surprised it is giving you trouble. If you |
That builds. Whew. I'll let you know whether the delay property works for me, but I think it will be a few hours. Gotta pack and drive to Montreal now. |
Back to trying to use PyAV. I copied the results of my build from the PyAV venv to the venv where I am doing my work, and lifting from your Basic Demo, after the assignment to variable video, I print video.delay and it doesn't complain--good sign--it prints 0. And the demo runs. But no matter what I set it to it really wants to buffer--on my test data I need over a thousand frames before it starts reading any additional data while outputting frames. I reverted to the pip install version, and it complained about my accessing the delay property (so that part was real) but it behaves the same way, not reading additional data until the exact same frame. Am I using it wrong? Thanks, -kb |
Are you able to provide a sample of your file? Or a way to generate one with the same behavior? (Sent from my phone.)
|
I can upload my Python file, but it won't let me upload a 1MB mpeg test file. I could e-mail it... -kb |
Heck, it won't let me upload a .py file either. |
You can upload your small sample to https://www.dropbox.com/request/26cFYq3DBTWM0MKVjEuH |
I've isolated the reads to I could potentially add a I have also identified where the buffer size is set for Python IO, and could expose it, but I don't know where that could be helpful. |
My stream has distinctly funny frame rates, I make it by feeding only the frames I want, when I want, to code based on the Raspberry Pi hello_encode example. mplayer isn't very pleased with the result. Maybe I could make my stream more conventional, but I haven't figured out how.
That sounds promising: I would like to make the read buffering as small as possible and have it still work, to have it spit out a frame as promptly as possible when it has enough data. I would like it to make further read calls only when it really needs more data, because maybe this frame is really new and its compressed data didn't exist until a moment ago. And a moment later data for yet another frame will be available, but not quite yet. I expect I will lie on that seek() to the and tell() calls it makes. Yeah, sure, I have lots of data--just not yet. Some of the read calls will stall until I have more data. But constant timing isn't the point, I am looking to recreate the original frames I fed in, as frames again. Thanks, -kb |
I'm not sure adjusting the buffer size will do what you want. I think it is just how much the library will request, not how much it actually needs. It would be interesting to see if we could signal that you wont permit seeking, and then use a custom file-like object (e.g. a wrapper around a list of strings, popping one off on every read request). |
This was interesting: http://ffmpeg.org/pipermail/libav-user/2014-December/007672.html But I don't fully understand it. -kb |
Remember me? I'm wondering whether you have any new insights here. The reason I pester is I finally have an end-to-end implementation of my project. Terribly incomplete, but all the key pieces are in place, I have convinced it can all work and I know mostly how to make it all work. This is MPEG annoyance is big remaining wart... Earlier you wrote:
I am tossing compressed data that I concluded corresponds to exact input frame boundaries. I fed in frames one at a time, and collected the that came out each time. I figure that if I fed it a frame and if returned compressed data, then that same compressed data should be dang close to what is needed to reproduce something resembling the original frame. Or am I misunderstanding MPEG? Thanks, -kb |
Um, "...tossing..." as "...tossing around...", not discarding! Sorry, -kb |
Lots here to remind myself about. I wonder if #155 would help (e.g. exposing raw codecs without formats). Is what you uploaded to me (ages ago 😞) still roughly what is going on? You are streaming (effectively) a whole container file, and want to pull out frames with as little buffered data as possible. I wonder if B-frames are giving you a hard time (although the sample you gave me does not seem to have any). Looking at the file you gave me in March, I have to decode 12 packets before getting a frame (with the current master). Looks like the GOP size is ~40. So those don't line up... I really wish I could keep digging into this right now, but I have a really crazy deadline hanging over my head. You are welcome to come chat at me on Gitter (https://gitter.im/mikeboers/PyAV), but I can't do a ton myself. |
On 05/30/2016 06:20 PM, Mike Boers wrote:
Let me look at that. Maybe it would help.
I am feeding a frame at a time in and grabbing the compressed data
My encoding code was pretty closely lifted from a Raspberry Pi sample
Forget about it for the while. I have plenty of other stuff to work on, Thanks for your time--now get back to more important work! -kb |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Oh, am I impressed with how easy PyAV makes using ffmpeg! Thanks.
I am decoding video from a custom stream, I am managing to decode data in RAM and get image frames out. But the decoder wants to buffer data before giving me the first frame out. I would like to get each frame out as promptly as possible, and as I feed more data in, get out new frames--again as promptly as possibly.
Googling around there seems to be an ffmpeg option to control this: codec_ctx->delay (mentioned in http://ffmpeg.org/pipermail/libav-user/2014-December/007672.html).
Is that what I am looking for? Is there a way to set it via an av.open() option?
Thanks!
-kb
The text was updated successfully, but these errors were encountered: