要使用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_streams; i++) {if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {video_stream_index = i;break;}
}if (video_stream_ind