在FFmpeg中,有一个参数"-listen“来侦听指定的端口:
# Server side (receiving):
ffmpeg -listen 1 -enter code herei http://server:port -c copy somefile.ogghttps://www.ffmpeg.org/ffmpeg-protocols.html#toc-http
我想在C++中与Libav一起使用这个命令(因为FFMpeg已经移到了Libav)。
对于侦听端口,我需要使用哪种Libav方法?
发布于 2015-09-11 08:43:53
我通过以下方式解决了问题:
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;
}https://stackoverflow.com/questions/31783860
复制相似问题