From 13e74b147abe530e0373c836bcadaa4cf58fad84 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Fri, 31 May 2019 19:02:28 -0500 Subject: [PATCH 1/7] Adding new CheckPixel method to validate a specific pixel color --- include/Frame.h | 3 +++ src/Frame.cpp | 22 ++++++++++++++++++++++ tests/FFmpegReader_Tests.cpp | 8 ++++++++ 3 files changed, 33 insertions(+) diff --git a/include/Frame.h b/include/Frame.h index 56a2a3ec..72822188 100644 --- a/include/Frame.h +++ b/include/Frame.h @@ -249,6 +249,9 @@ namespace openshot /// Get pixel data (for only a single scan-line) const unsigned char* GetPixels(int row); + /// Check a specific pixel color value (returns True/False) + bool CheckPixel(int row, int col, int red, int green, int blue, int alpha); + /// Get height of image int GetHeight(); diff --git a/src/Frame.cpp b/src/Frame.cpp index 6ef44d67..27bf5f71 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -480,6 +480,28 @@ const unsigned char* Frame::GetPixels(int row) return image->scanLine(row); } +// Check a specific pixel color value (returns True/False) +bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha) { + int col_pos = col * 4; // Find column array position + if (!image || row < 0 || row >= (height - 1) || + col_pos < 0 || col_pos >= (width - 1) ) { + // invalid row / col + return false; + } + // Check pixel color + const unsigned char* pixels = GetPixels(row); + if (pixels[col_pos + 0] == red && + pixels[col_pos + 1] == green && + pixels[col_pos + 2] == blue && + pixels[col_pos + 3] == alpha) { + // Pixel color matches successfully + return true; + } else { + // Pixel color does not match + return false; + } +} + // Set Pixel Aspect Ratio void Frame::SetPixelRatio(int num, int den) { diff --git a/tests/FFmpegReader_Tests.cpp b/tests/FFmpegReader_Tests.cpp index 53563cac..454420a4 100644 --- a/tests/FFmpegReader_Tests.cpp +++ b/tests/FFmpegReader_Tests.cpp @@ -100,6 +100,10 @@ TEST(FFmpegReader_Check_Video_File) CHECK_EQUAL(0, (int)pixels[pixel_index + 2]); CHECK_EQUAL(255, (int)pixels[pixel_index + 3]); + // Check pixel function + CHECK_EQUAL(true, f->CheckPixel(10, 112, 21, 191, 0, 255)); + CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0)); + // Get frame 1 f = r.GetFrame(2); @@ -113,6 +117,10 @@ TEST(FFmpegReader_Check_Video_File) CHECK_EQUAL(188, (int)pixels[pixel_index + 2]); CHECK_EQUAL(255, (int)pixels[pixel_index + 3]); + // Check pixel function + CHECK_EQUAL(true, f->CheckPixel(10, 112, 0, 96, 188, 255)); + CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0)); + // Close reader r.Close(); } From 2be5e5e16845cdcf2f80383b1329808558e98c87 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Tue, 4 Jun 2019 13:42:46 -0500 Subject: [PATCH 2/7] Fixing crash on certain hardware accelerator modes (specifically decoder 2, device 0) --- src/FFmpegReader.cpp | 4 +--- src/examples/Example.cpp | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index e8f135ce..6aa0938e 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -934,9 +934,7 @@ std::shared_ptr FFmpegReader::ReadStream(int64_t requested_frame) { // down processing considerably, but might be more stable on some systems. #pragma omp taskwait } - } else { - RemoveAVFrame(pFrame); - } + } } // Audio packet diff --git a/src/examples/Example.cpp b/src/examples/Example.cpp index 80339684..1e19f4d9 100644 --- a/src/examples/Example.cpp +++ b/src/examples/Example.cpp @@ -38,7 +38,7 @@ int main(int argc, char* argv[]) { Settings *s = Settings::Instance(); s->HARDWARE_DECODER = 2; // 1 VA-API, 2 NVDEC - s->HW_DE_DEVICE_SET = 1; + s->HW_DE_DEVICE_SET = 0; FFmpegReader r9("/home/jonathan/Videos/sintel_trailer-720p.mp4"); r9.Open(); From 438b2c333e1366e206957b18baef6e17d73f4a38 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sat, 8 Jun 2019 12:21:56 -0500 Subject: [PATCH 3/7] Update Frame.cpp --- src/Frame.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Frame.cpp b/src/Frame.cpp index 27bf5f71..cacd91d9 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -481,7 +481,7 @@ const unsigned char* Frame::GetPixels(int row) } // Check a specific pixel color value (returns True/False) -bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha) { +bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold) { int col_pos = col * 4; // Find column array position if (!image || row < 0 || row >= (height - 1) || col_pos < 0 || col_pos >= (width - 1) ) { @@ -490,10 +490,10 @@ bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha } // Check pixel color const unsigned char* pixels = GetPixels(row); - if (pixels[col_pos + 0] == red && - pixels[col_pos + 1] == green && - pixels[col_pos + 2] == blue && - pixels[col_pos + 3] == alpha) { + if (pixels[col_pos + 0] >= (red - threshold) && pixels[col_pos + 0] <= (red + threshold) && + pixels[col_pos + 0] >= (green - threshold) && pixels[col_pos + 0] <= (green + threshold) && + pixels[col_pos + 0] >= (blue - threshold) && pixels[col_pos + 0] <= (blue + threshold) && + pixels[col_pos + 0] >= (alpha - threshold) && pixels[col_pos + 0] <= (alpha + threshold)) { // Pixel color matches successfully return true; } else { From 2b308c6d5974a6cd643f2414b1f5b41285d831d2 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sat, 8 Jun 2019 12:23:26 -0500 Subject: [PATCH 4/7] Update Frame.h --- include/Frame.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Frame.h b/include/Frame.h index 72822188..6b682edb 100644 --- a/include/Frame.h +++ b/include/Frame.h @@ -250,7 +250,7 @@ namespace openshot const unsigned char* GetPixels(int row); /// Check a specific pixel color value (returns True/False) - bool CheckPixel(int row, int col, int red, int green, int blue, int alpha); + bool CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold); /// Get height of image int GetHeight(); From 238e2d16d8a5a45716297415892dac50f2824761 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sat, 8 Jun 2019 12:24:49 -0500 Subject: [PATCH 5/7] Update FFmpegReader_Tests.cpp --- tests/FFmpegReader_Tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FFmpegReader_Tests.cpp b/tests/FFmpegReader_Tests.cpp index 454420a4..72f5462d 100644 --- a/tests/FFmpegReader_Tests.cpp +++ b/tests/FFmpegReader_Tests.cpp @@ -101,8 +101,8 @@ TEST(FFmpegReader_Check_Video_File) CHECK_EQUAL(255, (int)pixels[pixel_index + 3]); // Check pixel function - CHECK_EQUAL(true, f->CheckPixel(10, 112, 21, 191, 0, 255)); - CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0)); + CHECK_EQUAL(true, f->CheckPixel(10, 112, 21, 191, 0, 255, 5)); + CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5)); // Get frame 1 f = r.GetFrame(2); From 3f926f45df8f7c2c30c0872346749beb47bf37f9 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sat, 8 Jun 2019 12:45:13 -0500 Subject: [PATCH 6/7] Update FFmpegReader_Tests.cpp --- tests/FFmpegReader_Tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FFmpegReader_Tests.cpp b/tests/FFmpegReader_Tests.cpp index 72f5462d..462a77c3 100644 --- a/tests/FFmpegReader_Tests.cpp +++ b/tests/FFmpegReader_Tests.cpp @@ -118,8 +118,8 @@ TEST(FFmpegReader_Check_Video_File) CHECK_EQUAL(255, (int)pixels[pixel_index + 3]); // Check pixel function - CHECK_EQUAL(true, f->CheckPixel(10, 112, 0, 96, 188, 255)); - CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0)); + CHECK_EQUAL(true, f->CheckPixel(10, 112, 0, 96, 188, 255, 5)); + CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5)); // Close reader r.Close(); From 722d672f5838fc6799aa5faec0cc9da821750691 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Sat, 8 Jun 2019 12:52:35 -0500 Subject: [PATCH 7/7] Update Frame.cpp --- src/Frame.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Frame.cpp b/src/Frame.cpp index cacd91d9..aa7c0d87 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -491,9 +491,9 @@ bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha // Check pixel color const unsigned char* pixels = GetPixels(row); if (pixels[col_pos + 0] >= (red - threshold) && pixels[col_pos + 0] <= (red + threshold) && - pixels[col_pos + 0] >= (green - threshold) && pixels[col_pos + 0] <= (green + threshold) && - pixels[col_pos + 0] >= (blue - threshold) && pixels[col_pos + 0] <= (blue + threshold) && - pixels[col_pos + 0] >= (alpha - threshold) && pixels[col_pos + 0] <= (alpha + threshold)) { + pixels[col_pos + 1] >= (green - threshold) && pixels[col_pos + 1] <= (green + threshold) && + pixels[col_pos + 2] >= (blue - threshold) && pixels[col_pos + 2] <= (blue + threshold) && + pixels[col_pos + 3] >= (alpha - threshold) && pixels[col_pos + 3] <= (alpha + threshold)) { // Pixel color matches successfully return true; } else {