博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ffmpeg-hls拉流代码
阅读量:6002 次
发布时间:2019-06-20

本文共 2286 字,大约阅读时间需要 7 分钟。

ffmpeg-hls拉流

协议接口变量

const URLProtocol ff_hls_protocol = {    .name           = "hls",    .url_open       = hls_open,    .url_read       = hls_read,    .url_close      = hls_close,    .flags          = URL_PROTOCOL_FLAG_NESTED_SCHEME,    .priv_data_size = sizeof(HLSContext),};
从上面可以看出来一共就三个接口,打开,读取,关闭

打开

static int hls_open(URLContext *h, const char *uri, int flags){    HLSContext *s = h->priv_data;    int ret, i;    const char *nested_url;    if (flags & AVIO_FLAG_WRITE)        return AVERROR(ENOSYS);    h->is_streamed = 1;    if (av_strstart(uri, "hls+", &nested_url)) {        av_strlcpy(s->playlisturl, nested_url, sizeof(s->playlisturl));    } else if (av_strstart(uri, "hls://", &nested_url)) {        av_log(h, AV_LOG_ERROR,               "No nested protocol specified. Specify e.g. hls+http://%s\n",               nested_url);        ret = AVERROR(EINVAL);        goto fail;    } else {        av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);        ret = AVERROR(EINVAL);        goto fail;    }    av_log(h, AV_LOG_WARNING,           "Using the hls protocol is discouraged, please try using the "           "hls demuxer instead. The hls demuxer should be more complete "           "and work as well as the protocol implementation. (If not, "           "please report it.) To use the demuxer, simply use %s as url.\n",           s->playlisturl);    if ((ret = parse_playlist(h, s->playlisturl)) < 0)        goto fail;    if (s->n_segments == 0 && s->n_variants > 0) {        int max_bandwidth = 0, maxvar = -1;        for (i = 0; i < s->n_variants; i++) {            if (s->variants[i]->bandwidth > max_bandwidth || i == 0) {                max_bandwidth = s->variants[i]->bandwidth;                maxvar = i;            }        }        av_strlcpy(s->playlisturl, s->variants[maxvar]->url,                   sizeof(s->playlisturl));        if ((ret = parse_playlist(h, s->playlisturl)) < 0)            goto fail;    }    if (s->n_segments == 0) {        av_log(h, AV_LOG_WARNING, "Empty playlist\n");        ret = AVERROR(EIO);        goto fail;    }    s->cur_seq_no = s->start_seq_no;    if (!s->finished && s->n_segments >= 3)        s->cur_seq_no = s->start_seq_no + s->n_segments - 3;    return 0;fail:    hls_close(h);    return ret;}
open主要是读取m3u8的信息,并存储到变量中

转载地址:http://badmx.baihongyu.com/

你可能感兴趣的文章
Build Instructions (Windows) – The Chromium Projects
查看>>
我所了解的WEB开发 (1)
查看>>
python官方文档
查看>>
Linux下tomcat无法启动
查看>>
Maven之Nexus构建企业级Maven仓库
查看>>
Vware Workstation pro 12|虚拟机
查看>>
AngularJs学习笔记
查看>>
华为交换机端口安全
查看>>
30天React Native从零到IOS/Android双平台发布总结
查看>>
stringByAppendingPathComponent和stringByAppendingString 的区别
查看>>
dubbo main方法启动
查看>>
Oracle中TO_DATE TO_CHAR格式
查看>>
C#实现HTTP请求文件下载,GET、POST请求的数据流接收
查看>>
Apache配置HTTPS功能
查看>>
CreatarGlobe实现多机立体显示方案(初稿)
查看>>
EasyUI 取得选中行数据
查看>>
Pairwise Leanrning
查看>>
在红帽的linux-rhce-5.4下配置lamp环境
查看>>
流程控制 - PHP手册笔记
查看>>
cocos2d-x 3.0 新特性样例
查看>>