openh264 编码命令行工具源码分析

openh264

OpenH264 是由 Cisco 公司发布的一个开源的 H.264 编码和解码器。它提供了命令行工具,可以用于对视频进行编码和解码操作。

使用说明

  • openh264 编码命令行工具可以使用命令行或 config 配置进行编码操作。
  • 编译和使用方法具体可以参考 Windows11编译openh264源码。

编码命令行工具源码分析

源码位置

位置:openh264/codec/console/enc/src/welsenc.cpp

框架

在这里插入图片描述

  1. 模块功能:
  • main:可执行程序的入口函数。
  • PrintHelp:打印帮助函数,提示如何应用命令行参数说明。
  • WelsTime:计算时间函数。
  • ParseConfig:解析 config 函数。
  • signal:信号处理,中断程序。
  • ParseCommandLine:解析命令行函数。
  • libopenh264enc:调用 openh264 编码模块API,实现编码功能。

关键类或结构体分析

  1. ISVCEncoder:编码抽象基类,提供了视频编码的基本操作,在 codec_api.h 文件中定义。
//代码有删减
class ISVCEncoder {public:/*** @brief  Initialize the encoder* @param  pParam  basic encoder parameter* @return CM_RETURN: 0 - success; otherwise - failed;*/virtual int EXTAPI Initialize (const SEncParamBase* pParam) = 0;/*** @brief  Initilaize encoder by using extension parameters.* @param  pParam  extension parameter for encoder* @return CM_RETURN: 0 - success; otherwise - failed;*/virtual int EXTAPI InitializeExt (const SEncParamExt* pParam) = 0;/*** @brief   Get the default extension parameters.*          If you want to change some parameters of encoder, firstly you need to get the default encoding parameters,*          after that you can change part of parameters you want to.* @param   pParam  extension parameter for encoder* @return  CM_RETURN: 0 - success; otherwise - failed;* */virtual int EXTAPI GetDefaultParams (SEncParamExt* pParam) = 0;/// uninitialize the encodervirtual int EXTAPI Uninitialize() = 0;/*** @brief Encode one frame* @param kpSrcPic the pointer to the source luminance plane*        chrominance data:*        CbData = kpSrc  +  m_iMaxPicWidth * m_iMaxPicHeight;*        CrData = CbData + (m_iMaxPicWidth * m_iMaxPicHeight)/4;*        the application calling this interface needs to ensure the data validation between the location* @param pBsInfo output bit stream* @return  0 - success; otherwise -failed;*/virtual int EXTAPI EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSInfo* pBsInfo) = 0;/*** @brief  Encode the parameters from output bit stream* @param  pBsInfo output bit stream* @return 0 - success; otherwise - failed;*/virtual int EXTAPI EncodeParameterSets (SFrameBSInfo* pBsInfo) = 0;/*** @brief  Force encoder to encoder frame as IDR if bIDR set as true* @param  bIDR true: force encoder to encode frame as IDR frame;false, return 1 and nothing to do* @return 0 - success; otherwise - failed;*/virtual int EXTAPI ForceIntraFrame (bool bIDR, int iLayerId = -1) = 0;/*** @brief   Set option for encoder, detail option type, please refer to enumurate ENCODER_OPTION.* @param   pOption option for encoder such as InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,...* @return  CM_RETURN: 0 - success; otherwise - failed;*/virtual int EXTAPI SetOption (ENCODER_OPTION eOptionId, void* pOption) = 0;/*** @brief   Get option for encoder, detail option type, please refer to enumurate ENCODER_OPTION.* @param   pOption option for encoder such as InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,...* @return  CM_RETURN: 0 - success; otherwise - failed;*/virtual int EXTAPI GetOption (ENCODER_OPTION eOptionId, void* pOption) = 0;virtual ~ISVCEncoder() {}
};
  1. SFrameBSInfo:编码器中描述视频比特流信息结构体,在 codec_app_def.h 文件中定义。
//代码有删减
/**
* @brief Frame bit stream info
*/
typedef struct {int           iLayerNum;SLayerBSInfo  sLayerInfo[MAX_LAYER_NUM_OF_FRAME];EVideoFrameType eFrameType;int iFrameSizeInBytes;long long uiTimeStamp;
} SFrameBSInfo, *PFrameBSInfo;
  1. SEncParamExt:编码器中扩展编码参数结构体,包含了 svc 相关编码参数,在codec_app_def.h 文件中定义。
//代码有删减
/**
* @brief SVC Encoding Parameters extention
*/
typedef struct TagEncParamExt {EUsageTypeiUsageType;                          ///< same as in TagEncParamBaseint       iPicWidth;                 ///< same as in TagEncParamBaseint       iPicHeight;                ///< same as in TagEncParamBaseint       iTargetBitrate;            ///< same as in TagEncParamBaseRC_MODES  iRCMode;                   ///< same as in TagEncParamBasefloat     fMaxFrameRate;             ///< same as in TagEncParamBaseint       iTemporalLayerNum;         ///< temporal layer number, max temporal layer = 4int       iSpatialLayerNum;          ///< spatial layer number,1<= iSpatialLayerNum <= MAX_SPATIAL_LAYER_NUM, MAX_SPATIAL_LAYER_NUM = 4SSpatialLayerConfig sSpatialLayers[MAX_SPATIAL_LAYER_NUM];ECOMPLEXITY_MODE iComplexityMode;unsigned int      uiIntraPeriod;     ///< period of Intra frameint               iNumRefFrame;      ///< number of reference frame usedEParameterSetStrategyeSpsPpsIdStrategy;       ///< different stategy in adjust ID in SPS/PPS: 0- constant ID, 1-additional ID, 6-mapping and additionalbool    bPrefixNalAddingCtrl;        ///< false:not use Prefix NAL; true: use Prefix NALbool    bEnableSSEI;                 ///< false:not use SSEI; true: use SSEI -- TODO: planning to remove the interface of SSEIbool    bSimulcastAVC;               ///< (when encoding more than 1 spatial layer) false: use SVC syntax for higher layers; true: use Simulcast AVCint     iPaddingFlag;                ///< 0:disable padding;1:paddingint     iEntropyCodingModeFlag;      ///< 0:CAVLC  1:CABAC./* rc control */bool    bEnableFrameSkip;            ///< False: don't skip frame even if VBV buffer overflow.True: allow skipping frames to keep the bitrate within limitsint     iMaxBitrate;                 ///< the maximum bitrate, in unit of bps, set it to UNSPECIFIED_BIT_RATE if not neededint     iMaxQp;                      ///< the maximum QP encoder supportsint     iMinQp;                      ///< the minmum QP encoder supportsunsigned int uiMaxNalSize;           ///< the maximum NAL size.  This value should be not 0 for dynamic slice mode/*LTR settings*/bool     bEnableLongTermReference;   ///< 1: on, 0: offint      iLTRRefNum;                 ///< the number of LTR(long term reference),TODO: not supported to set it arbitrary yetunsigned int      iLtrMarkPeriod;    ///< the LTR marked period that is used in feedback./* multi-thread settings*/unsigned shortiMultipleThreadIdc;                  ///< 1 # 0: auto(dynamic imp. internal encoder); 1: multiple threads imp. disabled; lager than 1: count number of threads;bool  bUseLoadBalancing; ///< only used when uiSliceMode=1 or 3, will change slicing of a picture during the run-time of multi-thread encoding, so the result of each run may be different/* Deblocking loop filter */int       iLoopFilterDisableIdc;     ///< 0: on, 1: off, 2: on except for slice boundariesint       iLoopFilterAlphaC0Offset;  ///< AlphaOffset: valid range [-6, 6], default 0int       iLoopFilterBetaOffset;     ///< BetaOffset: valid range [-6, 6], default 0/*pre-processing feature*/bool    bEnableDenoise;              ///< denoise controlbool    bEnableBackgroundDetection;  ///< background detection control //VAA_BACKGROUND_DETECTION //BGD cmdbool    bEnableAdaptiveQuant;        ///< adaptive quantization controlbool    bEnableFrameCroppingFlag;    ///< enable frame cropping flag: TRUE always in applicationbool    bEnableSceneChangeDetect;bool    bIsLosslessLink;            ///<  LTR advanced setting
} SEncParamExt;
  1. SSourcePicture:编码器中输入源图像数据结构体,在 codec_app_def.h 文件中定义。
//代码有删减
/**
*  @brief Structure for source picture
*/
typedef struct Source_Picture_s {int       iColorFormat;          ///< color space typeint       iStride[4];            ///< stride for each plane pDataunsigned char*  pData[4];        ///< plane pDataint       iPicWidth;             ///< luma picture width in x coordinateint       iPicHeight;            ///< luma picture height in y coordinatelong long uiTimeStamp;           ///< timestamp of the source picture, unit: millisecond
} SSourcePicture;
  1. SFilesSet:命令行工具模块存储与视频编码相关的文件设置信息的结构体,在welsenc.cpp文件中定义。
