ffmpeg: 解析SDP

使用ffmpeg直接打开sdp文件播放里面流媒体.

0x0 使用Custom I/O

ffmpeg 有一个非常好用的模块: AVIO, 这个模块是用ffmpeg Custom I/O 的主要接口,来看API;

  • 结构体

    • AVIOInterruptCB : Callback for checking whether to abort blocking functions
    • AVIODirEntry
    • AVIODirContext
    • AVIOContext : Bytestream IO Context,
  • 常用函数

    • avio_open, avio_open2
    • avio_alloc_context,
    • avio_read
    • avio_write

这些函数的详细使用可以参考官方示例:http_multiclinet.c官方文档

解析SDP

初始话必要的网络和解码模块

av_register_all()
avformat_network_init()

Alloc AVIO Context

unsigned char *iobuffer; // sdp 
AVIOContext *avio = avio_alloc_context(iobuffer, sdp_size, 0, (void*)NULL, NULL, NULL,NULL);

// 把io context 设置到 avformat context 上去,
//这样ffmpeg就进入了Custom模式;
//详细查看源码里面类是 if (formatCtx->pb != NULL) { //custom io }

pFormatCtx->pb = avio

Demuxer, Decoder


pFormatCtx->iformat = av_find_input_format("sdp");

int err = avformat_open_input(&pFormatCtx, "nothing", NULL, NULL);
if(err) {
printf("avformat_open_input error: %d\n", err);
return -1;
}

// Retrieve stream information
if(avformat_find_stream_info(pFormatCtx, NULL)<0) {
printf("avformat_find_stream_info error!!!\n");
return -1; // Couldn't find stream information
}

完整示例

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include <stdio.h>
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值