Skip to content

Commit

Permalink
* Add FrameGrabber.videoDisposition/audioDisposition properties to…
Browse files Browse the repository at this point in the history
… select streams by disposition (pull bytedeco#1879)
  • Loading branch information
Tengyyy authored Oct 2, 2022
1 parent 72e9a2a commit e47cb2f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/bytedeco/javacv/FrameGrabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e47cb2f

Please sign in to comment.