diff --git a/README.md b/README.md index 414be43c..0b022a90 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![logo](https://raw.githubusercontent.com/zlmediakit/ZLMediaKit/master/logo.png) +![logo](https://raw.githubusercontent.com/zlmediakit/ZLMediaKit/master/www/logo.png) [english readme](https://github.com/xiongziliang/ZLMediaKit/blob/master/README_en.md) diff --git a/README_en.md b/README_en.md index 6e261981..485bd5ce 100644 --- a/README_en.md +++ b/README_en.md @@ -1,4 +1,4 @@ -![logo](https://raw.githubusercontent.com/zlmediakit/ZLMediaKit/master/logo.png) +![logo](https://raw.githubusercontent.com/zlmediakit/ZLMediaKit/master/www/logo.png) # A lightweight ,high performance and stable stream server and client framework based on C++11. diff --git a/conf/config.ini b/conf/config.ini index 981b458e..8f5fe93f 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -6,6 +6,8 @@ apiDebug=1 secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc #截图保存路径根目录,截图通过http api(/index/api/getSnap)生成和获取 snapRoot=./www/snap/ +#默认截图图片,在启动FFmpeg截图后但是截图还未生成时,可以返回默认的预设图片 +defaultSnap=./www/logo.png [ffmpeg] #FFmpeg可执行程序绝对路径 diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 2ee5d1f6..d596604b 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -8,11 +8,12 @@ * may be found in the AUTHORS file in the root of the source tree. */ +#include +#include #include #include #include #include -#include #include "jsoncpp/json.h" #include "Util/util.h" #include "Util/logger.h" @@ -51,12 +52,13 @@ typedef enum { const string kApiDebug = API_FIELD"apiDebug"; const string kSecret = API_FIELD"secret"; const string kSnapRoot = API_FIELD"snapRoot"; +const string kDefaultSnap = API_FIELD"defaultSnap"; static onceToken token([]() { mINI::Instance()[kApiDebug] = "1"; mINI::Instance()[kSecret] = "035c73f7-bb6b-4889-a715-d9eb2d1925cc"; mINI::Instance()[kSnapRoot] = "./www/snap/"; - + mINI::Instance()[kDefaultSnap] = "./www/logo.png"; }); }//namespace API @@ -850,24 +852,32 @@ void installWebApi() { if(!snap_path.empty()){ StrCaseMap headerOut; - headerOut["Content-Type"] = HttpFileManager::getContentType(".jpeg"); + struct stat statbuf = {0}; + GET_CONFIG(string, defaultSnap, API::kDefaultSnap); + if (!defaultSnap.empty() && !(stat(snap_path.data(), &statbuf) == 0 && statbuf.st_size != 0)) { + //空文件,则返回预设图片(也就是FFmpeg生成截图中空档期的默认图片) + snap_path = File::absolutePath(defaultSnap, ""); + headerOut["Content-Type"] = HttpFileManager::getContentType(snap_path.data()); + } else { + //之前生成的截图文件,我们默认为jpeg格式 + headerOut["Content-Type"] = HttpFileManager::getContentType(".jpeg"); + } + //返回图片给http客户端 invoker.responseFile(headerIn,headerOut,snap_path); - return ; + return; } //无截图或者截图已经过期 snap_path = StrPrinter << scan_path << time(NULL) << ".jpeg"; - { - //生成一个空文件,目的是顺便创建文件夹路径, - //同时防止在FFmpeg生成截图途中不停的尝试调用该api启动FFmpeg生成相同的截图 - //当然,我们可以拷贝一个"正在截图中"的图来替换这个空图,这需要开发者自己实现 - auto file = File::create_file(snap_path.data(), "wb"); - if(file){ - fclose(file); - } + //生成一个空文件,目的是顺便创建文件夹路径, + //同时防止在FFmpeg生成截图途中不停的尝试调用该api启动FFmpeg生成相同的截图 + auto file = File::create_file(snap_path.data(), "wb"); + if (file) { + fclose(file); } + //启动FFmpeg进程,开始截图 FFmpegSnap::makeSnap(allArgs["url"],snap_path,allArgs["timeout_sec"],[invoker,headerIn,snap_path](bool success){ if(!success){ //生成截图失败,可能残留空文件 diff --git a/logo.png b/www/logo.png similarity index 100% rename from logo.png rename to www/logo.png