检查、等待ffmpeg截图完成在返回请求结果
This commit is contained in:
parent
fff0345462
commit
11820db3e4
|
|
@ -13,6 +13,7 @@
|
|||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <math.h>
|
||||
#include <sys/stat.h>
|
||||
#include "jsoncpp/json.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/logger.h"
|
||||
|
|
@ -868,12 +869,30 @@ void installWebApi() {
|
|||
}
|
||||
}
|
||||
|
||||
FFmpegSnap::makeSnap(allArgs["url"],snap_path,allArgs["timeout_sec"],[invoker,headerIn,snap_path](bool success){
|
||||
if(!success){
|
||||
FFmpegSnap::makeSnap(allArgs["url"], snap_path, allArgs["timeout_sec"], [invoker, headerIn, snap_path](bool success) {
|
||||
if (!success) {
|
||||
//生成截图失败,可能残留空文件
|
||||
File::delete_file(snap_path.data());
|
||||
}
|
||||
|
||||
struct stat buf;
|
||||
clock_t delayStart = clock();
|
||||
clock_t timeoutStart = clock();
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue