In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Function call logic
Avformat_open_input
Init_input
Av_probe_input_buffer2
Av_probe_input_format3
Read_header
Brief introduction
The avformat_open_input function initializes the AVFormatContext structure. Where the init_input function is called in initializing the AVIOContext structure parameter, and it calls av_probe_input_buffer2 by default to populate the AVIOContext structure parameter. In general, you can first call the av_probe_input_buffer function, populate the AVIOContext structure parameter, and then assign a value to the AVIOContext field in the AVFormatContext structure
Code
AVIOContext pIOContext= avio_alloc_context
AVInputFormat pInputFormat = NULL
Av_probe_input_buffer (pIOContext, & pInputFormat, ", NULL, 0,0)
AVFormatContext* pFormatContext = avformat_alloc_context ()
PFormatContext- > pb = pIOContext
If (avformat_open_input (& FormatContext, ", pInputFormat, NULL)
< 0) 根据av_probe_input_buffer会调用av_probe_input_buffer2,包裹了一层 简化代码如下 AVFormatContext* pFormatContext = avformat_alloc_context(); if (avformat_open_input(&FormatContext, "", pInputFormat, NULL) < 0) 根据实际的测试,关键的地方是AVIOContext的初始化,该结构体将会保存一个读取网络数据的函数入口,根据函数入口来分析数据流。avformat_open_input函数在目前的 测试结果是耗时1秒多,这个应该是一个优化的方向 av_probe_input_buffer2主要是针对输入输出结构体AVIOContext的初始化,如果知道avformat_open_input的赋值内容,对各种协议的读写格式的探测,就可以优化这一块代码。协议的探测分别有file协议,rtmp协议等等,目前在项目中只需要实现文件协议,而文件协议应该如何进行读写? 调用ffio_fdopen()函数创建AVIOContext()结构体并获取URLContext结构体引用的资源(调用avio_alloc_context()实现) 问题 avformat_open_input函数探测ES流开销是150毫秒,探测PS流开销是500毫秒。avformat_open_input函数里面已经实现了av_probe_input_buffer函数的调用,去探测AVInputFormat结构体的相关变量。所以在avformat_open_input函数之前,调用av_probe_input_buffer函数之后,就不会去探测AVInputFormat结构体 优化方向 尝试屏蔽avformat_open_input函数,直接指定码流的输入格式pInputFormat,代码如下: pInputFormat = av_find_input_format("h364"); pFormatCtx->Iformat = pInputFormat
If the avformat_open_input is blocked at this time, the image is banded, and according to the reference, the avformat_open_input
The function is to detect the relevant variables of the AVInputFormat structure
Final optimization scheme
Instead of blocking the avformat _ open_input function, specify the stream input format of AVInputFormat before calling it
Code
AVInputFormat* pInputFormat = NULL
AVFormatContext* pFormatContext = NULL
PFormatContext = avformat_alloc_context ()
PInputFormat = av_find_input_format ("h364")
If (avformat_open_input (& pFormatContext, ", InputFormat, NULL)
< 0) { av_free(...); avformat_free_context(...); fprintf(stdout, "open stream failed!\n"); } else { fprintf(stdout, "open stream success!\n"); } 笔记 m_pVideoc->Io_ctx = avio_alloc_context (m_pAvioBuf, BUF_SIZE, 0, this, ReadStreamData, NULL, NULL)
If (& pFormatCtx, ", piFmt, NULL) < 0)
The actual use of the above ReadStreamData is that when the real-time stream is opened below, if you need to read the data, you can obtain the message content of the frame through the ReadStreamData function.
Instead of passing url through the second argument of the avformat_open_input function
Referenc
Http://blog.csdn.net/leo2007608/article/details/53421528
Http://blog.csdn.net/leixiaohua1020/article/details/39759163
Http://blog.csdn.net/leixiaohua1020/article/details/44064715
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.