From 07f1e4fd9895491229f22480aa1b23634d9d0ab4 Mon Sep 17 00:00:00 2001 From: Samuel Audet Date: Wed, 29 Apr 2015 15:02:03 +0900 Subject: [PATCH] * Add the ability to specify from which video and audio streams `FFmpegFrameGrabber` should grab from (issue #135) --- CHANGELOG.md | 1 + .../org/bytedeco/javacv/FFmpegFrameGrabber.java | 9 +++++---- .../java/org/bytedeco/javacv/FrameGrabber.java | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58a0db4c..3032b6f7 100644 --- a/CHANGELOG.md +++ b/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)) diff --git a/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java b/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java index f72a5806..f47269e7 100644 --- a/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java +++ b/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java @@ -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) { diff --git a/src/main/java/org/bytedeco/javacv/FrameGrabber.java b/src/main/java/org/bytedeco/javacv/FrameGrabber.java index af1e37c2..6aea5a58 100644 --- a/src/main/java/org/bytedeco/javacv/FrameGrabber.java +++ b/src/main/java/org/bytedeco/javacv/FrameGrabber.java @@ -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; @@ -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; }