indent fix
This commit is contained in:
parent
562386fef7
commit
2ab4204e71
1 changed files with 84 additions and 72 deletions
156
src/info.cpp
156
src/info.cpp
|
@ -4,6 +4,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <mist/json.h>
|
#include <mist/json.h>
|
||||||
|
#include <mist/dtsc.h>
|
||||||
#include <mist/procs.h>
|
#include <mist/procs.h>
|
||||||
|
|
||||||
namespace Info {
|
namespace Info {
|
||||||
|
@ -12,85 +13,96 @@ namespace Info {
|
||||||
fprintf( stderr, "Usage: %s <filename>\n", argv[0] );
|
fprintf( stderr, "Usage: %s <filename>\n", argv[0] );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
JSON::Value fileSpecs;
|
DTSC::File F(argv[1]);
|
||||||
std::vector<std::string> cmd;
|
JSON::Value fileSpecs = F.getMeta();
|
||||||
cmd.push_back("ffprobe");
|
if( !fileSpecs ) {
|
||||||
cmd.push_back(argv[1]);
|
std::vector<std::string> cmd;
|
||||||
int outFD = -1;
|
cmd.push_back("ffprobe");
|
||||||
Util::Procs::StartPiped("FFProbe", cmd, 0, 0, &outFD);
|
cmd.push_back(argv[1]);
|
||||||
FILE * outFile = fdopen( outFD, "r" );
|
int outFD = -1;
|
||||||
char * fileBuf = 0;
|
Util::Procs::StartPiped("FFProbe", cmd, 0, 0, &outFD);
|
||||||
size_t fileBufLen = 0;
|
FILE * outFile = fdopen( outFD, "r" );
|
||||||
while ( !(feof(outFile) || ferror(outFile)) && (getline(&fileBuf, &fileBufLen, outFile) != -1)){
|
char * fileBuf = 0;
|
||||||
std::string line = fileBuf;
|
size_t fileBufLen = 0;
|
||||||
if (line.find("Input") != std::string::npos){
|
while ( !(feof(outFile) || ferror(outFile)) && (getline(&fileBuf, &fileBufLen, outFile) != -1)){
|
||||||
std::string tmp = line.substr(line.find("'") + 1);
|
std::string line = fileBuf;
|
||||||
fileSpecs["fileName"] = tmp.substr(0, tmp.find("'"));
|
if (line.find("Input") != std::string::npos){
|
||||||
}
|
std::string tmp = line.substr(line.find("'") + 1);
|
||||||
if (line.find("Duration") != std::string::npos ){
|
fileSpecs["fileName"] = tmp.substr(0, tmp.find("'"));
|
||||||
std::string tmp = line.substr(line.find(": ", line.find("Duration")) + 2);
|
}
|
||||||
tmp = tmp.substr(0, tmp.find(","));
|
if (line.find("Duration") != std::string::npos ){
|
||||||
fileSpecs["duration"] = tmp;
|
std::string tmp = line.substr(line.find(": ", line.find("Duration")) + 2);
|
||||||
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());
|
tmp = tmp.substr(0, tmp.find(","));
|
||||||
fileSpecs["length"] = length;
|
fileSpecs["duration"] = tmp;
|
||||||
length *= 100;
|
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());
|
||||||
length += atoi(tmp.substr(9,2).c_str());
|
fileSpecs["length"] = length;
|
||||||
fileSpecs["lastms"] = length * 10;
|
length *= 100;
|
||||||
}
|
length += atoi(tmp.substr(9,2).c_str());
|
||||||
if (line.find("bitrate") != std::string::npos ){
|
fileSpecs["lastms"] = length * 10;
|
||||||
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("bitrate") != std::string::npos ){
|
||||||
}
|
std::string tmp = line.substr(line.find(": ", line.find("bitrate")) + 2);
|
||||||
if (line.find("Stream") != std::string::npos ){
|
fileSpecs["bps"] = atoi(tmp.substr(0, tmp.find(" ")).c_str()) * 128;
|
||||||
std::string tmp = line.substr(line.find(" ", line.find("Stream")) + 1);
|
}
|
||||||
int strmIdx = fileSpecs["streams"].size();
|
if (line.find("Stream") != std::string::npos ){
|
||||||
int curPos = 0;
|
std::string tmp = line.substr(line.find(" ", line.find("Stream")) + 1);
|
||||||
fileSpecs["streams"][strmIdx]["name"] = tmp.substr(curPos, tmp.find(": ", curPos) - curPos);
|
int strmIdx = fileSpecs["streams"].size();
|
||||||
curPos = tmp.find(": ", curPos) + 2;
|
int curPos = 0;
|
||||||
|
fileSpecs["streams"][strmIdx]["name"] = tmp.substr(curPos, tmp.find(": ", curPos) - curPos);
|
||||||
|
curPos = tmp.find(": ", curPos) + 2;
|
||||||
|
|
||||||
//curPos = tmp.find("(", curPos) + 1;
|
//curPos = tmp.find("(", curPos) + 1;
|
||||||
//fileSpecs["streams"][strmIdx]["language"] = tmp.substr(curPos, tmp.find(")", curPos) - curPos);
|
//fileSpecs["streams"][strmIdx]["language"] = tmp.substr(curPos, tmp.find(")", curPos) - curPos);
|
||||||
//curPos = tmp.find(")", curPos) + 3;
|
//curPos = tmp.find(")", curPos) + 3;
|
||||||
|
|
||||||
fileSpecs["streams"][strmIdx]["type"] = tmp.substr(curPos, tmp.find(":", curPos) - curPos);
|
fileSpecs["streams"][strmIdx]["type"] = tmp.substr(curPos, tmp.find(":", curPos) - curPos);
|
||||||
curPos = tmp.find(":", curPos) + 2;
|
curPos = tmp.find(":", curPos) + 2;
|
||||||
fileSpecs["streams"][strmIdx]["codec"] = tmp.substr(curPos, tmp.find(" ", curPos) - curPos);
|
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;
|
curPos = tmp.find(",", curPos) + 2;
|
||||||
fileSpecs["streams"][strmIdx]["width"] = atoi(tmp.substr(curPos, tmp.find("x", curPos) - curPos).c_str());
|
if (fileSpecs["streams"][strmIdx]["type"] == "Video"){
|
||||||
curPos = tmp.find("x", curPos) + 1;
|
fileSpecs["streams"][strmIdx]["encoding"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos);
|
||||||
fileSpecs["streams"][strmIdx]["height"] = atoi(tmp.substr(curPos, tmp.find(",", curPos) - curPos).c_str());
|
curPos = tmp.find(",", curPos) + 2;
|
||||||
curPos = tmp.find(",", curPos) + 2;
|
fileSpecs["streams"][strmIdx]["width"] = atoi(tmp.substr(curPos, tmp.find("x", curPos) - curPos).c_str());
|
||||||
fileSpecs["streams"][strmIdx]["bps"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 128;
|
curPos = tmp.find("x", curPos) + 1;
|
||||||
curPos = tmp.find(",", curPos) + 2;
|
fileSpecs["streams"][strmIdx]["height"] = atoi(tmp.substr(curPos, tmp.find(",", curPos) - curPos).c_str());
|
||||||
fileSpecs["streams"][strmIdx]["fpks"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 1000);
|
curPos = tmp.find(",", curPos) + 2;
|
||||||
curPos = tmp.find(",", curPos) + 2;
|
fileSpecs["streams"][strmIdx]["bps"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 128;
|
||||||
fileSpecs["streams"][strmIdx]["tbr"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) + 0.5);
|
curPos = tmp.find(",", curPos) + 2;
|
||||||
curPos = tmp.find(",", curPos) + 2;
|
fileSpecs["streams"][strmIdx]["fpks"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 1000);
|
||||||
fileSpecs["streams"][strmIdx]["tbn"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
curPos = tmp.find(",", curPos) + 2;
|
||||||
curPos = tmp.find(",", curPos) + 2;
|
fileSpecs["streams"][strmIdx]["tbr"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) + 0.5);
|
||||||
fileSpecs["streams"][strmIdx]["tbc"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
curPos = tmp.find(",", curPos) + 2;
|
||||||
}else if (fileSpecs["streams"][strmIdx]["type"] == "Audio"){
|
fileSpecs["streams"][strmIdx]["tbn"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
||||||
fileSpecs["streams"][strmIdx]["samplerate"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
curPos = tmp.find(",", curPos) + 2;
|
||||||
curPos = tmp.find(",", curPos) + 2;
|
fileSpecs["streams"][strmIdx]["tbc"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
||||||
if (tmp.substr(curPos, tmp.find(",", curPos) - curPos) == "stereo"){
|
}else if (fileSpecs["streams"][strmIdx]["type"] == "Audio"){
|
||||||
fileSpecs["streams"][strmIdx]["channels"] = 2;
|
fileSpecs["streams"][strmIdx]["samplerate"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str());
|
||||||
}else if (tmp.substr(curPos, tmp.find(",", curPos) - curPos) == "mono"){
|
curPos = tmp.find(",", curPos) + 2;
|
||||||
fileSpecs["streams"][strmIdx]["channels"] = 1;
|
if (tmp.substr(curPos, tmp.find(",", curPos) - curPos) == "stereo"){
|
||||||
}else{
|
fileSpecs["streams"][strmIdx]["channels"] = 2;
|
||||||
fileSpecs["streams"][strmIdx]["channels"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos);
|
}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;
|
||||||
}
|
}
|
||||||
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 );
|
||||||
}
|
}
|
||||||
fclose( outFile );
|
if (fileSpecs.isMember("video")){
|
||||||
printf( "%s\n", fileSpecs.toPrettyString().c_str() );
|
fileSpecs["video"].removeMember("init");
|
||||||
|
}
|
||||||
|
if (fileSpecs.isMember("audio")){
|
||||||
|
fileSpecs["audio"].removeMember("init");
|
||||||
|
}
|
||||||
|
fileSpecs.removeMember("keybpos");
|
||||||
|
fileSpecs.removeMember("keytime");
|
||||||
|
printf( "%s", fileSpecs.toString().c_str() );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue