0
votes

I’m working on some C++ project which depends on Wi-Fi RAK5206 electronic board. I’m using ffmpeg library to obtain video and audio stream and I have issue where I can start and stop stream for four times, but when I want to start for the fifth time I get error. Error description is Invalid data found when processing input and it happens when I call avformat_open_input function and I need to restart the electronic board, reconnect to Wi-Fi etc.

I figured out with Wireshark application that VLC is working and it is sending some BYE packets when TEARDOWN is called. I wonder if error depends to them, because from my application I’m not sending. How I can make setup to force ffmpeg to send BYE packets?

I found some declarations in rtpenc.h file which options to set and tried when I want to connect, but obviously without success. The code that I used for setting options and opening input:

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

2 Answers

0
votes

Make sure you are calling this av_write_trailer function, from your application.

if not please debug and check it.

/* 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);

function Call flow code snippet from ffmpeg source:

    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)
0
votes

Resolved issue with adding flag 16 (binary: 10000) to AVFormatContext object's flag.

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

According to rtpenc.h:

#define FF_RTP_FLAG_SEND_BYE  16