From 24627225c21738ec4f0737da536874e99d58d6ac Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期四, 19 九月 2019 18:01:29 +0800
Subject: [PATCH] update

---
 csrc/ffmpeg/format/FormatOut.cpp |   23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/csrc/ffmpeg/format/FormatOut.cpp b/csrc/ffmpeg/format/FormatOut.cpp
index bc77524..a6e8c3c 100644
--- a/csrc/ffmpeg/format/FormatOut.cpp
+++ b/csrc/ffmpeg/format/FormatOut.cpp
@@ -364,6 +364,7 @@
     bool FormatOut::endWriter(){
 
         auto flag =  writeTrailer();
+        closeResource();
         record_ = false;
 
         return flag;
@@ -403,34 +404,32 @@
         pkt.dts = pkt.pts;
         pkt.duration = av_rescale_q(calc_duration, time_base_q, time_base); //(double)(calc_duration)*(double)(av_q2d(time_base_q)) / (double)(av_q2d(time_base));
         
-        // if (pkt.duration < 0 || time_base.den != 90000){
-            // logIt("CALCULATE DURATION : %lld, fame count : %lld, TIMEBASE: %d", calc_duration,time_stamp, time_base.den);
-        // }
-        
+        // logIt("FRAME ID: %lld, PTS : %lld, DTS : %lld", frame_cnt, pkt.pts, pkt.dts);        
     }
 
     bool FormatOut::writeFrame(AVPacket &pkt, const int64_t &frame_cnt,
                               bool interleaved/* = true*/){
 
         adjustPTS(pkt, frame_cnt);
-        return writeFrame2(pkt, interleaved);
+        auto ret = writeFrame2(pkt, interleaved);
+        if (!ret){
+            logIt("write to file failed, pkt.pts: %lld, dts: %lld, frame count: %d",
+                    pkt.pts, pkt.dts, frame_cnt);
+        }
+        return ret;
     }
 
     bool FormatOut::writeFrame2(AVPacket &pkt, bool interleaved){
         
         int ret = 0;
-        if(interleaved)
+        if(interleaved){
             ret = av_interleaved_write_frame(ctx_, &pkt);
-        else
-        {
+        }else{
             // returns 1 if flushed and there is no more data to flush
             ret = av_write_frame(ctx_, &pkt);
         }
     
-        if(ret < 0)
-        {
-            logIt("write packet to file failed:%s",
-                    getAVErrorDesc(ret).c_str()); 
+        if(ret < 0){
             return false;
         }
 

--
Gitblit v1.8.0