要使用FFmpeg来解析RTSP流并获取视频的宽度和高度,你可以使用avformat_find_stream_info函数来获取流的信息,然后从AVStream结构体中读取视频的宽度和高度。以下是一个简单的示例代码:
#include <libavformat/avformat.h>
int main(int argc, char *argv[]) {
AVFormatContext *format_ctx = NULL;
int video_stream_index = -1;
AVDictionary *options = NULL;
AVCodecParameters *codec_params;
int width, height;
av_register_all();
// 打开RTSP流
if (avformat_open_input(&format_ctx, "rtsp://your_rtsp_url", NULL, &options) != 0) {
printf("无法打开输入流\n");
return -1;
}
// 获取流信息
if (avformat_find_stream_info(format_ctx, NULL) < 0) {
printf("无法获取流信息\n");
return -1;
}
// 查找视频流
for (unsigned i = 0; i < format_ctx->nb