繁体   English   中英

在FFmpeg / Libav中监听端口

[英]Listening to port in FFmpeg/Libav

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

# 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

我想在带有Libav的C ++中使用此命令(因为FFMpeg已移至Libav)。

要监听端口,我需要使用哪种Libav方法?

我通过以下方法解决了这个问题:

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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM