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/ffmpeg/format/FormatOut.cpp |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/csrc/ffmpeg/format/FormatOut.cpp b/csrc/ffmpeg/format/FormatOut.cpp
index 6c91db6..5d51aaf 100644
--- a/csrc/ffmpeg/format/FormatOut.cpp
+++ b/csrc/ffmpeg/format/FormatOut.cpp
@@ -107,8 +107,8 @@
 
         enc_ctx_->codec_id = AV_CODEC_ID_H264;
         enc_ctx_->codec_type = AVMEDIA_TYPE_VIDEO;
-        enc_ctx_->height = (prop.height_ & 0x01) ? prop.height_-1 : prop.height_;
-        enc_ctx_->width = (prop.width_ & 0x01) ? prop.width_ - 1 : prop.width_;
+        enc_ctx_->height = prop.height_ & ~0x01;
+        enc_ctx_->width = prop.width_ & ~0x01;
 
         enc_ctx_->sample_aspect_ratio = prop.sample_aspect_ratio_;
         
@@ -182,7 +182,7 @@
         av_opt_set(enc_ctx_->priv_data, "tune", "zerolatency", 0);
         av_opt_set(enc_ctx_->priv_data, "profile", "baseline", 0);
     
-        int err =avcodec_open2(enc_ctx_, codec, NULL);
+        int err = avcodec_open2(enc_ctx_, codec, NULL);
         if( err< 0)
         {
             logIt("can't open output codec: %s", getAVErrorDesc(err).c_str());
@@ -194,14 +194,11 @@
             return false;
         }
         ofmt->video_codec = codec_id;
-        if(ofmt->flags & AVFMT_GLOBALHEADER)
-        {
+        if(ofmt->flags & AVFMT_GLOBALHEADER){
             enc_ctx_->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
         }
 
-
         return true;
-
 	}
 	
     AVStream *FormatOut::getStream(){

--
Gitblit v1.8.0