Skip to content

Commit

Permalink
Fix a timestamp rounding issue in FFmpegFrameGrabber that causes `s…
Browse files Browse the repository at this point in the history
…etFrameNumber()` to sometimes pick the wrong frame if FPS is not a proper divisor of 1000000 (issue bytedeco#5)
  • Loading branch information
juergenuhl committed May 13, 2014
1 parent 923d813 commit ebfda82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

* Fix a timestamp rounding issue in `FFmpegFrameGrabber` that causes `setFrameNumber()` to sometimes pick the wrong frame if FPS is not a proper divisor of 1000000 ([issue #5](https://github.com/bytedeco/javacv/issues/5))
* Increase the flexibility of the `pom.xml` file by making it possible to specify a custom version of JavaCPP
* Add missing dependencies for JogAmp in the `pom.xml` file ([issue #2](https://github.com/bytedeco/javacv/issues/2))
* Add new `OpenCVFaceRecognizer` sample, thanks to Petter Christian Bjelland
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,16 @@ public void releaseUnsafe() throws Exception {
pkt2.size(0);
av_free_packet(pkt);
}
while (this.timestamp > timestamp && grabFrame(false) != null) {
/* comparing to timestamp +/- 1 avoids rouding issues for framerates
which are no proper divisors of 1000000, e.g. where
av_frame_get_best_effort_timestamp in grabFrame sets this.timestamp
to ...666 and the given timestamp has been rounded to ...667
(or vice versa)
*/
while (this.timestamp > timestamp + 1 && grabFrame(false) != null) {
// flush frames if seeking backwards
}
while (this.timestamp < timestamp && grabFrame(false) != null) {
while (this.timestamp < timestamp - 1 && grabFrame(false) != null) {
// decode up to the desired frame
}
if (video_c != null) {
Expand Down

0 comments on commit ebfda82

Please sign in to comment.