From 18a05d269516a5e33d8460291c2f93e73d95adce Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期二, 26 十二月 2023 10:45:31 +0800
Subject: [PATCH] GetYUV format is NV12

---
 csrc/buz/recorder.cpp |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp
index 2d00c57..8f32088 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>
 }
@@ -68,7 +70,6 @@
                 fclose(fp_);
                 fp_ = NULL;
             }
-            
         }
 
         int Recorder::init_write_h264(const bool audio){
@@ -81,6 +82,12 @@
             int pid = getpid();
             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){
@@ -95,9 +102,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 +127,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_){
@@ -305,10 +322,6 @@
             if (in->open(NULL, NULL) < 0){
                 logIt("mux hevc open stream error");
                 return -3;
-            }
-            if (!in->findStreamInfo(NULL)) {
-                logIt("mux hevc can't find streams");
-                return -4;
             }
             
             std::unique_ptr<FormatOut> out(new FormatOut(in_->getFPS(), "mp4"));

--
Gitblit v1.8.0