ps:本文总结的是ffmpeg库在调用过程中因为版本不同或编译器不同导致问题的一些解决方法,在实际使用过程中还需根据当前的环境进行验证测试。
(1)fatal error C1189: #error : missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
解决方法:在libavutil\common.h文件头部加上以下宏定义即可:
#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#ifdef _STDINT_H
#undef _STDINT_H
#endif
# include "stdint.h"
#endif
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
(2)ffmpeg版本升级导致的该函数在使用时出现 编译不通过的问题
如下情况:
AVStream::codec 被声明为已否决
// if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
// pCodecCtx = pFormatCtx->streams[videoindex]->codec;
pCodecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoindex]->codecpar);
解决方法:
替换注释部分
(3)windows.h 与 winsock2.h 头文件部分函数重复
解决方法:加此宏
#define WIN32_LEAN_AND_MEAN#include <windows.h>
(4)对于网络流起播延迟的处理方法
avformt_find_stream_info(AVFormatContext *ic, AVDictionary **options)函数默认需要花费较长的时间进行流格式探测,因此需要对该ic的probesize (32k) 和 max_analyze_duration(5s)的默认参数进行进行修改,实际可以根据情况进行测试修改其值。
解决方法:
AVDictionary *optionsDict = NULL
//设置打开流的超时时间(微秒)
av_dict_set(&optionsDict, "stimeout", "1000000", 0);
//av_dict_set(&optionsDict, "rtsp_transport", "udp_multicast", 0);
//当从输入中读取数据包时,不要阻塞
m_FormatCtx->flags |= AVFMT_FLAG_NONBLOCK;
//确定输入格式而从输入读取的最大数据大小
m_FormatCtx->probesize = 100 * 1024;
//从输入avformat_find_stream_info()中读取数据的最大持续时间
m_FormatCtx->max_analyze_duration = 1 * AV_TIME_BASE;