主函数:
cpp
//108录制五秒视频
#include <iostream>
#include <thread>
#include "xtools.h"
#include "xdemux_task.h"
#include "xdecodetask.h"
#include "xvideo_view.h"
#include "xmux_task.h"
using namespace std;
//大华
#define CAM1 \
"rtsp://admin:admin@192.168.2.108/cam/realmonitor?channel=1&subtype=0"
//海康
#define CAM2 \
"rtsp://127.0.0.1:8554/test"
int main(int argc, char* argv[])
{
XDemuxTask demux_task;
for (;;)
{
if (demux_task.Open(CAM2))
{
cout << "shexiangtoudakaile!!!!";
break;
}
MSleep(100);
continue;
}
auto vpara = demux_task.CopyVideoPara();
AVCodecParameters* video_para = nullptr;
AVCodecParameters* audio_para = nullptr;
AVRational* video_time_base = nullptr;
AVRational* audio_time_base = nullptr;
if (vpara)
{
video_para = vpara->para;
video_time_base = vpara->time_base;
}
auto apara = demux_task.CopyAudioPara();
if (apara)
{
audio_para = apara->para;
audio_time_base = apara->time_base;
}
XMuxTask mux_task;
if (!mux_task.Open("rtsp_out1.mp4", video_para, video_time_base,
audio_para, audio_time_base
))
{
LOGERROR("mux_task.Open failed!");
return -1;
}
demux_task.set_next(&mux_task);
demux_task.Start();
mux_task.Start();
MSleep(5000);
mux_task.Stop();
if (!mux_task.Open("rtsp_out2.mp4", video_para, video_time_base,
audio_para, audio_time_base
))
{
LOGERROR("mux_task.Open failed!");
return -1;
}
mux_task.Start();
MSleep(5000);
mux_task.Stop();
getchar();
return 0;
}