From 91ea57a7d12725fd69b89b93849061d871478b35 Mon Sep 17 00:00:00 2001 From: alodijutgla Date: Tue, 22 Nov 2022 12:31:31 +0100 Subject: [PATCH 1/3] Add --json-format argument to print the results into the std output --- .gitignore | 3 ++- source/apps/vca/vca.cpp | 36 ++++++++++++++++++++++++------------ source/apps/vca/vcacli.h | 2 ++ source/lib/vcaLib.h | 2 +- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 1899660..1a9e165 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build -.vscode \ No newline at end of file +.vscode +cmake-build-*/ diff --git a/source/apps/vca/vca.cpp b/source/apps/vca/vca.cpp index fe2fcae..c62ee3d 100644 --- a/source/apps/vca/vca.cpp +++ b/source/apps/vca/vca.cpp @@ -20,6 +20,7 @@ #include "vcacli.h" +#include #include #include #include @@ -67,7 +68,7 @@ void printStatus(uint32_t frameNum, unsigned framesToBeAnalyzed, bool printSumma prevUpdateTime = now; auto elapsedAbsMs = std::chrono::duration_cast(now - startTime) - .count(); + .count(); double fps = elapsedAbsMs > 0 ? frameNum * 1000. / elapsedAbsMs : 0; if (printSummary) @@ -116,6 +117,8 @@ struct CLIOptions vca_param vcaParam; vca_shot_detection_param shotDetectParam; + + bool jsonFormat{}; }; struct Result @@ -180,7 +183,7 @@ std::optional parseCLIOptions(int argc, char **argv) if (c != 63) vca_log(LogLevel::Warning, "internal error: short option " + std::string(1, c) - + " has no long option"); + + " has no long option"); return {}; } } @@ -201,6 +204,8 @@ std::optional parseCLIOptions(int argc, char **argv) options.vcaParam.enableChroma = false; else if (name == "y4m") options.openAsY4m = true; + else if (name == "json-format") + options.jsonFormat = true; else { auto arg = std::string(optarg); @@ -288,7 +293,7 @@ bool checkOptions(CLIOptions options) { vca_log(LogLevel::Error, "Invalid block size (" + std::to_string(options.vcaParam.blockSize) - + ") provided. Valid values are 8, 16 and 32."); + + ") provided. Valid values are 8, 16 and 32."); return false; } @@ -309,6 +314,7 @@ void logOptions(const CLIOptions &options) vca_log(LogLevel::Info, " Complexity csv: "s + options.complexityCSVFilename); vca_log(LogLevel::Info, " Shot csv: "s + options.shotCSVFilename); vca_log(LogLevel::Info, " YUView stats file: "s + options.yuviewStatsFilename); + vca_log(LogLevel::Info, " Results as Json: "s + (options.jsonFormat ? "True"s : "False"s)); } void logResult(const Result &result, const vca_frame *frame, const unsigned resultsCounter) @@ -316,19 +322,19 @@ void logResult(const Result &result, const vca_frame *frame, const unsigned resu if (result.result.poc != frame->stats.poc) vca_log(LogLevel::Warning, "The poc of the returned data (" + std::to_string(result.result.poc) - + ") does not match the expected next frames POC (" - + std::to_string(frame->stats.poc) + ")."); + + ") does not match the expected next frames POC (" + + std::to_string(frame->stats.poc) + ")."); if (result.result.poc != resultsCounter) vca_log(LogLevel::Warning, "The poc of the returned data (" + std::to_string(result.result.poc) - + ") does not match the expected results counter (" - + std::to_string(resultsCounter) + ")."); + + ") does not match the expected results counter (" + + std::to_string(resultsCounter) + ")."); vca_log(LogLevel::Debug, "Got results POC " + std::to_string(result.result.poc) + "averageBrightness " - + std::to_string(result.result.averageBrightness) + " averageEnergy " - + std::to_string(result.result.averageEnergy) + " sad " - + std::to_string(result.result.sad)); + + std::to_string(result.result.averageBrightness) + " averageEnergy " + + std::to_string(result.result.averageEnergy) + " sad " + + std::to_string(result.result.sad)); } void writeComplexityStatsToFile(const Result &result, std::ofstream &file, bool enableChroma) @@ -607,6 +613,12 @@ int main(int argc, char **argv) logResult(result, processedFrame->getFrame(), resultsCounter); + if (options.jsonFormat) + { + nlohmann::json j = result.result; + std::cout << j << std::endl; + } + frameRecycling.push(std::move(processedFrame)); resultsCounter++; } @@ -642,7 +654,7 @@ int main(int argc, char **argv) vca_analyzer_close(analyzer); printStatus(resultsCounter, pushedFrames, true); - if (!options.shotCSVFilename.empty()) + if (options.shotCSVFilename.empty()) { if (options.shotDetectParam.fps == 0.0) options.shotDetectParam.fps = inputFile->getFPS(); @@ -667,7 +679,7 @@ int main(int argc, char **argv) [](auto frame) { return frame.isNewShot; }); vca_log(LogLevel::Info, "Performed shot detection for " + std::to_string(shotDetectFrames.size()) - + " frames. Detected " + std::to_string(nrShots) + " shots."); + + " frames. Detected " + std::to_string(nrShots) + " shots."); } return 0; diff --git a/source/apps/vca/vcacli.h b/source/apps/vca/vcacli.h index 15d1cd8..45ff2b1 100644 --- a/source/apps/vca/vcacli.h +++ b/source/apps/vca/vcacli.h @@ -30,6 +30,7 @@ static const struct option long_options[] = {{"help", no_argument, NULL, 'h'}, {"no-chroma", no_argument, NULL, 0}, {"input", required_argument, NULL, 0}, {"y4m", no_argument, NULL, 0}, + {"json-format", no_argument, NULL, 0}, {"input-depth", required_argument, NULL, 0}, {"input-res", required_argument, NULL, 0}, {"input-csp", required_argument, NULL, 0}, @@ -79,6 +80,7 @@ static void showHelp() printf(" --yuview-stats Write the per block results (energy, sad) to a stats " "file\n"); printf(" that can be visualized using YUView.\n"); + printf(" --json-format Print VCA results as Json. Default: Disabled\n"); printf("\nOperation Options:\n"); printf(" --no-simd Disable SIMD. Default: Enabled\n"); printf(" --no-chroma Disable chroma. Default: Enabled\n"); diff --git a/source/lib/vcaLib.h b/source/lib/vcaLib.h index f7d8d36..4de337a 100644 --- a/source/lib/vcaLib.h +++ b/source/lib/vcaLib.h @@ -101,7 +101,7 @@ struct vca_frame_results bool isNewShot{}; // An increasing counter that is incremented with each call to 'vca_analyzer_push'. - // So with this one can double check that the results are recieved in the right order. + // So with this one can double-check that the results are received in the right order. unsigned jobID{}; }; From f237542149676dfc9846e8ba1321adbae3b93935 Mon Sep 17 00:00:00 2001 From: alodijutgla Date: Tue, 22 Nov 2022 12:42:49 +0100 Subject: [PATCH 2/3] add ResultsToJson file --- source/apps/common/ResultToJson.h | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 source/apps/common/ResultToJson.h diff --git a/source/apps/common/ResultToJson.h b/source/apps/common/ResultToJson.h new file mode 100644 index 0000000..c66b918 --- /dev/null +++ b/source/apps/common/ResultToJson.h @@ -0,0 +1,34 @@ +#pragma once + +#include "lib/vcaLib.h" +#include +#include + +[[maybe_unused]] void to_json(nlohmann::json &j, const vca_frame_results &frameResults) +{ + j = nlohmann::json{ + {"averageBrightness", frameResults.averageBrightness}, + {"averageEnergy", frameResults.averageEnergy}, + {"sad", frameResults.sad}, + {"averageU", frameResults.averageU}, + {"averageV", frameResults.averageV}, + {"energyU", frameResults.energyU}, + {"energyV", frameResults.energyV}, + {"epsilon", frameResults.epsilon}, + {"poc", frameResults.poc}, + {"isNewShot", frameResults.isNewShot}}; +} + +[[maybe_unused]] void from_json(const nlohmann::json &j, vca_frame_results &frameResults) +{ + j.at("averageBrightness").get_to(frameResults.averageBrightness); + j.at("averageEnergy").get_to(frameResults.averageEnergy); + j.at("sad").get_to(frameResults.sad); + j.at("averageU").get_to(frameResults.averageU); + j.at("averageV").get_to(frameResults.averageV); + j.at("energyU").get_to(frameResults.energyU); + j.at("energyV").get_to(frameResults.energyV); + j.at("epsilon").get_to(frameResults.epsilon); + j.at("poc").get_to(frameResults.poc); + j.at("isNewShot").get_to(frameResults.isNewShot); +} \ No newline at end of file From 840678c0b144cd63177cb9140731f850bad3d39a Mon Sep 17 00:00:00 2001 From: ATrattnig Date: Tue, 22 Nov 2022 14:51:36 +0100 Subject: [PATCH 3/3] Also print json format for flushing frames --- source/apps/vca/vca.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/apps/vca/vca.cpp b/source/apps/vca/vca.cpp index c62ee3d..c0967be 100644 --- a/source/apps/vca/vca.cpp +++ b/source/apps/vca/vca.cpp @@ -648,6 +648,12 @@ int main(int argc, char **argv) logResult(result, processedFrame->getFrame(), resultsCounter); + if (options.jsonFormat) + { + nlohmann::json j = result.result; + std::cout << j << std::endl; + } + resultsCounter++; }