以下是一段使用ffmpeg库解析rtsp流并将其转码为H264的C代码:
``` #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libswscale/swscale.h>
int main(int argc, char *argv[]) { AVFormatContext *pFormatCtx = NULL; int videoStream, i; AVCodecContext *pCodecCtx = NULL; AVCodec *pCodec = NULL; AVFrame *pFrame = NULL; AVPacket packet; int frameFinished; AVFrame *pFrameRGB = NULL; uint8_t *buffer = NULL; struct SwsContext *sws_ctx = NULL;
av_register_all();
// 打开rtsp流
if (avformat_open_input(&pFormatCtx, "rtsp://stream_url", NULL, NULL