检查、等待ffmpeg截图完成在返回请求结果
This commit is contained in:
parent
fff0345462
commit
11820db3e4
|
|
@ -13,6 +13,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include "jsoncpp/json.h"
|
#include "jsoncpp/json.h"
|
||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
|
|
@ -868,17 +869,35 @@ void installWebApi() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FFmpegSnap::makeSnap(allArgs["url"],snap_path,allArgs["timeout_sec"],[invoker,headerIn,snap_path](bool success){
|
FFmpegSnap::makeSnap(allArgs["url"], snap_path, allArgs["timeout_sec"], [invoker, headerIn, snap_path](bool success) {
|
||||||
if(!success){
|
if (!success) {
|
||||||
//生成截图失败,可能残留空文件
|
//生成截图失败,可能残留空文件
|
||||||
File::delete_file(snap_path.data());
|
File::delete_file(snap_path.data());
|
||||||
}
|
}
|
||||||
|
struct stat buf;
|
||||||
StrCaseMap headerOut;
|
clock_t delayStart = clock();
|
||||||
headerOut["Content-Type"] = HttpFileManager::getContentType(".jpeg");
|
clock_t timeoutStart = clock();
|
||||||
invoker.responseFile(headerIn, headerOut, snap_path);
|
long snapFileSize = 0;
|
||||||
});
|
while (clock() < timeoutStart + 4 * CLOCKS_PER_SEC) {
|
||||||
});
|
if (clock() < delayStart + 0.5 * CLOCKS_PER_SEC) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
delayStart = clock();
|
||||||
|
stat(snap_path.data(), &buf);
|
||||||
|
if (buf.st_size >0) {
|
||||||
|
if (buf.st_size == snapFileSize) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
snapFileSize = buf.st_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StrCaseMap headerOut;
|
||||||
|
headerOut["Content-Type"] = HttpFileManager::getContentType(".jpeg");
|
||||||
|
invoker.responseFile(headerIn, headerOut, snap_path);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
////////////以下是注册的Hook API////////////
|
////////////以下是注册的Hook API////////////
|
||||||
api_regist1("/index/hook/on_publish",[](API_ARGS1){
|
api_regist1("/index/hook/on_publish",[](API_ARGS1){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue