From cd25ac331f1f05dd2abedba71f2a33052d4b6cad Mon Sep 17 00:00:00 2001 From: Tengyyy Date: Sat, 5 Nov 2022 03:06:28 +0200 Subject: [PATCH] improve disposition properties --- src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java | 8 ++++++++ src/main/java/org/bytedeco/javacv/FrameGrabber.java | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java b/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java index 35d0c1ac..4f304e22 100644 --- a/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java +++ b/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java @@ -990,17 +990,25 @@ public synchronized void startUnsafe(boolean findStreamInfo) throws Exception { } // Find the first stream with the user-specified disposition property + boolean videoStreamFound = false; + boolean audioStreamFound = false; 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; + videoStreamFound = true; } else if (audioStream < 0 && par.codec_type() == AVMEDIA_TYPE_AUDIO && st.disposition() == audioDisposition) { audioStream = i; + audioStreamFound = true; } } + // resets the disposition value if a stream with the specified disposition value isnt found, so the user would know + if(!videoStreamFound) setVideoDisposition(AV_DISPOSITION_DEFAULT); + if(!audioStreamFound) setAudioDisposition(AV_DISPOSITION_DEFAULT); + // Find the first video and audio stream, unless the user specified otherwise video_st = audio_st = null; AVCodecParameters video_par = null, audio_par = null; diff --git a/src/main/java/org/bytedeco/javacv/FrameGrabber.java b/src/main/java/org/bytedeco/javacv/FrameGrabber.java index b819b0fa..fd955b3a 100644 --- a/src/main/java/org/bytedeco/javacv/FrameGrabber.java +++ b/src/main/java/org/bytedeco/javacv/FrameGrabber.java @@ -40,6 +40,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; +import static org.bytedeco.ffmpeg.global.avformat.AV_DISPOSITION_DEFAULT; + /** * * @author Samuel Audet @@ -180,7 +182,7 @@ public static enum SampleMode { SENSOR_PATTERN_BGGR = (1L << 32) | 1; protected int videoStream = -1, audioStream = -1; - protected int videoDisposition = 0, audioDisposition = 0; + protected int videoDisposition = AV_DISPOSITION_DEFAULT, audioDisposition = AV_DISPOSITION_DEFAULT; protected String format = null, videoCodecName = null, audioCodecName = null; protected int imageWidth = 0, imageHeight = 0, audioChannels = 0; protected ImageMode imageMode = ImageMode.COLOR;