From cecfe7ba54e81717b728dd9955579f2f64141df7 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 10 Jun 2020 10:33:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=AA=E5=9B=BEapi=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- README_en.md | 2 +- conf/config.ini | 2 ++ server/WebApi.cpp | 34 ++++++++++++++++++++++------------ logo.png => www/logo.png | Bin 5 files changed, 26 insertions(+), 14 deletions(-) rename logo.png => www/logo.png (100%) 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