Skip to content

Commit

Permalink
* Add the ability to specify from which video and audio streams `FFm…
Browse files Browse the repository at this point in the history
…pegFrameGrabber` should grab from (issue #135)
  • Loading branch information
saudet committed Apr 29, 2015
1 parent 918c754 commit 07f1e4f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,4 +1,5 @@

* Add the ability to specify from which video and audio streams `FFmpegFrameGrabber` should grab from ([issue #135](https://github.com/bytedeco/javacv/issues/135))
* Fix `Java2DFrameConverter` when used with `BufferedImage.TYPE_INT_RGB` or other types based on `int`
* Add new `WebcamAndMicrophoneCapture` sample ([pull #131](https://github.com/bytedeco/javacv/pull/131))
* Add `aspectRatio` property to `FrameGrabber` and `FrameRecorder`, to be able to use pixel aspect ratios other than 1.0 ([issue #90](https://github.com/bytedeco/javacv/issues/90))
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Expand Up @@ -413,23 +413,24 @@ public void startUnsafe() throws Exception {
// Dump information about file onto standard error
av_dump_format(oc, 0, filename, 0);

// Find the first video and audio stream
// Find the first video and audio stream, unless the user specified otherwise
video_st = audio_st = null;
int nb_streams = oc.nb_streams();
for (int i = 0; i < nb_streams; i++) {
AVStream st = oc.streams(i);
// Get a pointer to the codec context for the video or audio stream
AVCodecContext c = st.codec();
if (video_st == null && c.codec_type() == AVMEDIA_TYPE_VIDEO) {
if (video_st == null && c.codec_type() == AVMEDIA_TYPE_VIDEO && (videoStream < 0 || videoStream == i)) {
video_st = st;
video_c = c;
} else if (audio_st == null && c.codec_type() == AVMEDIA_TYPE_AUDIO) {
} else if (audio_st == null && c.codec_type() == AVMEDIA_TYPE_AUDIO && (audioStream < 0 || audioStream == i)) {
audio_st = st;
audio_c = c;
}
}
if (video_st == null && audio_st == null) {
throw new Exception("Did not find a video or audio stream inside \"" + filename + "\".");
throw new Exception("Did not find a video or audio stream inside \"" + filename
+ "\" for videoStream == " + videoStream + " and audioStream == " + audioStream + ".");
}

if (video_st != null) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/bytedeco/javacv/FrameGrabber.java
Expand Up @@ -164,6 +164,7 @@ public static enum ImageMode {
SENSOR_PATTERN_GRBG = 1,
SENSOR_PATTERN_BGGR = (1L << 32) | 1;

protected int videoStream = -1, audioStream = -1;
protected String format = null;
protected int imageWidth = 0, imageHeight = 0, audioChannels = 0;
protected ImageMode imageMode = ImageMode.COLOR;
Expand All @@ -181,6 +182,20 @@ public static enum ImageMode {
protected int frameNumber = 0;
protected long timestamp = 0;

public int getVideoStream() {
return videoStream;
}
public void setVideoStream(int videoStream) {
this.videoStream = videoStream;
}

public int getAudioStream() {
return audioStream;
}
public void setAudioStream(int audioStream) {
this.audioStream = audioStream;
}

public String getFormat() {
return format;
}
Expand Down

0 comments on commit 07f1e4f

Please sign in to comment.