FFmpeg 4.3 H265 二十二.3,avformat_open_input 支持打开的协议
avformat_open_input
函数说明:
解封装:avformat_open_input,avformat_find_stream_info,av_read_frame,av_dump_format,avformat_close_input-CSDN博客
原型
/**
* Open an input stream and read the header. The codecs are not opened.
* The stream must be closed with avformat_close_input().
*
* @param ps Pointer to user-supplied AVFormatContext (allocated by
* avformat_alloc_context). May be a pointer to NULL, in
* which case an AVFormatContext is allocated by this
* function and written into ps.
* Note that a user-supplied AVFormatContext will be freed
* on failure.
* @param url URL of the stream to open.
* @param fmt If non-NULL, this parameter forces a specific input format.
* Otherwise the format is autodetected.
* @param options A dictionary filled with AVFormatContext and demuxer-private
* options.
* On return this parameter will be destroyed and replaced with
* a dict containing options that were not found. May be NULL.
*
* @return 0 on success, a negative AVERROR on failure.
*
* @note If you want to use custom IO, preallocate the format context and set its pb field.
*/
int avformat_open_input(AVFormatContext **ps, const char *url,
const AVInputFormat *fmt, AVDictionary **options);
avformat_open_input
支持的协议--对url参数的说明
avformat_open_input
支持多种协议,主要通过 FFmpeg 的协议层实现统一访问。以下是主要协议类型及特性:
一、本地文件协议
- 文件系统协议:支持
file://
前缀或直接路径(如/home/video.mp4
),可处理 MP4、AVI、FLV 等封装格式13 - 特殊设备:如
/dev/video0
摄像头采集设备(需系统支持)3
二、网络流媒体协议
-
RTSP/RTP
- 支持
rtsp://
开头的实时流传输,可通过rtsp_transport
参数指定 TCP/UDP 传输方式 - 典型应用:监控摄像头、直播推流
- 支持
-
HTTP/HTTPS
- 支持点播(如
http://example.com/video.m3u8
)和直播流(HLS/DASH) - 需注意:部分 HTTPS 需配置 SSL 证书
- 支持点播(如
-
UDP/TCP
- 原始流传输协议(如
udp://@239.255.0.1:1234
),常用于组播场景
- 原始流传输协议(如
-
其他专用协议
- RTMP:
rtmp://
常用于直播推拉流 - SRT:
srt://
低延迟传输协议
- RTMP:
三、特殊协议
- 管道协议:
pipe:
支持标准输入输出重定向3 - 内存协议:
mem:
直接读写内存数据(需配合自定义 AVIOContext)
四、协议支持验证
若遇到 Protocol not found
错误,需检查:
- FFmpeg 编译时是否包含对应协议模块(如
--enable-protocol=rtsp
) - URL 格式是否符合规范(如遗漏
://
前缀) - 网络权限或防火墙限制
完整协议列表可通过 ffmpeg -protocols
命令查看。实际使用建议通过 av_dict_set
设置超时等参数优化稳定性。