将rtsp流中的h264视频流在没解码之前获取下来,并保存到本地文件mp4中的h264流中,h264->mp4
网络摄像机rtsp地址详解。
流程图:
源码:
.h
#ifndef RTSPSTREAMMUXTASK_H
#define RTSPSTREAMMUXTASK_H
#include <QMainWindow>
#include <QThread>
#include <QImage>
#include <iostream>
#include <stdio.h>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libavutil/mathematics.h"
}
class RtspStreamMuxTask : public QMainWindow
{
Q_OBJECT
public:
explicit RtspStreamMuxTask(QWidget *parent = 0);
~RtspStreamMuxTask();
void rtsp();
};
#endif // RTSPSTREAMMUXTASK_H
.cpp
#include "rtspstreammuxtask.h"
#include <stdio.h>
#include <iostream>
#include <QDebug>
#include <QDateTime>
#include <stdlib.h>
RtspStreamMuxTask::RtspStreamMuxTask(QWidget *parent) :
QMainWindow(parent)
{
rtsp();
}
RtspStreamMuxTask::~RtspStreamMuxTask()
{
}
void RtspStreamMuxTask::rtsp()
{
AVFormatContext *inVFmtCtx=NULL,*outFmtCtx=NULL;
int frame_index=0;//统计帧数
int inVStreamIndex=-1,outVStreamIndex=-1;//输入输出视频流在文件中的索引位置
const char *inVFileName = "rtsp://admin:123456@192.168.31.16