由于项目需要实时显示摄像头的图像,就学习了FFmpeg的相关知识。
执行run()函数
打开tcp或udp地址
能否读取流
查找解码器
打开解码器
将解码后数据转换成RGB32
在Qwidget中显示
释放内存
结束程序
网络摄像机rtsp地址详解。
流程框架
程序源代码
#include "Camera_page.h"
#include <stdio.h>
#include<iostream>
#include<QDebug>
#include <QDateTime>
#include <stdlib.h>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/pixfmt.h"
#include "libswscale/swscale.h"
#include "libavutil/time.h"
}
using namespace std;
VideoPlayer::VideoPlayer()
{
}
VideoPlayer::~VideoPlayer()
{
}
void VideoPlayer::startPlay()
{
this->start();
}
void VideoPlayer::run()
{
AVFormatContext *pFormatCtx;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame, *pFrameRGB;
AVPacket *packet;
static uint8_t *out_buffer;
static struct SwsContext *img_convert_ctx;
int videoStream, i, numBytes;
int ret, got_picture;
avformat_network_init();
av_register_all();
pFormatCtx = avformat_alloc_context();
AVDictionary *avdic=NULL;
char option_key[]="rtsp_transport";
char m_bTcp;
av_dict_set(&avdic,option_key,