我目前正在开发一个需要解码UDP多播RTSP流的应用程序。目前,我可以使用ffplay via查看RTP流
ffplay -rtsp_transport udp_multicast rtsp://streamURLGoesHere但是,我正在尝试使用FFMPEG通过打开UDP流(为了简洁,删除了错误检查和清理代码)。
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
...
}
}
...此方法适用于由原始编码视频流组成的文件输入,但对于UDP多播RTSP流,它无法通过在av_open_input_file()上执行的任何错误检查。敬请指教...
发布于 2012-04-25 03:55:42
事实证明,打开组播UDP RTSP流可以通过以下方式执行:
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);以这种方式而不是av_open_input_file()使用avformat_open_input()会产生所需的行为。我猜测av_open_input_file()要么已被弃用,要么从未打算以这种方式使用--很可能是后者;)
https://stackoverflow.com/questions/10300207
复制相似问题