Skip to content

Commit

Permalink
fix setAudioFrameNumber and remove unnecessary part of test
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherche committed Jul 29, 2022
1 parent 289baba commit 587bc88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
30 changes: 16 additions & 14 deletions platform/src/test/java/org/bytedeco/javacv/FrameGrabberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,20 +409,22 @@ 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;
Frame frame2 = grabber.grab();
while ((wasVideo && frame2.image != null)
|| (wasAudio && frame2.samples != null)) {
frame2 = grabber.grab();
}
assertTrue(wasVideo ^ frame2.image != null);
assertTrue(wasAudio ^ frame2.samples != null);
long timestamp3 = grabber.getTimestamp();
System.out.println(timestamp3 + " - " + timestamp + " = " + (timestamp3 - timestamp));
assertTrue(timestamp3 >= timestamp - tolerance && timestamp3 < timestamp + tolerance);
}
/*
if (seektestnum==0) {
boolean wasVideo = frame.image != null;
boolean wasAudio = frame.samples != null;
Frame frame2 = grabber.grab();
while ((wasVideo && frame2.image != null)
|| (wasAudio && frame2.samples != null)) {
frame2 = grabber.grab();
}
assertTrue(wasVideo ^ frame2.image != null);
assertTrue(wasAudio ^ frame2.samples != null);
long timestamp3 = grabber.getTimestamp();
System.out.println(timestamp3 + " - " + timestamp + " = " + (timestamp3 - timestamp));
assertTrue(timestamp3 >= timestamp - tolerance && timestamp3 < timestamp + tolerance);
}
*/
}
System.out.println();
System.out.println("------------------------------------");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public void setVideoFrameNumber(int frameNumber) throws Exception {
* ignoring otherwise */
public void setAudioFrameNumber(int frameNumber) throws Exception {
// best guess, AVSEEK_FLAG_FRAME has not been implemented in FFmpeg...
if (hasAudio()) setAudioTimestamp(Math.round((1000000L * frameNumber + 500000L)/ getFrameRate()));
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

0 comments on commit 587bc88

Please sign in to comment.