Reputation: 1937
I am currently developing an application that needs to decode a UDP multicast RTSP stream. At the moment, I can view the RTP stream using ffplay via
ffplay -rtsp_transport udp_multicast rtsp://streamURLGoesHere
However, I am trying to use FFMPEG to open the UDP stream via (error checking and cleanup code removed for the sake of brevity).
AVFormatContext* ctxt = NULL;
av_open_input_file(
&ctxt,
urlString,
NULL,
0,
NULL
);
av_find_stream_info(ctxt);
AVCodecContext* codecCtxt;
int videoStreamIdx = -1;
for (int i = 0; i < ctxt->nb_streams; i++)
{
if (ctxt->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoStreamIdx = i;
break;
}
}
AVCodecContext* codecCtxt = ctxt->streams[videoStreamIdx]->codec;
AVCodec* codec = avcodec_fine_decoder(codecCtxt->codec_id);
avcodec_open(codecCtxt, codec);
AVPacket packet;
while(av_read_frame(ctxt, &packet) >= 0)
{
if (packet.stream_index == videoStreamIdx)
{
/// Decoding performed here
...
}
}
...
This approach works fine with file inputs that consist of a raw encoded video stream, but for UDP multicast RTSP streams, it fails any error checking performed on av_open_input_file()
. Please advise...
Upvotes: 1
Views: 8929
Reputation: 1937
It turns out that opening a multicast UDP RTSP stream can be performed via the following:
AVFormatContext* ctxt = avformat_alloc_context();
AVDictionary* options = NULL;
av_dict_set(&options, "rtsp_transport", "udp_multicast", 0);
avformat_open_input(
&ctxt,
urlString,
NULL,
&options
);
...
avformat_free_context(ctxt);
Using avformat_open_input()
in this manner instead of av_open_input_file()
results in the desired behavior. I'm guessing that av_open_input_file()
is either deprecated or was never intended to be used in this manner -- more than likely the latter ;)
Upvotes: 6