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

Improve setting framenumber #1851

Merged
merged 56 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
be1080f
Change grabFrame loop to a single grabFrame after seeking backwards;
anotherche Feb 11, 2018
017ee9b
Change truncation to rounding in getLengthInFrames()
anotherche Feb 12, 2018
a95bf93
Merge branch 'master' into master
saudet Feb 12, 2018
46b91f7
new setTimestamp code;
anotherche Feb 17, 2018
6ba9633
Add seek in audio only files;
anotherche Feb 18, 2018
f6a45e0
Set frameGrabbed = false after grabFrame
anotherche Feb 18, 2018
21c87b2
switch on other test
anotherche Feb 18, 2018
73fe5a6
Merge branch 'master' into master
saudet Feb 21, 2018
0970fa6
Merge branch 'master' into master
saudet Feb 21, 2018
495fe91
Seek test repair
anotherche Feb 22, 2018
0b53f58
Add a possibility to seek by specified types of frames
anotherche Feb 24, 2018
50158f4
Merge remote-tracking branch 'upstream/master'
saudet Mar 9, 2018
fea0388
setVideoTimestamp()
anotherche Mar 9, 2018
4daf9fb
seeking tolerance adjust
anotherche Mar 9, 2018
db2d196
Merge remote-tracking branch 'origin/master'
anotherche Mar 9, 2018
15d2dbb
Fix formatting
saudet Mar 11, 2018
4aa7446
add Frame.Type to use in Frame.getType() and setTimestamp();
anotherche Mar 12, 2018
d9d0430
Adjust a few minor details
saudet Mar 28, 2018
53fc429
Returns possibility to use old seeking code (prior to v. 1.4.1)
anotherche Mar 31, 2018
40d4f45
Merge branch 'master' into master
anotherche Apr 1, 2018
2e02865
Change setFrameNumber() to use old setTimestamp() code by default
anotherche Apr 1, 2018
32a8e19
Merge remote-tracking branch 'origin/master'
anotherche Apr 1, 2018
24dcfa5
Revert a couple more changes and fix formatting
saudet Apr 22, 2018
1b638d6
Merge remote-tracking branch 'upstream/master'
anotherche Nov 24, 2020
655b9ba
Merge branch 'bytedeco:master' into master
anotherche Oct 8, 2021
9f33d36
# 1689 and # 1697
anotherche Dec 30, 2021
d53b6e5
Merge branch 'master' into framenumber
saudet Jan 3, 2022
84cfe60
Frame enum Type reorder and grabFrame readPacket condition fix
anotherche Jan 4, 2022
2211262
Merge remote-tracking branch 'origin/framenumber' into framenumber
anotherche Jan 5, 2022
668633b
clean doData handling scheme
anotherche Jan 7, 2022
9cf3063
Fix formatting
saudet Jan 13, 2022
2afd9fb
Update CHANGELOG.md
saudet Jan 13, 2022
c03208a
Merge branch 'bytedeco:master' into master
anotherche Jul 28, 2022
5de60ba
fix rounding errors when evaluating and setting frameNumber
anotherche Jul 28, 2022
cd29fed
Merge branch 'framenumber' of ssh://[email protected]/anotherche/javacv.…
anotherche Jul 28, 2022
0f09f4e
# 1689 and # 1697
anotherche Dec 30, 2021
b28af8d
Frame enum Type reorder and grabFrame readPacket condition fix
anotherche Jan 4, 2022
a6d2fff
* Call `Frame.close()` on temporary clones in `Java2DFrameUtils` to …
saudet Nov 6, 2021
252cb1a
* Upgrade dependencies for OpenBLAS 0.3.18, OpenCV 4.5.4, FFmpeg 4.4…
saudet Nov 6, 2021
cce5c6d
* Add `charset` property to `FrameGrabber` and `FrameRecorder` to us…
Konyaco Nov 19, 2021
2867966
* Set metadata for `AVFrame.opaque` in `FFmpegFrameGrabber` with cal…
saudet Dec 10, 2021
72f2284
* Add new `Frame.pictType` field set to `I`, `P`, `B`, etc by `FFmpe…
steeveen Dec 13, 2021
c0826d5
* Upgrade dependencies for librealsense2 2.50.0
saudet Dec 14, 2021
438a528
clean doData handling scheme
anotherche Jan 7, 2022
e980ac2
fix rounding errors when evaluating and setting frameNumber
anotherche Jul 28, 2022
4f57918
Fix formatting
saudet Jan 13, 2022
58ee2aa
Update CHANGELOG.md
saudet Jan 13, 2022
b1254be
Merge branch 'framenumber' of ssh://[email protected]/anotherche/javacv.…
anotherche Jul 28, 2022
b08c6ed
revert to Math.round in frameNumber calculation
anotherche Jul 28, 2022
8aa5d9c
comment cleanup
anotherche Jul 28, 2022
54b2fc0
Merge branch 'master' of ssh://github.com/anotherche/javacv
anotherche Jul 28, 2022
289baba
improved frameNumber setting
anotherche Jul 28, 2022
587bc88
fix setAudioFrameNumber and remove unnecessary part of test
anotherche Jul 29, 2022
716eed3
test of sequential setVideoFrameNumber (issue #1697)
anotherche Jul 29, 2022
d194ec1
Update CHANGELOG.md and fix formatting
saudet Aug 2, 2022
24548f9
Merge branch 'master' into framenumber
saudet Aug 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Improve accuracy of `FFmpegFrameGrabber.setFrameNumber()` ([pull #1851](https://github.com/bytedeco/javacv/pull/1851))
* Add `FrameGrabber.resetStartTime()` to allow `grabAtFrameRate()` after operations such as seeking ([pull #1846](https://github.com/bytedeco/javacv/pull/1846))
* Add `FrameGrabber.videoSideData/audioSideData` properties and `FFmpegFrameGrabber.getDisplayRotation()` for convenience ([issue #1361](https://github.com/bytedeco/javacv/issues/1361))
* Add to `FFmpegFrameGrabber` and `FFmpegFrameRecorder` constructors taking a `URL` for convenience and clarity
Expand Down
12 changes: 12 additions & 0 deletions platform/src/test/java/org/bytedeco/javacv/FrameGrabberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ public void testFFmpegFrameGrabberSeeking() throws IOException {
assertTrue(frame.image != null ^ frame.samples != null);
System.out.println(timestamp2 + " - " + timestamp + " = " + delta + " type: " + frame.getTypes());
assertTrue(Math.abs(delta) < tolerance);
/*
if (seektestnum==0) {
boolean wasVideo = frame.image != null;
boolean wasAudio = frame.samples != null;
Expand All @@ -423,12 +424,23 @@ public void testFFmpegFrameGrabberSeeking() throws IOException {
System.out.println(timestamp3 + " - " + timestamp + " = " + (timestamp3 - timestamp));
assertTrue(timestamp3 >= timestamp - tolerance && timestamp3 < timestamp + tolerance);
}
*/
}
System.out.println();
System.out.println("------------------------------------");
System.out.println("delta from " + mindelta + " to " + maxdelta);
System.out.println();
}
if (seektestnum==0) {
System.out.println();
System.out.println("======== Check sequential setVideoFrameNumber (issue #1697) ========");
for (int i = 0; i < 10; i++) {
grabber.setVideoFrameNumber(i);
long timestamp = grabber.grabImage().timestamp;
System.out.println("frame number:" + i + " timestamp:" + timestamp);
assertTrue(i == Math.round(timestamp * grabber.getFrameRate() / 1000000L));
}
}
if (seektestnum==2) {

long count1 = 0;
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,24 +652,23 @@ public double getDisplayRotation() {
/** default override of super.setFrameNumber implies setting
* of a frame close to a video frame having that number */
@Override public void setFrameNumber(int frameNumber) throws Exception {
if (hasVideo()) setTimestamp((long)Math.floor(1000000L * frameNumber / getFrameRate()));
if (hasVideo()) setTimestamp(Math.round((1000000L * frameNumber + 500000L)/ getFrameRate()));
else super.frameNumber = frameNumber;
}

/** if there is video stream tries to seek to video frame with corresponding timestamp
* otherwise sets super.frameNumber only because frameRate==0 if there is no video stream */
public void setVideoFrameNumber(int frameNumber) throws Exception {
// best guess, AVSEEK_FLAG_FRAME has not been implemented in FFmpeg...
if (hasVideo()) setVideoTimestamp((long)Math.floor(1000000L * frameNumber / getFrameRate()));
if (hasVideo()) setVideoTimestamp(Math.round((1000000L * frameNumber + 500000L)/ getFrameRate()));
else super.frameNumber = frameNumber;
}

/** if there is audio stream tries to seek to audio frame with corresponding timestamp
* ignoring otherwise */
public void setAudioFrameNumber(int frameNumber) throws Exception {
// best guess, AVSEEK_FLAG_FRAME has not been implemented in FFmpeg...
if (hasAudio()) setAudioTimestamp((long)Math.floor(1000000L * frameNumber / getAudioFrameRate()));

if (hasAudio()) setAudioTimestamp(Math.round((1000000L * frameNumber + 500000L)/ getAudioFrameRate()));
}

/** setTimestamp without checking frame content (using old code used in JavaCV versions prior to 1.4.1) */
Expand Down Expand Up @@ -1464,7 +1463,7 @@ public synchronized Frame grabFrame(boolean doAudio, boolean doVideo, boolean do
AVRational time_base = video_st.time_base();
timestamp = 1000000L * pts * time_base.num() / time_base.den();
// best guess, AVCodecContext.frame_number = number of decoded frames...
frameNumber = (int)Math.floor(timestamp * getFrameRate() / 1000000L);
frameNumber = (int)Math.round(timestamp * getFrameRate() / 1000000L);
frame.image = image_buf;
if (doProcessing) {
processImage();
Expand Down