c++ - 在 FFmpeg/Libav 中监听端口

标签 c++ 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

我想在 C++ 中将这个命令与 Libav 一起使用(因为 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;
}

关于c++ - 在 FFmpeg/Libav 中监听端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31783860/

相关文章:

c++ - OpenGL 模板测试发生在片段程序运行之前还是之后?

c++ - 在 C++ 中更改 INI 文件的节顺序的最简单方法是什么

c++ - 从 Qt 中的对话框中获取数据并在 Ui 中使用它

ffmpeg - 从图像创建视频,然后流式传输给用户

ffmpeg - 使用 ffmpeg 合并/混合多个音频

audio - AVCONV : Select german stream not highest quality one

c++ - 如何在 Xlib 应用程序中等待 VSYNC?

c++ - FFMPEG 在 C++ 中对 'avcodoec_open2' 的 undefined reference

c++ - 调用 avformat_find_stream_info 会阻止简单 PNG 图像的解码?

c++ - 使用 libav 从内存中解码视频文件