首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在FFmpeg/Libav中收听端口

在FFmpeg/Libav中收听端口
EN

Stack Overflow用户
提问于 2015-08-03 09:29:01
回答 1查看 1.4K关注 0票数 1

在FFmpeg中,有一个参数"-listen“来侦听指定的端口:

代码语言:javascript
复制
# Server side (receiving):
ffmpeg -listen 1 -enter code herei http://server:port -c copy somefile.ogg

https://www.ffmpeg.org/ffmpeg-protocols.html#toc-http

我想在C++中与Libav一起使用这个命令(因为FFMpeg已经移到了Libav)。

对于侦听端口,我需要使用哪种Libav方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-11 08:43:53

我通过以下方式解决了问题:

代码语言:javascript
复制
void listen(const unsigned int port) {

const int TIMEOUT = 600000;

// check if webservice is already listening
if (!m_listening) {

    m_listening = true;

    // Format specification: tcp://hostname:port[?options]
    // See: https://www.ffmpeg.org/ffmpeg-protocols.html#tcp

    std::stringstream ss;
    ss << "tcp://localhost:" << port << "?listen=1" << "?listen_timeout=" << TIMEOUT << "?timeout=" << TIMEOUT * 1000;
    const std::string publishingPointURI = ss.str();
    avformat_network_init();
    if (avformat_open_input(&m_stream, publishingPointURI.c_str(), NULL, NULL) != 0) {
            throw Exception(
                    "Unable to buffer stream received from " + publishingPointURI + "");
    }

    m_listening = false;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31783860

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档