Skip to content

Commit

Permalink
* Add imageScalingFlags property to FrameGrabber and `FrameRecor…
Browse files Browse the repository at this point in the history
…der`, with `SWS_BILINEAR` as default for FFmpeg (issue #845)
  • Loading branch information
saudet committed Oct 12, 2018
1 parent 3415869 commit 77addc5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Add `imageScalingFlags` property to `FrameGrabber` and `FrameRecorder`, with `SWS_BILINEAR` as default for FFmpeg ([issue #845](https://github.com/bytedeco/javacv/issues/845))
* Add `OpenCVFrameConverter.ToOrgOpenCvCoreMat` to easily but efficiently get image data from official Java API of OpenCV ([issue bytedeco/javacpp#38](https://github.com/bytedeco/javacpp/issues/38))
* Keep globally shared callback objects for FFmpeg out of `PointerScope` ([issue #911](https://github.com/bytedeco/javacv/issues/911))
* Upgrade dependencies for OpenCV 3.4.3, FFmpeg 4.0.2, and Tesseract 4.0.0-rc2
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2017 Samuel Audet
* Copyright (C) 2009-2018 Samuel Audet
*
* Licensed either under the Apache License, Version 2.0, or (at your option)
* under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -967,7 +967,8 @@ private void processImage() throws Exception {
// Convert the image into BGR or GRAY format that OpenCV uses
img_convert_ctx = sws_getCachedContext(img_convert_ctx,
video_c.width(), video_c.height(), video_c.pix_fmt(),
frame.imageWidth, frame.imageHeight, getPixelFormat(), SWS_BILINEAR,
frame.imageWidth, frame.imageHeight, getPixelFormat(),
imageScalingFlags != 0 ? imageScalingFlags : SWS_BILINEAR,
null, null, (DoublePointer)null);
if (img_convert_ctx == null) {
throw new Exception("sws_getCachedContext() error: Cannot initialize the conversion context.");
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/bytedeco/javacv/FFmpegFrameRecorder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2017 Samuel Audet
* Copyright (C) 2009-2018 Samuel Audet
*
* Licensed either under the Apache License, Version 2.0, or (at your option)
* under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -919,7 +919,8 @@ public boolean recordImage(int width, int height, int depth, int channels, int s
if (video_c.pix_fmt() != pixelFormat || video_c.width() != width || video_c.height() != height) {
/* convert to the codec pixel format if needed */
img_convert_ctx = sws_getCachedContext(img_convert_ctx, width, height, pixelFormat,
video_c.width(), video_c.height(), video_c.pix_fmt(), SWS_BILINEAR,
video_c.width(), video_c.height(), video_c.pix_fmt(),
imageScalingFlags != 0 ? imageScalingFlags : SWS_BILINEAR,
null, null, (DoublePointer)null);
if (img_convert_ctx == null) {
throw new Exception("sws_getCachedContext() error: Cannot initialize the conversion context.");
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/bytedeco/javacv/FrameGrabber.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2015 Samuel Audet
* Copyright (C) 2009-2018 Samuel Audet
*
* Licensed either under the Apache License, Version 2.0, or (at your option)
* under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -182,7 +182,7 @@ public static enum SampleMode {
protected int imageWidth = 0, imageHeight = 0, audioChannels = 0;
protected ImageMode imageMode = ImageMode.COLOR;
protected long sensorPattern = -1L;
protected int pixelFormat = -1, videoCodec, videoBitrate = 0;
protected int pixelFormat = -1, videoCodec, videoBitrate = 0, imageScalingFlags = 0;
protected double aspectRatio = 0, frameRate = 0;
protected SampleMode sampleMode = SampleMode.SHORT;
protected int sampleFormat = -1, audioCodec, audioBitrate = 0, sampleRate = 0;
Expand Down Expand Up @@ -293,6 +293,13 @@ public void setVideoBitrate(int videoBitrate) {
this.videoBitrate = videoBitrate;
}

public int getImageScalingFlags() {
return imageScalingFlags;
}
public void setImageScalingFlags(int imageScalingFlags) {
this.imageScalingFlags = imageScalingFlags;
}

public double getAspectRatio() {
return aspectRatio;
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/bytedeco/javacv/FrameRecorder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2015 Samuel Audet
* Copyright (C) 2009-2018 Samuel Audet
*
* Licensed either under the Apache License, Version 2.0, or (at your option)
* under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -106,7 +106,7 @@ public static FrameRecorder create(String className, String filename, int width,

protected String format, videoCodecName, audioCodecName;
protected int imageWidth, imageHeight, audioChannels;
protected int pixelFormat, videoCodec, videoBitrate, gopSize = -1;
protected int pixelFormat, videoCodec, videoBitrate, imageScalingFlags, gopSize = -1;
protected double aspectRatio, frameRate, videoQuality = -1;
protected int sampleFormat, audioCodec, audioBitrate, sampleRate;
protected double audioQuality = -1;
Expand Down Expand Up @@ -186,6 +186,13 @@ public void setVideoBitrate(int videoBitrate) {
this.videoBitrate = videoBitrate;
}

public int getImageScalingFlags() {
return imageScalingFlags;
}
public void setImageScalingFlags(int imageScalingFlags) {
this.imageScalingFlags = imageScalingFlags;
}

public int getGopSize() {
return gopSize;
}
Expand Down

0 comments on commit 77addc5

Please sign in to comment.