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"];
|
statusHistory[name] = "Can not find encoder " + parameters["encoder"];
|
||||||
return;
|
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;
|
std::stringstream encoderCommand;
|
||||||
if (parameters["encoder"] == "ffmpeg"){
|
if (parameters["encoder"] == "ffmpeg"){
|
||||||
encoderCommand << "ffmpeg -i ";
|
encoderCommand << "ffmpeg -i ";
|
||||||
|
@ -134,6 +144,9 @@ namespace Converter {
|
||||||
if (parameters["video"].isMember("kfps")){
|
if (parameters["video"].isMember("kfps")){
|
||||||
encoderCommand << "-r " << parameters["video"]["kfps"].asInt() / 1000 << " ";
|
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?)
|
///\todo Keyframe interval (different in older and newer versions of ffmpeg?)
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
@ -175,14 +188,45 @@ namespace Converter {
|
||||||
hasChanged = false;
|
hasChanged = false;
|
||||||
for (cIt = allConversions.begin(); cIt != allConversions.end(); cIt++){
|
for (cIt = allConversions.begin(); cIt != allConversions.end(); cIt++){
|
||||||
if (Util::Procs::isActive(cIt->first)){
|
if (Util::Procs::isActive(cIt->first)){
|
||||||
continue;
|
int statusFD = dup(cIt->second["statusFD"].asInt());
|
||||||
|
fsync( statusFD );
|
||||||
|
FILE* statusFile = fdopen( statusFD, "r" );
|
||||||
|
char * fileBuf = 0;
|
||||||
|
size_t fileBufLen = 0;
|
||||||
|
fseek(statusFile,0,SEEK_END);
|
||||||
|
std::string line;
|
||||||
|
int totalTime = 0;
|
||||||
|
do{
|
||||||
|
getdelim(&fileBuf, &fileBufLen, '\r', statusFile);
|
||||||
|
line = fileBuf;
|
||||||
|
if (line.find("Duration") != std::string::npos){
|
||||||
|
int curOffset = line.find("Duration: ") + 10;
|
||||||
|
totalTime += atoi(line.substr(curOffset, 2).c_str()) * 60 * 60 * 1000;
|
||||||
|
totalTime += atoi(line.substr(curOffset+3, 2).c_str()) * 60 * 1000;
|
||||||
|
totalTime += atoi(line.substr(curOffset+6, 2).c_str()) *1000;
|
||||||
|
totalTime += atoi(line.substr(curOffset+9, 2).c_str()) * 10;
|
||||||
|
cIt->second["duration"] = totalTime;
|
||||||
|
}
|
||||||
|
}while ( !feof(statusFile) && line.find("frame") != 0);//"frame" is the fist word on an actual status line of ffmpeg
|
||||||
|
if ( !feof(statusFile)){
|
||||||
|
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 );
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +244,7 @@ namespace Converter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON::Value parseFFMpegStatus(std::string statusLine){
|
JSON::Value Converter::parseFFMpegStatus(std::string statusLine){
|
||||||
JSON::Value result;
|
JSON::Value result;
|
||||||
int curOffset = statusLine.find("frame=") + 6;
|
int curOffset = statusLine.find("frame=") + 6;
|
||||||
result["frame"] = atoi(statusLine.substr(curOffset, statusLine.find("fps=") - curOffset).c_str() );
|
result["frame"] = atoi(statusLine.substr(curOffset, statusLine.find("fps=") - curOffset).c_str() );
|
||||||
|
@ -219,38 +263,7 @@ namespace Converter {
|
||||||
JSON::Value result;
|
JSON::Value result;
|
||||||
if (allConversions.size()){
|
if (allConversions.size()){
|
||||||
for (std::map<std::string,JSON::Value>::iterator cIt = allConversions.begin(); cIt != allConversions.end(); cIt++){
|
for (std::map<std::string,JSON::Value>::iterator cIt = allConversions.begin(); cIt != allConversions.end(); cIt++){
|
||||||
int statusFD = dup(cIt->second["statusFD"].asInt());
|
result[cIt->first] = cIt->second["status"];
|
||||||
fsync( statusFD );
|
|
||||||
FILE* statusFile = fdopen( statusFD, "r" );
|
|
||||||
char * fileBuf = 0;
|
|
||||||
size_t fileBufLen = 0;
|
|
||||||
fseek(statusFile,0,SEEK_END);
|
|
||||||
std::string line;
|
|
||||||
int totalTime = 0;
|
|
||||||
do{
|
|
||||||
getdelim(&fileBuf, &fileBufLen, '\r', statusFile);
|
|
||||||
line = fileBuf;
|
|
||||||
if (line.find("Duration") != std::string::npos){
|
|
||||||
int curOffset = line.find("Duration: ") + 10;
|
|
||||||
totalTime += atoi(line.substr(curOffset, 2).c_str()) * 60 * 60 * 1000;
|
|
||||||
totalTime += atoi(line.substr(curOffset+3, 2).c_str()) * 60 * 1000;
|
|
||||||
totalTime += atoi(line.substr(curOffset+6, 2).c_str()) *1000;
|
|
||||||
totalTime += atoi(line.substr(curOffset+9, 2).c_str()) * 10;
|
|
||||||
cIt->second["duration"] = totalTime;
|
|
||||||
}
|
|
||||||
}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();
|
|
||||||
}else{
|
|
||||||
line.erase(line.end()-1);
|
|
||||||
line = line.substr( line.rfind("\n") + 1 );
|
|
||||||
result[cIt->first] = line;
|
|
||||||
statusHistory[cIt->first] = line;
|
|
||||||
}
|
|
||||||
free(fileBuf);
|
|
||||||
fclose(statusFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (statusHistory.size()){
|
if (statusHistory.size()){
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace Converter {
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
JSON::Value getStatus();
|
JSON::Value getStatus();
|
||||||
void clearStatus();
|
void clearStatus();
|
||||||
|
JSON::Value parseFFMpegStatus(std::string statusLine);
|
||||||
private:
|
private:
|
||||||
void fillFFMpegEncoders();
|
void fillFFMpegEncoders();
|
||||||
converterInfo allCodecs;
|
converterInfo allCodecs;
|
||||||
|
|
Loading…
Add table
Reference in a new issue