Skip to content

Commit a17a934

Browse files
committed
* Allow FFmpegFrameGrabber to use accelerated decoders with videoCodecName and audioCodecName properties (pull #948)
1 parent adc6180 commit a17a934

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
* Allow `FFmpegFrameGrabber` to use accelerated decoders with `videoCodecName` and `audioCodecName` properties ([pull #948](https://github.com/bytedeco/javacv/pull/948))
23
* Add new `KazemiFacemarkExample` and `LBFFacemarkExampleWithVideo` samples ([pull #1030](https://github.com/bytedeco/javacv/pull/1030))
34
* Expose `apiPreference` constructor argument of `VideoCapture` to `OpenCVFrameGrabber` ([pull #1025](https://github.com/bytedeco/javacv/pull/1025))
45
* Add `LeptonicaFrameConverter` to easily but efficiently pass image data to Tesseract ([issue bytedeco/javacpp-presets#224](https://github.com/bytedeco/javacpp-presets/issues/224))

src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,10 @@ void startUnsafe() throws Exception {
792792

793793
if (video_st != null) {
794794
// Find the decoder for the video stream
795-
AVCodec codec = avcodec_find_decoder(video_par.codec_id());
795+
AVCodec codec = avcodec_find_decoder_by_name(videoCodecName);
796+
if (codec == null) {
797+
codec = avcodec_find_decoder(video_par.codec_id());
798+
}
796799
if (codec == null) {
797800
throw new Exception("avcodec_find_decoder() error: Unsupported video format or codec not found: " + video_par.codec_id() + ".");
798801
}
@@ -836,7 +839,10 @@ void startUnsafe() throws Exception {
836839

837840
if (audio_st != null) {
838841
// Find the decoder for the audio stream
839-
AVCodec codec = avcodec_find_decoder(audio_par.codec_id());
842+
AVCodec codec = avcodec_find_decoder_by_name(audioCodecName);
843+
if (codec == null) {
844+
codec = avcodec_find_decoder(audio_par.codec_id());
845+
}
840846
if (codec == null) {
841847
throw new Exception("avcodec_find_decoder() error: Unsupported audio format or codec not found: " + audio_par.codec_id() + ".");
842848
}

src/main/java/org/bytedeco/javacv/FrameGrabber.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public static enum SampleMode {
178178
SENSOR_PATTERN_BGGR = (1L << 32) | 1;
179179

180180
protected int videoStream = -1, audioStream = -1;
181-
protected String format = null;
181+
protected String format = null, videoCodecName = null, audioCodecName = null;
182182
protected int imageWidth = 0, imageHeight = 0, audioChannels = 0;
183183
protected ImageMode imageMode = ImageMode.COLOR;
184184
protected long sensorPattern = -1L;
@@ -223,6 +223,20 @@ public void setFormat(String format) {
223223
this.format = format;
224224
}
225225

226+
public String getVideoCodecName() {
227+
return videoCodecName;
228+
}
229+
public void setVideoCodecName(String videoCodecName) {
230+
this.videoCodecName = videoCodecName;
231+
}
232+
233+
public String getAudioCodecName() {
234+
return audioCodecName;
235+
}
236+
public void setAudioCodecName(String audioCodecName) {
237+
this.audioCodecName = audioCodecName;
238+
}
239+
226240
public int getImageWidth() {
227241
return imageWidth;
228242
}

0 commit comments

Comments
 (0)