Working conversion
This commit is contained in:
parent
9a9b5f8fe6
commit
a6299235d1
2 changed files with 54 additions and 40 deletions
|
@ -117,6 +117,16 @@ namespace Converter {
|
|||
statusHistory[name] = "Can not find encoder " + parameters["encoder"];
|
||||
return;
|
||||
}
|
||||
if (parameters.isMember("video")){
|
||||
if (parameters["video"].isMember("width") && !parameters["video"].isMember("height")){
|
||||
statusHistory[name] = "No height parameter given";
|
||||
return;
|
||||
}
|
||||
if (parameters["video"].isMember("height") && !parameters["video"].isMember("width")){
|
||||
statusHistory[name] = "No width parameter given";
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::stringstream encoderCommand;
|
||||
if (parameters["encoder"] == "ffmpeg"){
|
||||
encoderCommand << "ffmpeg -i ";
|
||||
|
@ -134,6 +144,9 @@ namespace Converter {
|
|||
if (parameters["video"].isMember("kfps")){
|
||||
encoderCommand << "-r " << parameters["video"]["kfps"].asInt() / 1000 << " ";
|
||||
}
|
||||
if (parameters["video"].isMember("width")){
|
||||
encoderCommand << "-s " << parameters["video"]["width"].asInt() << "x" << parameters["video"]["height"].asInt() << " ";
|
||||
}
|
||||
///\todo Keyframe interval (different in older and newer versions of ffmpeg?)
|
||||
}
|
||||
}else{
|
||||
|
@ -175,50 +188,6 @@ namespace Converter {
|
|||
hasChanged = false;
|
||||
for (cIt = allConversions.begin(); cIt != allConversions.end(); cIt++){
|
||||
if (Util::Procs::isActive(cIt->first)){
|
||||
continue;
|
||||
}
|
||||
if (statusHistory.find( cIt->first ) == statusHistory.end()){
|
||||
statusHistory[cIt->first] = "Conversion successful, running DTSCFix";
|
||||
Util::Procs::Start(cIt->first+"DTSCFix",Util::getMyPath() + "MistDTSCFix " + cIt->second["output"].asString());
|
||||
}
|
||||
allConversions.erase(cIt);
|
||||
hasChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(statusHistory.size()){
|
||||
std::map<std::string,std::string>::iterator sIt;
|
||||
for (sIt = statusHistory.begin(); sIt != statusHistory.end(); sIt++){
|
||||
if (statusHistory[sIt->first].find("DTSCFix") != std::string::npos){
|
||||
if (Util::Procs::isActive(sIt->first+"DTSCFIX")){
|
||||
continue;
|
||||
}
|
||||
statusHistory[sIt->first] = "Conversion successful";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSON::Value parseFFMpegStatus(std::string statusLine){
|
||||
JSON::Value result;
|
||||
int curOffset = statusLine.find("frame=") + 6;
|
||||
result["frame"] = atoi(statusLine.substr(curOffset, statusLine.find("fps=") - curOffset).c_str() );
|
||||
curOffset = statusLine.find("time=") + 5;
|
||||
int myTime = 0;
|
||||
myTime += atoi(statusLine.substr(curOffset, 2).c_str()) * 60 * 60 * 1000;
|
||||
myTime += atoi(statusLine.substr(curOffset+3, 2).c_str()) * 60 * 1000;
|
||||
myTime += atoi(statusLine.substr(curOffset+6, 2).c_str()) *1000;
|
||||
myTime += atoi(statusLine.substr(curOffset+9, 2).c_str()) * 10;
|
||||
result["time"] = myTime;
|
||||
return result;
|
||||
}
|
||||
|
||||
JSON::Value Converter::getStatus(){
|
||||
updateStatus();
|
||||
JSON::Value result;
|
||||
if (allConversions.size()){
|
||||
for (std::map<std::string,JSON::Value>::iterator cIt = allConversions.begin(); cIt != allConversions.end(); cIt++){
|
||||
int statusFD = dup(cIt->second["statusFD"].asInt());
|
||||
fsync( statusFD );
|
||||
FILE* statusFile = fdopen( statusFD, "r" );
|
||||
|
@ -240,17 +209,61 @@ namespace Converter {
|
|||
}
|
||||
}while ( !feof(statusFile) && line.find("frame") != 0);//"frame" is the fist word on an actual status line of ffmpeg
|
||||
if ( !feof(statusFile)){
|
||||
result[cIt->first] = parseFFMpegStatus( line );
|
||||
result[cIt->first]["duration"] = cIt->second["duration"];
|
||||
result[cIt->first]["progress"] = (result[cIt->first]["time"].asInt() * 100) / cIt->second["duration"].asInt();
|
||||
cIt->second["status"] = parseFFMpegStatus( line );
|
||||
cIt->second["status"]["duration"] = cIt->second["duration"];
|
||||
cIt->second["status"]["progress"] = (cIt->second["status"]["time"].asInt() * 100) / cIt->second["duration"].asInt();
|
||||
}else{
|
||||
line.erase(line.end()-1);
|
||||
line = line.substr( line.rfind("\n") + 1 );
|
||||
result[cIt->first] = line;
|
||||
statusHistory[cIt->first] = line;
|
||||
cIt->second["status"] = line;
|
||||
}
|
||||
free(fileBuf);
|
||||
fclose(statusFile);
|
||||
}else{
|
||||
if (statusHistory.find( cIt->first ) == statusHistory.end()){
|
||||
statusHistory[cIt->first] = "Conversion successful, running DTSCFix";
|
||||
Util::Procs::Start(cIt->first+"DTSCFix",Util::getMyPath() + "MistDTSCFix " + cIt->second["output"].asString());
|
||||
}
|
||||
allConversions.erase(cIt);
|
||||
hasChanged = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(statusHistory.size()){
|
||||
std::map<std::string,std::string>::iterator sIt;
|
||||
for (sIt = statusHistory.begin(); sIt != statusHistory.end(); sIt++){
|
||||
if (statusHistory[sIt->first].find("DTSCFix") != std::string::npos){
|
||||
if (Util::Procs::isActive(sIt->first+"DTSCFIX")){
|
||||
continue;
|
||||
}
|
||||
statusHistory[sIt->first] = "Conversion successful";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSON::Value Converter::parseFFMpegStatus(std::string statusLine){
|
||||
JSON::Value result;
|
||||
int curOffset = statusLine.find("frame=") + 6;
|
||||
result["frame"] = atoi(statusLine.substr(curOffset, statusLine.find("fps=") - curOffset).c_str() );
|
||||
curOffset = statusLine.find("time=") + 5;
|
||||
int myTime = 0;
|
||||
myTime += atoi(statusLine.substr(curOffset, 2).c_str()) * 60 * 60 * 1000;
|
||||
myTime += atoi(statusLine.substr(curOffset+3, 2).c_str()) * 60 * 1000;
|
||||
myTime += atoi(statusLine.substr(curOffset+6, 2).c_str()) *1000;
|
||||
myTime += atoi(statusLine.substr(curOffset+9, 2).c_str()) * 10;
|
||||
result["time"] = myTime;
|
||||
return result;
|
||||
}
|
||||
|
||||
JSON::Value Converter::getStatus(){
|
||||
updateStatus();
|
||||
JSON::Value result;
|
||||
if (allConversions.size()){
|
||||
for (std::map<std::string,JSON::Value>::iterator cIt = allConversions.begin(); cIt != allConversions.end(); cIt++){
|
||||
result[cIt->first] = cIt->second["status"];
|
||||
}
|
||||
}
|
||||
if (statusHistory.size()){
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Converter {
|
|||
void updateStatus();
|
||||
JSON::Value getStatus();
|
||||
void clearStatus();
|
||||
JSON::Value parseFFMpegStatus(std::string statusLine);
|
||||
private:
|
||||
void fillFFMpegEncoders();
|
||||
converterInfo allCodecs;
|
||||
|
|
Loading…
Add table
Reference in a new issue