Skip to content
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

Fix FFmpegFrameGrabber to properly seek/skip the data inside custom InputStream #703

Merged
merged 2 commits into from
May 28, 2017

Conversation

teerapap
Copy link
Contributor

The code previously did not respect InputStream.skip() return value. It leads to wrong seek result because the data might not be skipped to the desired offset.

It also assumed that the maximum input stream size is 1MB which might not be the case for bigger file. The problem arises when that the data after 1MB offset is read and the mark position is reset. It leads to InputStream.reset() not reset to the start of the stream as expected.

This merge requests

  • Respect the InputStream.skip() return value
  • Assume the input stream maximum size is at integer maximum.

…nputStream

* Respect the InputStream.skip() return value
* Mark the whole stream so that it can be freely seekable
@saudet
Copy link
Member

saudet commented May 26, 2017

Thanks! But we shouldn't force users to allocate 2 GB of memory to hold the whole stream. Let's make this configurable, via an optional constructor parameter would be best I believe.

@teerapap
Copy link
Contributor Author

@saudet Thanks for the fast response. It is my bug that I pre-allocate big size of the buffer of BufferedInputStream. I fix it in the latest commit.

Calling mark() with big size does not mean the stream have to allocate the buffer with the same size. At least BufferedInputStream does not do that. It grows its internal buffer as needed.

I'll add another constructor to set this size then.

@teerapap
Copy link
Contributor Author

teerapap commented May 26, 2017

@saudet If I add another constructor with optional maximumSize of the InputStream.
What should be the default value?

  • 1024*1024 to be backward compatible.
    or
  • Integer.MAX_VALUE-8 to cover bigger files by default and let the user set it to lower size if desired.

@saudet
Copy link
Member

saudet commented May 26, 2017 via email

@saudet
Copy link
Member

saudet commented May 28, 2017

Actually, it looks like you're right. Reading an MP4 file works even without passing the size of the buffer as argument to the BufferedInputStream, interesting. How does that work?

@saudet
Copy link
Member

saudet commented May 28, 2017

It does increase its internal buffer as needed. So, looks good to me as it is now. Thanks for the contribution!

@saudet saudet merged commit 3d58a5a into bytedeco:master May 28, 2017
@teerapap
Copy link
Contributor Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants