Skip to content

Commit

Permalink
* Add support for AVSEEK_SIZE to FFmpegFrameGrabber as required …
Browse files Browse the repository at this point in the history
…by MPEG-TS (issue #1234)
  • Loading branch information
saudet committed Jun 25, 2019
1 parent 5f2ff6a commit 5191628
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Add support for `AVSEEK_SIZE` to `FFmpegFrameGrabber` as required by MPEG-TS ([issue #1234](https://github.com/bytedeco/javacv/issues/1234))
* Throw exception on `start()` for already started `FFmpegFrameFilter`, `FFmpegFrameGrabber`, or `FFmpegFrameRecorder` ([issue #1233](https://github.com/bytedeco/javacv/issues/1233))
* Add dependency on OpenBLAS/MKL, now used by OpenCV to accelerate some matrix operations
* Upgrade dependencies for OpenCV 4.1.0, libdc1394 2.2.6
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,36 @@ static class SeekCallback extends Seek_Pointer_long_int {
@Override public long call(Pointer opaque, long offset, int whence) {
try {
InputStream is = inputStreams.get(opaque);
long size = 0;
switch (whence) {
case 0: is.reset(); break;
case 1: break;
case 0: is.reset(); break; // SEEK_SET
case 1: break; // SEEK_CUR
case 2: // SEEK_END
is.reset();
while (true) {
long n = is.skip(Long.MAX_VALUE);
if (n == 0) break;
size += n;
}
offset += size;
is.reset();
break;
case AVSEEK_SIZE:
long remaining = 0;
while (true) {
long n = is.skip(Long.MAX_VALUE);
if (n == 0) break;
remaining += n;
}
is.reset();
while (true) {
long n = is.skip(Long.MAX_VALUE);
if (n == 0) break;
size += n;
}
offset = size - remaining;
is.reset();
break;
default: return -1;
}
long remaining = offset;
Expand All @@ -302,7 +329,7 @@ static class SeekCallback extends Seek_Pointer_long_int {
if (skipped == 0) break; // end of the stream
remaining -= skipped;
}
return 0;
return whence == AVSEEK_SIZE ? size : 0;
} catch (Throwable t) {
System.err.println("Error on InputStream.reset() or skip(): " + t);
return -1;
Expand Down

0 comments on commit 5191628

Please sign in to comment.