//代码有删减
typedef struct tagFilesSet {string strBsFile;string strSeqFile;    // for cmd linesstring strLayerCfgFile[MAX_DEPENDENCY_LAYER];char   sRecFileName[MAX_DEPENDENCY_LAYER][MAX_FNAME_LEN];uint32_t uiFrameToBeCoded;bool     bEnableMultiBsFile;tagFilesSet() {uiFrameToBeCoded = 0;bEnableMultiBsFile = false;for (int i = 0; i < MAX_DEPENDENCY_LAYER; i++)sRecFileName[i][0] = '\0';}
} SFilesSet;
  1. CReadConfig:命令行工具模块中读入 config 的类,在 read_config.h 中定义。
//代码有删减
class CReadConfig {public:CReadConfig();CReadConfig (const char* pConfigFileName);CReadConfig (const std::string& pConfigFileName);virtual ~CReadConfig();void Openf (const char* strFile);long ReadLine (std::string* strVal, const int iValSize = 4);const bool EndOfFile();const int GetLines();const bool ExistFile();const std::string& GetFileName();private:FILE*             m_pCfgFile;std::string       m_strCfgFileName;unsigned int      m_iLines;
};
  1. SLayerPEncCtx:命令行工具模块中层上下文结构体,被用于存储与特定编码层相关的参数和上下文信息,主要在解析命令行中使用,在 welsenc.cpp 文件中定义。
//代码有删减
/**  Layer Context*/
typedef struct LayerpEncCtx_s {int32_t       iDLayerQp;SSliceArgument  sSliceArgument;
} SLayerPEncCtx;

函数流程图

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/22598.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

easyexcel将csv转为excel处理数字问题

使用easyexcel可以将csv格式的文件转为.xlsx文件&#xff0c;但是csv中有很多数字&#xff0c;比如&#xff1a;"123","12.34","-111"&#xff0c;默认情况下会将其作为字符串写入.xlsx文件&#xff0c;就如同下面一样&#xff0c;字符类型的数字…

web应用中的robots.txt配置

web应用中的robots.txt配置 配置/robots.txt 有什么用 在Web应用中&#xff0c;robots.txt 是一个非常重要的文件&#xff0c;它用于指导网络爬虫&#xff08;如搜索引擎的爬虫&#xff09;如何访问和索引网站的内容。这个文件位于网站的根目录&#xff08;即 http://www.exa…

国产SDI/功能与GV7600/GS2972类似

是一款传递数字标清和高清信号的数字视频发送器&#xff0c;功能与GV7600/GS2972类似&#xff0c;集成了线缆驱动器&#xff0c;可以使用 75 欧姆的同轴线缆传递525i&#xff0c;625i&#xff0c;720P&#xff0c;1080P。 支持的速率如下&#xff1a; 如需更多资料请留言哦&am…

手写apply,call,bind函数3

开始正题 bash 复制代码 手写apply,call,bind函数? 这道题其实理清楚apply,call,bind的特点就行了。首先apply,call,bind都是强制绑定this,而apply和call都是立即执行&#xff0c;只有bind是返回一个函数&#xff0c;所以可以将apply和call放在一起分析。 apply和call a…

【Spring框架全系列】SpringBoot_3种配置文件_yml语法_多环境开发配置_配置文件分类(详细)

文章目录 1.三种配置文件2. yaml语法2.1 yaml语法规则2.2 yaml数组数据2.3 yaml数据读取 3. 多环境开发配置3.1 多环境启动配置3.2 多环境启动命令格式3.3 多环境开发控制 4. 配置文件分类 1.三种配置文件 问题导入 框架常见的配置文件有哪几种形式&#xff1f; 比如&#xf…

python11 序列的相关操作

枚举遍历 序列的相关操作 text "hello,python" # in 判断字符是否在序列中&#xff0c;存在返回true,否则返回false print(p是否存在:,(p in text)) print(a是否存在:,(a in text)) # not in 判断字符不在序列中&#xff0c;不存在返回true,否则返回false print(p不…

解决selenium加载网页过慢影响程序运行时间的问题

在用selenium爬取动态加载网页时&#xff0c;发现网页内容都全部加载完了&#xff0c;但是页面还在转圈&#xff0c;并且获取页面内容的代码也没有执行&#xff0c;后面了解到selenium元素操作等方法是需要等待页面所有元素完全加载完成后才开始执行的&#xff0c;所以在页面未…

springboot +shiro导致springboot 事务不起作用

解决方法&#xff1a;一、加监听&#xff0c;二、懒加载&#xff08;Autowired前加Lazy&#xff09; 例如&#xff1a; 二、&#xff08;每个autowired前都加lazy&#xff09;(不推荐) Lazy Autowired private UserService userService; 一、 Bean("securityManager&…

2024年数字化经济与金融创新国际学术会议(ICDEFI 2024)

