First version MistInfo binary, for analyzing files using ffprobe.
This commit is contained in:
parent
c6aabfa4bf
commit
562386fef7
2 changed files with 102 additions and 1 deletions
|
@ -11,7 +11,7 @@ RELEASE ?= "Generic_`getconf LONG_BIT`"
|
|||
|
||||
AM_CPPFLAGS = $(global_CFLAGS) $(MIST_CFLAGS) -DRELEASE=\"$(RELEASE)\"
|
||||
LDADD = $(MIST_LIBS)
|
||||
bin_PROGRAMS=MistBuffer MistController MistConnRAW MistConnRTMP MistConnHTTP MistConnHTTPProgressive MistConnHTTPDynamic MistConnHTTPSmooth MistConnHTTPLive MistConnTS MistPlayer MistDTSC2FLV MistFLV2DTSC MistDTSCFix MistDTSCMerge MistDTSC2TS MistSRT2DTSC MistAnalyserRTMP MistAnalyserFLV MistAnalyserDTSC MistAnalyserAMF MistAnalyserMP4
|
||||
bin_PROGRAMS=MistBuffer MistController MistConnRAW MistConnRTMP MistConnHTTP MistConnHTTPProgressive MistConnHTTPDynamic MistConnHTTPSmooth MistConnHTTPLive MistConnTS MistPlayer MistDTSC2FLV MistFLV2DTSC MistDTSCFix MistDTSCMerge MistDTSC2TS MistSRT2DTSC MistAnalyserRTMP MistAnalyserFLV MistAnalyserDTSC MistAnalyserAMF MistAnalyserMP4 MistInfo
|
||||
|
||||
#buffer folder (MistBuffer, MistPlayer)
|
||||
MistBuffer_SOURCES=buffer/buffer.cpp buffer/buffer_user.h buffer/buffer_user.cpp buffer/buffer_stream.h buffer/buffer_stream.cpp tinythread.cpp tinythread.h ../VERSION
|
||||
|
@ -46,6 +46,7 @@ MistAnalyserFLV_SOURCES=analysers/flv_analyser.cpp
|
|||
MistAnalyserDTSC_SOURCES=analysers/dtsc_analyser.cpp
|
||||
MistAnalyserAMF_SOURCES=analysers/amf_analyser.cpp
|
||||
MistAnalyserMP4_SOURCES=analysers/mp4_analyser.cpp
|
||||
MistInfo_SOURCES=info.cpp
|
||||
|
||||
|
||||
connectors/embed.js.h: connectors/embed.js
|
||||
|
|
100
src/info.cpp
Normal file
100
src/info.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include <mist/json.h>
|
||||
#include <mist/procs.h>
|
||||
|
||||
namespace Info {
|
||||
int getInfo(int argc, char* argv[]) {
|
||||
if (argc < 2){
|
||||
fprintf( stderr, "Usage: %s <filename>\n", argv[0] );
|
||||
return 1;
|
||||
}
|
||||
JSON::Value fileSpecs;
|
||||
std::vector<std::string> cmd;
|
||||
cmd.push_back("ffprobe");
|
||||
cmd.push_back(argv[1]);
|
||||
int outFD = -1;
|
||||
Util::Procs::StartPiped("FFProbe", cmd, 0, 0, &outFD);
|
||||
FILE * outFile = fdopen( outFD, "r" );
|
||||
char * fileBuf = 0;
|
||||
size_t fileBufLen = 0;
|
||||
while ( !(feof(outFile) || ferror(outFile)) && (getline(&fileBuf, &fileBufLen, outFile) != -1)){
|
||||
std::string line = fileBuf;
|
||||
if (line.find("Input") != std::string::npos){
|
||||
std::string tmp = line.substr(line.find("'") + 1);
|
||||
fileSpecs["fileName"] = tmp.substr(0, tmp.find("'"));
|
||||
}
|
||||
if (line.find("Duration") != std::string::npos ){
|
||||
std::string tmp = line.substr(line.find(": ", line.find("Duration")) + 2);
|
||||
tmp = tmp.substr(0, tmp.find(","));
|
||||
fileSpecs["duration"] = tmp;
|
||||
int length = (((atoi(tmp.substr(0,2).c_str()) * 60) + atoi(tmp.substr(3,2).c_str())) * 60) + atoi(tmp.substr(6,2).c_str());
|
||||
fileSpecs["length"] = length;
|
||||
length *= 100;
|
||||
length += atoi(tmp.substr(9,2).c_str());
|
||||
fileSpecs["lastms"] = length * 10;
|
||||
}
|
||||
if (line.find("bitrate") != std::string::npos ){
|
||||
std::string tmp = line.substr(line.find(": ", line.find("bitrate")) + 2);
|
||||
fileSpecs["bps"] = atoi(tmp.substr(0, tmp.find(" ")).c_str()) * 128;
|
||||
}
|
||||
if (line.find("Stream") != std::string::npos ){
|
||||
std::string tmp = line.substr(line.find(" ", line.find("Stream")) + 1);
|
||||
int strmIdx = fileSpecs["streams"].size();
|
||||
int curPos = 0;
|
||||
fileSpecs["streams"][strmIdx]["name"] = tmp.substr(curPos, tmp.find(": ", curPos) - curPos);
|
||||
curPos = tmp.find(": ", curPos) + 2;
|
||||
|
||||
//curPos = tmp.find("(", curPos) + 1;
|
||||
//fileSpecs["streams"][strmIdx]["language"] = tmp.substr(curPos, tmp.find(")", curPos) - curPos);
|
||||
//curPos = tmp.find(")", curPos) + 3;
|
||||
|
||||
fileSpecs["streams"][strmIdx]["type"] = tmp.substr(curPos, tmp.find(":", curPos) - curPos);
|
||||
curPos = tmp.find(":", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["codec"] = tmp.substr(curPos, tmp.find(" ", curPos) - curPos);
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
if (fileSpecs["streams"][strmIdx]["type"] == "Video"){
|
||||
fileSpecs["streams"][strmIdx]["encoding"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos);
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["width"] = atoi(tmp.substr(curPos, tmp.find("x", curPos) - curPos).c_str());
|
||||
curPos = tmp.find("x", curPos) + 1;
|
||||
fileSpecs["streams"][strmIdx]["height"] = atoi(tmp.substr(curPos, tmp.find(",", curPos) - curPos).c_str());
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["bps"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 128;
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["fpks"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 1000);
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["tbr"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) + 0.5);
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["tbn"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["tbc"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
||||
}else if (fileSpecs["streams"][strmIdx]["type"] == "Audio"){
|
||||
fileSpecs["streams"][strmIdx]["samplerate"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
if (tmp.substr(curPos, tmp.find(",", curPos) - curPos) == "stereo"){
|
||||
fileSpecs["streams"][strmIdx]["channels"] = 2;
|
||||
}else if (tmp.substr(curPos, tmp.find(",", curPos) - curPos) == "mono"){
|
||||
fileSpecs["streams"][strmIdx]["channels"] = 1;
|
||||
}else{
|
||||
fileSpecs["streams"][strmIdx]["channels"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos);
|
||||
}
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["samplewidth"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos);
|
||||
curPos = tmp.find(",", curPos) + 2;
|
||||
fileSpecs["streams"][strmIdx]["bps"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 128;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose( outFile );
|
||||
printf( "%s\n", fileSpecs.toPrettyString().c_str() );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
return Info::getInfo(argc, argv);
|
||||
}
|
Loading…
Add table
Reference in a new issue