Skip to content

Commit

Permalink
* Add support for multiple inputs to FFmpegFrameFilter (issue #955)
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Oct 28, 2018
1 parent e2e62ce commit 3c92eef
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 76 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 multiple inputs to `FFmpegFrameFilter` ([issue #955](https://github.com/bytedeco/javacv/issues/955))
* Fix fps in output of `FFmpegFrameRecorder` by setting deprecated `AVStream.codec.time_base` ([issue #1069](https://github.com/bytedeco/javacv/issues/1069))
* Fix memory leak in `FFmpegFrameRecorder` on `writePacket()` ([issue #1068](https://github.com/bytedeco/javacv/issues/1068))
* Upgrade dependencies for Tesseract 4.0.0-rc3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
JavaCV
======

[![Join the chat at https://gitter.im/bytedeco/javacv](https://badges.gitter.im/bytedeco/javacv.svg)](https://gitter.im/bytedeco/javacv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/javacv/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/javacv) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.bytedeco/javacv.svg)](http://bytedeco.org/builds/) [![Build Status](https://travis-ci.org/bytedeco/javacv.svg?branch=master)](https://travis-ci.org/bytedeco/javacv)
[![Join the chat at https://gitter.im/bytedeco/javacv](https://badges.gitter.im/bytedeco/javacv.svg)](https://gitter.im/bytedeco/javacv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/javacv-platform/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.bytedeco/javacv-platform) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.bytedeco/javacv.svg)](http://bytedeco.org/builds/) [![Build Status](https://travis-ci.org/bytedeco/javacv.svg?branch=master)](https://travis-ci.org/bytedeco/javacv)

Introduction
------------
Expand Down
84 changes: 84 additions & 0 deletions platform/src/test/java/org/bytedeco/javacv/FrameFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,88 @@ public void testFFmpegFrameFilter() {
tempFile.delete();
}
}

@Test
public void testFFmpegFrameFilterMultipleInputs() {
System.out.println("FFmpegFrameFilterMultipleInputs");

File tempFile = new File(Loader.getTempDir(), "test.avi");
try {
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(tempFile, 320, 200, 2);
recorder.setVideoCodec(AV_CODEC_ID_VP8);
recorder.setAudioCodec(AV_CODEC_ID_VORBIS);
recorder.start();

int n = 1000;
Frame frame = new Frame(320, 200, Frame.DEPTH_UBYTE, 3);
for (int i = 0; i < n; i++) {
recorder.record(frame);
}
Frame audioFrame = new Frame();
ShortBuffer audioBuffer = ShortBuffer.allocate(8000 * 2 * n / 30);
audioFrame.sampleRate = 8000;
audioFrame.audioChannels = 2;
audioFrame.samples = new ShortBuffer[] {audioBuffer};
recorder.record(audioFrame);
recorder.stop();
recorder.release();

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(tempFile);
grabber.start();

FFmpegFrameFilter filter = new FFmpegFrameFilter(
"[0:v][1:v]hstack=inputs=2[v]",
"[0:a][1:a]amerge[a]",
grabber.getImageWidth(), grabber.getImageHeight(), grabber.getAudioChannels());
filter.setPixelFormat(grabber.getPixelFormat());
filter.setSampleFormat(grabber.getSampleFormat());
filter.setVideoInputs(2);
filter.setAudioInputs(2);
filter.start();

int a = 0, b = 0, c = 0, d = 0;
Frame frame2;
while ((frame2 = grabber.grab()) != null) {
if (frame2.image != null) {
a++;
}
if (frame2.samples != null) {
b++;
}
filter.push(0, frame2);
filter.push(1, frame2);
Frame frame3;
while ((frame3 = filter.pull()) != null) {
if (frame3.image != null) {
c++;
assertEquals(640, frame3.imageWidth);
assertEquals(200, frame3.imageHeight);
assertEquals(3, frame3.imageChannels);
}
if (frame3.samples != null) {
d++;
assertEquals(2, frame3.audioChannels);
assertEquals(1, frame3.samples.length);
assertTrue(frame3.samples[0] instanceof ByteBuffer);
assertEquals(frame2.samples.length, frame3.samples.length);
assertEquals(frame2.samples[0].limit(), frame3.samples[0].limit());
}
}
}
assertEquals(a, c);
assertEquals(b, d);
assertEquals(null, grabber.grab());
filter.stop();
filter.release();
grabber.restart();
grabber.stop();
grabber.release();
} catch (Exception e) {
e.printStackTrace();
fail("Exception should not have been thrown: " + e);
} finally {
tempFile.delete();
}
}

}
Loading

0 comments on commit 3c92eef

Please sign in to comment.