2024年数字化经济与金融创新国际学术会议&#xff08;ICDEFI 2024&#xff09; 会议简介 2024年数字经济与金融创新国际学术会议即将召开。此次会议旨在汇集全球数字经济与金融创新领域的专家学者&#xff0c;共同探讨数字经济的发展趋势以及金融创新的路径。与会者将分享前沿…

机房网络运维服务项目难点与关键点分析

随着信息技术的飞速发展&#xff0c;机房作为支撑企业信息化建设的核心枢纽&#xff0c;其网络运维服务的重要性日益凸显。然而&#xff0c;在实际运维过程中&#xff0c;运维团队常常面临诸多难点和挑战。本文将围绕机房网络运维服务项目的难点和关键点进行深入分析&#xff0…

如何理解 Java 8 引入的 Lambda 表达式及其使用场景

Lambda表达式是Java 8引入的一项重要特性&#xff0c;它使得编写简洁、可读和高效的代码成为可能。Lambda表达式本质上是一种匿名函数&#xff0c;能够更简洁地表示可传递的代码块&#xff0c;用于简化函数式编程的实现。 一、Lambda表达式概述 1. 什么是Lambda表达式 Lambd…

【STM32】STM32F103C6T6标准外设库

1、标准外设库获取 第一步&#xff0c;首先获取标准外设库&#xff0c;可以从官网进行下载。 https://www.st.com.cn/zh/embedded-software/stm32-standard-peripheral-libraries.html 根据自己的型号选择不同的系列&#xff0c;我这里选择是STM32F1系列 下载最新版本V3.6&a…

KafkaStream Local Store和Global Store区别和用法

前言 使用kafkaStream进行流式计算时&#xff0c;如果需要对数据进行状态处理&#xff0c;那么常用的会遇到kafkaStream的store&#xff0c;而store也有Local Store以及Global Store&#xff0c;当然也可以使用其他方案的来进行状态保存&#xff0c;文本主要理清楚kafkaStream…

【QT5】<总览二> QT信号槽、对象树及样式表

文章目录 前言 一、QT信号与槽 1. 信号槽连接模型 2. 信号槽介绍 3. 自定义信号槽 二、不使用UI文件编程 三、QT的对象树 四、添加资源文件 五、样式表的使用 六、QSS文件的使用 前言 承接【QT5】&#xff1c;总览一&#xff1e; QT环境搭建、快捷键及编程规范。若存…

【最新鸿蒙应用开发】——一篇搞懂什么是UIAbility

UIAbility组件 UIAbility组件是一种包含UI的应用组件&#xff0c;UIAbility组件是系统调度的基本单元&#xff08;最小单元&#xff09;&#xff0c;为应用提供绘制界面的窗口&#xff0c;主要用于和用户交互。一个应用可以包含一个或多个UIAbility组件。 UIAbility的设计理念…

AI大模型应用开发实践:5.快速入门 Assistants API

快速入门 Assistants API Assistants API 允许您在自己的应用程序中构建人工智能助手。一个助手有其指令,并可以利用模型、工具和知识来回应用户查询。 Assistants API 目前支持三种类型的工具: 代码解释器 Code Interpreter检索 Retrieval函数调用 Function calling使用 P…

【LeetCode】使括号有效的最少添加

题目链接&#xff1a; 921. 使括号有效的最少添加 - 力扣&#xff08;LeetCode&#xff09; 对于一个只有&#xff08;&#xff09;组合的括号字符串&#xff0c;如果想要这个字符串是有效的括号对&#xff0c;找出最少需要插入多少个括号 括号离不开栈&#xff0c;栈可以消除…

Java同步与线程安全,同步方法、同步块和java.util.concurrent包的使用

Java的同步与线程安全是并发编程中至关重要的部分。在多线程环境下&#xff0c;确保数据的一致性和避免竞态条件&#xff08;race condition&#xff09;是程序设计的关键。 一、Java中的线程安全 线程安全&#xff08;Thread Safety&#xff09;是指多线程环境下&#xff0c…

C++中的注释作用

程序的注释是解释性语句&#xff0c;您可以在 C 代码中包含注释&#xff0c;这将提高源代码的可读性。所有的编程语言都允许某种形式的注释。 C 支持单行注释和多行注释。注释中的所有字符会被 C 编译器忽略。 C 注释一般有两种&#xff1a; // - 一般用于单行注释。 / ...…

【耗时八个小时】机器学习过拟合和欠拟合!看这一篇文章就够了

.. 纯. .干 货 . . . . 在机器学习中&#xff0c;有一项非常重要的概念&#xff0c;那就是&#xff1a;过拟合&#xff08;Overfitting&#xff09;和欠拟合&#xff08;Underfitting&#xff09;。 它们涉及到机器学习中常见的两种模型性能问题&#xff0c;分别表示模型在训练…