From 5a8b9be44af3a44e1e86390341cabe40fb116e69 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Tue, 17 May 2016 14:46:28 +0200 Subject: [PATCH] Added a -c / --compact flag to MistAnalyserDTSC --- lib/h264.cpp | 4 ++- lib/h264.h | 2 ++ src/analysers/dtsc_analyser.cpp | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/h264.cpp b/lib/h264.cpp index 591cf725..a256b61e 100644 --- a/lib/h264.cpp +++ b/lib/h264.cpp @@ -113,8 +113,10 @@ namespace h264 { } char profileIdc = bs.get(8); + result.profile = profileIdc; //Start skipping unused data - bs.skip(16); + bs.skip(8); + result.level = bs.get(8); bs.getUExpGolomb(); if (profileIdc == 100 || profileIdc == 110 || profileIdc == 122 || profileIdc == 244 || profileIdc == 44 || profileIdc == 83 || profileIdc == 86 || profileIdc == 118 || profileIdc == 128) { //chroma format idc diff --git a/lib/h264.h b/lib/h264.h index 23dec794..48fcfcc9 100644 --- a/lib/h264.h +++ b/lib/h264.h @@ -12,6 +12,8 @@ namespace h264 { unsigned int width; unsigned int height; double fps; + uint8_t profile; + uint8_t level; }; ///Class for analyzing generic nal units diff --git a/src/analysers/dtsc_analyser.cpp b/src/analysers/dtsc_analyser.cpp index fe886c83..3f97e44f 100644 --- a/src/analysers/dtsc_analyser.cpp +++ b/src/analysers/dtsc_analyser.cpp @@ -9,6 +9,7 @@ #include #include #include +#include ///\brief Holds everything unique to the analysers. namespace Analysers { @@ -23,6 +24,48 @@ namespace Analysers { std::cerr << "Not a valid DTSC file" << std::endl; return 1; } + + if (conf.getBool("compact")){ + JSON::Value result; + for (std::map::iterator it = F.getMeta().tracks.begin(); it != F.getMeta().tracks.end(); it++){ + JSON::Value track; + if (it->second.type=="video"){ + std::stringstream tStream; + track["resolution"] = JSON::Value((long long)it->second.width).asString() + "x" + JSON::Value((long long)it->second.height).asString(); + track["fps"] = (long long)((double)it->second.fpks / 1000); + track["fpks"] = it->second.fpks; + tStream << it->second.bps * 8 << " b/s, " << (double)it->second.bps * 8 / 1024 << " kb/s, " << (double)it->second.bps * 8 / 1024 / 1024 << " mb/s"; + track["bitrate"] = tStream.str(); + tStream.str(""); + track["keyframe_duration"] = (long long)((float)(it->second.lastms - it->second.firstms) / it->second.keys.size()); + tStream << ((double)(it->second.lastms - it->second.firstms) / it->second.keys.size()) / 1000; + track["keyframe_interval"] = tStream.str(); + + tStream.str(""); + if (it->second.codec == "H264"){ + h264::sequenceParameterSet sps; + sps.fromDTSCInit(it->second.init); + h264::SPSMeta spsData = sps.getCharacteristics(); + track["encoding"]["width"] = spsData.width; + track["encoding"]["height"] = spsData.height; + tStream << spsData.fps; + track["encoding"]["fps"] = tStream.str(); + track["encoding"]["profile"] = spsData.profile; + track["encoding"]["level"] = spsData.level; + } + } + if (it->second.type == "audio"){ + std::stringstream tStream; + tStream << it->second.bps * 8 << " b/s, " << (double)it->second.bps * 8 / 1024 << " kb/s, " << (double)it->second.bps * 8 / 1024 / 1024 << " mb/s"; + track["bitrate"] = tStream.str(); + track["keyframe_interval"] = (long long)((float)(it->second.lastms - it->second.firstms) / it->second.keys.size()); + } + result[it->second.getWritableIdentifier()] = track; + } + std::cout << result.toString(); + return 0; + } + if (F.getMeta().vod || F.getMeta().live){ F.getMeta().toPrettyString(std::cout,0, 0x03); } @@ -63,6 +106,7 @@ namespace Analysers { int main(int argc, char ** argv){ Util::Config conf = Util::Config(argv[0]); conf.addOption("filename", JSON::fromString("{\"arg_num\":1, \"arg\":\"string\", \"help\":\"Filename of the DTSC file to analyse.\"}")); + conf.addOption("compact", JSON::fromString("{\"short\": \"c\", \"long\": \"compact\", \"help\":\"Filename of the DTSC file to analyse.\"}")); conf.parseArgs(argc, argv); return Analysers::analyseDTSC(conf); } //main