【问题标题】:FFmpeg: Live streaming using RSTP C++FFmpeg:使用 RSTP C++ 进行直播
【发布时间】:2016-12-14 07:59:51
【问题描述】:

我想从摄像头接收视频流,使用 openCV 处理它(用于测试 - 绘制红色矩形)和实时流结果。

我已经可以读取相机帧,转换为 openCV Mat 并将它们改回 AVFrame。

从控制台即时启动 rtsp 服务器,使用:ffplay -rtsp_flags listen -i rtsp://127.0.0.1:8765/live.sdp 当我尝试调用 avio_open(); 时出现问题;

av_register_all();
avformat_network_init();
avcodec_register_all();
(...)
avformat_alloc_output_context2(&outputContext, NULL, "rtsp", outputPath.c_str());
outputFormat = outputContext->oformat;

cout << "Codec = " << avcodec_get_name(outputFormat->video_codec) << endl;

if (outputFormat->video_codec != AV_CODEC_ID_NONE) {
    videoStream = add_stream(outputContext, &outputVideoCodec, outputFormat->video_codec);
}
char errorBuff[80];
int k = avio_open(&outputContext->pb, outputPath.c_str(), AVIO_FLAG_WRITE);
if (k < 0) {
    cout << "code: " << k << endl;
    fprintf(stderr, "%s \n", av_make_error_string(errorBuff, 80, k));
}

if (avformat_write_header(outputContext, NULL) < 0) {
    fprintf(stderr, "Error occurred when writing header");
}

}

其中 outputPath = "rtsp://127.0.0.1:8765/live.sdp" avformat_alloc_output_context2 返回 0,但 avio_open

代码:-1330794744

未找到协议

我不知道出了什么问题。我正在使用来自https://ffmpeg.zeranoe.com/builds/ 64-bit Dev 的 ffmpeg 构建

【问题讨论】:

    标签: c++ ffmpeg streaming


    【解决方案1】:

    通过执行以下操作启用文件协议:

    --enable-protocol=file
    

    【讨论】:

    • 我尝试在 Windows 下使用 github.com/jb-alvarado/media-autobuild_suite 编译 ffmpeg,但我得到了 .a 库文件,如果我在 Visual Studio 中链接它们,我会遇到 LNK 错误墙。 libavutil.a(timecode.o) : error LNK2001: unresolved external symbol __mingw_vsnprintf 经过研究,我发现我还应该链接 libmingw32.a 和 libmingwex.a 库。我做到了,但又遇到了一大堆错误,例如:c:\build\autobuildffmpeg\msys64\mingw64\x86_64-w64-mingw32\include\stdlib.h(306)‌​: error C2059: syntax error: '__declspec(nothrow )'
    • 您是否尝试过查看最后提到如何为 ffmpeg 构建 mingw 的链接? - 该链接似乎已损坏。请参阅本指南:gooli.org/blog/building-ffmpeg-for-windows-with-msys-and-mingw 并按照 jb-alvarado/media-autobuild_suite 中提到的其余步骤
    • 不,我没试过。我将遵循本指南并告知结果。不幸的是,我明天可以做到。
    • 没问题希望它能解决您的问题:)
    • 我尝试按照指南进行操作,但我在使用 Windows 时遇到了一些问题,但是 - 多亏了你 - 我找到了另一种可能性。我在虚拟机上安装了 ubuntu 并遵循了本指南:ffmpeg.zeranoe.com/blog/?p=414 现在我正在使用 ./configure --enable-memalign-hack --arch=x86 --target-os=mingw32 --cross-prefix= 交叉编译 ffmpeg x86_64-w64-mingw32- --prefix=... (...) --enable-protocol=file 我会告诉我得到了什么:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-28
    • 2022-08-20
    • 1970-01-01
    • 2015-10-21
    • 2019-03-17
    • 2012-03-16
    • 2023-04-01
    相关资源
    最近更新 更多