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

二、网络流媒体协议

  1. RTSP/RTP

    • 支持 rtsp:// 开头的实时流传输,可通过 rtsp_transport 参数指定 TCP/UDP 传输方式
    • 典型应用:监控摄像头、直播推流
  2. HTTP/HTTPS

    • 支持点播(如 http://example.com/video.m3u8)和直播流(HLS/DASH)
    • 需注意:部分 HTTPS 需配置 SSL 证书
  3. UDP/TCP

    • 原始流传输协议(如 udp://@239.255.0.1:1234),常用于组播场景
  4. 其他专用协议

    • RTMP:rtmp:// 常用于直播推拉流
    • SRT:srt:// 低延迟传输协议

三、特殊协议

  • 管道协议‌:pipe: 支持标准输入输出重定向3
  • 内存协议‌:mem: 直接读写内存数据(需配合自定义 AVIOContext)

四、协议支持验证

若遇到 Protocol not found 错误,需检查:

  1. FFmpeg 编译时是否包含对应协议模块(如 --enable-protocol=rtsp
  2. URL 格式是否符合规范(如遗漏 :// 前缀)
  3. 网络权限或防火墙限制

完整协议列表可通过 ffmpeg -protocols 命令查看。实际使用建议通过 av_dict_set 设置超时等参数优化稳定性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值