From 11820db3e4bc2bc19d2083fb054b155b53b1692b Mon Sep 17 00:00:00 2001 From: Lawrence <1934378145@qq.com> Date: Sun, 7 Jun 2020 12:43:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E3=80=81=E7=AD=89=E5=BE=85ff?= =?UTF-8?q?mpeg=E6=88=AA=E5=9B=BE=E5=AE=8C=E6=88=90=E5=9C=A8=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E8=AF=B7=E6=B1=82=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 2ee5d1f6..e11c3999 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "jsoncpp/json.h" #include "Util/util.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){ - if(!success){ - //生成截图失败,可能残留空文件 - File::delete_file(snap_path.data()); - } - - StrCaseMap headerOut; - headerOut["Content-Type"] = HttpFileManager::getContentType(".jpeg"); - invoker.responseFile(headerIn, headerOut, snap_path); - }); - }); + 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); + }); + }); ////////////以下是注册的Hook API//////////// api_regist1("/index/hook/on_publish",[](API_ARGS1){