diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d3f2929..65d36723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Add `FrameGrabber.videoDisposition/audioDisposition` properties to select streams by disposition ([pull #1879](https://github.com/bytedeco/javacv/pull/1879)) * Work around `OpenKinect2FrameGrabber` failing when provided with a pipeline on some system ([pull #1886](https://github.com/bytedeco/javacv/pull/1886)) * Fix `FFmpegFrameRecorder.record()` incorrectly flushing the video codec on data frames ([issue #1858](https://github.com/bytedeco/javacv/issues/1858)) * Improve accuracy of `FFmpegFrameGrabber.setFrameNumber()` ([pull #1851](https://github.com/bytedeco/javacv/pull/1851)) diff --git a/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java b/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java index e921a12d..bb57852e 100644 --- a/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java +++ b/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java @@ -980,10 +980,21 @@ public synchronized void startUnsafe(boolean findStreamInfo) throws Exception { av_dump_format(oc, 0, filename, 0); } + // Find the first stream with the user-specified disposition property + int nb_streams = oc.nb_streams(); + for (int i = 0; i < nb_streams; i++) { + AVStream st = oc.streams(i); + AVCodecParameters par = st.codecpar(); + if (videoStream < 0 && par.codec_type() == AVMEDIA_TYPE_VIDEO && st.disposition() == videoDisposition) { + videoStream = i; + } else if (audioStream < 0 && par.codec_type() == AVMEDIA_TYPE_AUDIO && st.disposition() == audioDisposition) { + audioStream = i; + } + } + // Find the first video and audio stream, unless the user specified otherwise video_st = audio_st = null; AVCodecParameters video_par = null, audio_par = null; - int nb_streams = oc.nb_streams(); streams = new int[nb_streams]; for (int i = 0; i < nb_streams; i++) { AVStream st = oc.streams(i); diff --git a/src/main/java/org/bytedeco/javacv/FrameGrabber.java b/src/main/java/org/bytedeco/javacv/FrameGrabber.java index d1b1313a..b819b0fa 100644 --- a/src/main/java/org/bytedeco/javacv/FrameGrabber.java +++ b/src/main/java/org/bytedeco/javacv/FrameGrabber.java @@ -180,6 +180,7 @@ public static enum SampleMode { SENSOR_PATTERN_BGGR = (1L << 32) | 1; protected int videoStream = -1, audioStream = -1; + protected int videoDisposition = 0, audioDisposition = 0; protected String format = null, videoCodecName = null, audioCodecName = null; protected int imageWidth = 0, imageHeight = 0, audioChannels = 0; protected ImageMode imageMode = ImageMode.COLOR; @@ -222,6 +223,20 @@ public void setAudioStream(int audioStream) { this.audioStream = audioStream; } + public void setVideoDisposition(int videoDisposition) { + this.videoDisposition = videoDisposition; + } + public int getVideoDisposition() { + return videoDisposition; + } + + public void setAudioDisposition(int audioDisposition) { + this.audioDisposition = audioDisposition; + } + public int getAudioDisposition() { + return audioDisposition; + } + public String getFormat() { return format; }