mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
截图api支持默认图片
This commit is contained in:
parent
e946b3b3d2
commit
cecfe7ba54
@ -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)
|
[english readme](https://github.com/xiongziliang/ZLMediaKit/blob/master/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.
|
# A lightweight ,high performance and stable stream server and client framework based on C++11.
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ apiDebug=1
|
|||||||
secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc
|
secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc
|
||||||
#截图保存路径根目录,截图通过http api(/index/api/getSnap)生成和获取
|
#截图保存路径根目录,截图通过http api(/index/api/getSnap)生成和获取
|
||||||
snapRoot=./www/snap/
|
snapRoot=./www/snap/
|
||||||
|
#默认截图图片,在启动FFmpeg截图后但是截图还未生成时,可以返回默认的预设图片
|
||||||
|
defaultSnap=./www/logo.png
|
||||||
|
|
||||||
[ffmpeg]
|
[ffmpeg]
|
||||||
#FFmpeg可执行程序绝对路径
|
#FFmpeg可执行程序绝对路径
|
||||||
|
@ -8,11 +8,12 @@
|
|||||||
* may be found in the AUTHORS file in the root of the source tree.
|
* may be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <math.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <math.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"
|
||||||
@ -51,12 +52,13 @@ typedef enum {
|
|||||||
const string kApiDebug = API_FIELD"apiDebug";
|
const string kApiDebug = API_FIELD"apiDebug";
|
||||||
const string kSecret = API_FIELD"secret";
|
const string kSecret = API_FIELD"secret";
|
||||||
const string kSnapRoot = API_FIELD"snapRoot";
|
const string kSnapRoot = API_FIELD"snapRoot";
|
||||||
|
const string kDefaultSnap = API_FIELD"defaultSnap";
|
||||||
|
|
||||||
static onceToken token([]() {
|
static onceToken token([]() {
|
||||||
mINI::Instance()[kApiDebug] = "1";
|
mINI::Instance()[kApiDebug] = "1";
|
||||||
mINI::Instance()[kSecret] = "035c73f7-bb6b-4889-a715-d9eb2d1925cc";
|
mINI::Instance()[kSecret] = "035c73f7-bb6b-4889-a715-d9eb2d1925cc";
|
||||||
mINI::Instance()[kSnapRoot] = "./www/snap/";
|
mINI::Instance()[kSnapRoot] = "./www/snap/";
|
||||||
|
mINI::Instance()[kDefaultSnap] = "./www/logo.png";
|
||||||
});
|
});
|
||||||
}//namespace API
|
}//namespace API
|
||||||
|
|
||||||
@ -850,24 +852,32 @@ void installWebApi() {
|
|||||||
|
|
||||||
if(!snap_path.empty()){
|
if(!snap_path.empty()){
|
||||||
StrCaseMap headerOut;
|
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);
|
invoker.responseFile(headerIn,headerOut,snap_path);
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//无截图或者截图已经过期
|
//无截图或者截图已经过期
|
||||||
snap_path = StrPrinter << scan_path << time(NULL) << ".jpeg";
|
snap_path = StrPrinter << scan_path << time(NULL) << ".jpeg";
|
||||||
|
|
||||||
{
|
//生成一个空文件,目的是顺便创建文件夹路径,
|
||||||
//生成一个空文件,目的是顺便创建文件夹路径,
|
//同时防止在FFmpeg生成截图途中不停的尝试调用该api启动FFmpeg生成相同的截图
|
||||||
//同时防止在FFmpeg生成截图途中不停的尝试调用该api启动FFmpeg生成相同的截图
|
auto file = File::create_file(snap_path.data(), "wb");
|
||||||
//当然,我们可以拷贝一个"正在截图中"的图来替换这个空图,这需要开发者自己实现
|
if (file) {
|
||||||
auto file = File::create_file(snap_path.data(), "wb");
|
fclose(file);
|
||||||
if(file){
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//启动FFmpeg进程,开始截图
|
||||||
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){
|
||||||
//生成截图失败,可能残留空文件
|
//生成截图失败,可能残留空文件
|
||||||
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
Loading…
Reference in New Issue
Block a user