簡體   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