0

我正在开发一些依赖于 Wi-Fi RAK5206 电子板的 C++ 项目。我正在使用 ffmpeg 库来获取视频和音频流,我遇到了可以启动和停止流四次的问题,但是当我想第五次启动时出现错误。错误描述是Invalid data found when processing input当我调用avformat_open_input函数并且我需要重新启动电子板,重新连接到 Wi-Fi 等时发生。

我通过 Wireshark 应用程序发现 VLC 正在工作,并且在TEARDOWN被调用时它正在发送一些 BYE 数据包。我想知道错误是否取决于他们,因为我没有从我的应用程序发送。如何进行设置以强制 ffmpeg 发送 BYE 数据包?

我在rtpenc.h文件中找到了一些声明,当我想连接时设置和尝试这些选项,但显然没有成功。我用于设置选项和打开输入的代码:

AVDictionary* stream_opts = 0;
av_dict_set(&stream_opts, "rtpflags", "send_bye", 0);
avformat_open_input(&format_ctx, url.c_str(), NULL, &stream_opts);
4

2 回答 2

0

确保从您的应用程序中调用此 av_write_trailer 函数。

如果不是,请调试并检查它。

/* Write the trailer, if any. The trailer must be written before you
     * close the CodecContexts open when you wrote the header; otherwise
     * av_write_trailer() may try to use memory that was freed on
     * av_codec_close(). */
    av_write_trailer(oc);

来自ffmpeg源的函数调用流代码片段:

    av_write_trailer -> 
    ....
    ret = s->oformat->write_trailer(s);
    } else {
        s->oformat->write_trailer(s);
    }
    ...
    .write_trailer  = rtp_write_trailer  -> 
    ...
    if (s1->pb && (s->flags & FF_RTP_FLAG_SEND_BYE))
       rtcp_send_sr(s1, ff_ntp_time(), 1)
于 2019-10-20T20:54:21.663 回答
0

解决了将标志 16(二进制:10000)添加到AVFormatContext对象标志的问题。

formatCtx->flags = formatCtx->flags | 16;

根据rtpenc.h

#define FF_RTP_FLAG_SEND_BYE  16
于 2019-10-29T08:38:03.703 回答