From 4514810002f2d5ba98ed886f3dae28e2e8aaf448 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期一, 02 十二月 2019 16:53:59 +0800
Subject: [PATCH] up
---
csrc/buz/recorder.cpp | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp
index 2d00c57..beda224 100644
--- a/csrc/buz/recorder.cpp
+++ b/csrc/buz/recorder.cpp
@@ -5,6 +5,8 @@
#include <unistd.h>
#include <chrono>
+#include <sys/stat.h>
+
extern "C"{
#include <libavcodec/avcodec.h>
}
@@ -82,6 +84,12 @@
std::string filename(sole::uuid4().base62() + "-" + std::to_string(pid) + ".mp4");
file_path_ = dir_ + "/" + filename;
+ std::string backup_dir("./video");
+ size_t pos = dir_.rfind("/");
+ if (pos != std::string::npos){
+ backup_dir = dir_.substr(0, pos);
+ }
+
auto v = in_->getStream(AVMEDIA_TYPE_VIDEO);
if (!v){
return -2;
@@ -95,9 +103,11 @@
logIt("start record h264 file: %s", file_path_.c_str());
return 0;
}else{
- file_path_ = "./" + filename;
- ret = out_->JustWriter(v, a, file_path_.c_str());
+ mkdir(backup_dir.c_str(), 0777);
+ file_path_ = backup_dir + "/" + filename;
+
logIt("failed in dir %s, try file %s to start record file", dir_.c_str(), file_path_.c_str());
+ ret = out_->JustWriter(v, a, file_path_.c_str());
if (ret){
logIt("start record h264 file: %s", file_path_.c_str());
return 0;
@@ -118,9 +128,17 @@
std::string filename(sole::uuid4().base62() + "-" + std::to_string(pid) + ".hevc");
file_path_ = dir_ + "/" + filename;
+ std::string backup_dir("./video");
+ size_t pos = dir_.rfind("/");
+ if (pos != std::string::npos){
+ backup_dir = dir_.substr(0, pos);
+ }
+
fp_ = fopen(file_path_.c_str(), "wb");
if (!fp_){
- file_path_ = "./" + filename;
+ mkdir(backup_dir.c_str(), 0777);
+ file_path_ = backup_dir + "/" + filename;
+
logIt("failed in dir %s, try file %s to start record hevc file", dir_.c_str(), file_path_.c_str());
fp_ = fopen(file_path_.c_str(), "wb");
if (!fp_){
--
Gitblit v1.8.0