|
@@ -1121,6 +1121,21 @@ void MainWindow::threadinfo()
|
|
|
void MainWindow::threadframe(int ncamppos)
|
|
|
{
|
|
|
iv::h264rawframedata xframe;
|
|
|
+ bool bSave = false;
|
|
|
+ QFile xFile;
|
|
|
+ bool bSaving = false;
|
|
|
+
|
|
|
+ AVOutputFormat *ofmt = NULL;
|
|
|
+ //创建输入AVFormatContext对象和输出AVFormatContext对象
|
|
|
+ AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
|
|
|
+ AVPacket pkt;
|
|
|
+ const char *in_filename;
|
|
|
+ int ret, i;
|
|
|
+ int stream_index = 0;
|
|
|
+ int *stream_mapping = NULL;
|
|
|
+ int stream_mapping_size = 0;
|
|
|
+
|
|
|
+
|
|
|
while(mbThreadrun)
|
|
|
{
|
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
@@ -1134,6 +1149,62 @@ void MainWindow::threadframe(int ncamppos)
|
|
|
xrawframe.mpstr_ptr = xframe.mpstr_ptr;
|
|
|
xrawframe.ndatasize = xframe.mdatasize;
|
|
|
mph264decode[ncamppos]->addframedata(xrawframe);
|
|
|
+ if(bSave != mbSave[ncamppos])
|
|
|
+ {
|
|
|
+ bSave = mbSave[ncamppos];
|
|
|
+ if(bSave)
|
|
|
+ {
|
|
|
+ QString strpath = "./" + QString::number(QDateTime::currentMSecsSinceEpoch())+ "-"+QString::number(ncamppos)+".mp4";
|
|
|
+ //输出文件分配空间
|
|
|
+ avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, strpath.toLatin1().data());
|
|
|
+ if (!ofmt_ctx) {
|
|
|
+ //LogMessage::DebugLogInfo("ReCode", "输出文件分配空间分配失败");
|
|
|
+ std::cout<<" open context fail."<<std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ AVStream *outStream = avformat_new_stream(ofmt_ctx, NULL);
|
|
|
+
|
|
|
+
|
|
|
+ outStream->codecpar->codec_id = AV_CODEC_ID_H264;
|
|
|
+
|
|
|
+ outStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
+ outStream->codecpar->width = mnframewidth;
|
|
|
+ outStream->codecpar->height = mnframeheight;
|
|
|
+ outStream->id = 0;
|
|
|
+
|
|
|
+ ofmt = ofmt_ctx->oformat;
|
|
|
+
|
|
|
+ //打开文件
|
|
|
+ if (!(ofmt->flags & AVFMT_NOFILE)) {
|
|
|
+ ret = avio_open(&ofmt_ctx->pb, strpath.toLatin1().data(), AVIO_FLAG_WRITE);
|
|
|
+ if (ret < 0) {
|
|
|
+ //LogMessage::DebugLogInfo("ReCode", "打开输出文件失败");
|
|
|
+ std::cout<<" open recode fail."<<std::endl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开始写入文件头
|
|
|
+ ret = avformat_write_header(ofmt_ctx, NULL);
|
|
|
+ if (ret < 0) {
|
|
|
+ //LogMessage::DebugLogInfo("ReCode", "写入文件头失败");
|
|
|
+ std::cout<<"write header fail."<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(bSaving)
|
|
|
+ {
|
|
|
+// xFile.close();
|
|
|
+// bSaving = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(bSaving)
|
|
|
+ {
|
|
|
+ xFile.write(xrawframe.mpstr_ptr.get(),xrawframe.ndatasize);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1234,3 +1305,31 @@ void MainWindow::on_horizontalSlider_wheelspeed_valueChanged(int value)
|
|
|
mfWheelSpeed = mfWheelBaseSpeed * ui->horizontalSlider_wheelspeed->value();
|
|
|
mbNeedSetBack = true;
|
|
|
}
|
|
|
+
|
|
|
+void MainWindow::on_actionSave_Video_triggered()
|
|
|
+{
|
|
|
+ static bool bSave = false;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(bSave == false)
|
|
|
+ {
|
|
|
+ bSave = true;
|
|
|
+ ui->actionSave_Video->setText(tr("Recording..."));
|
|
|
+ int i;
|
|
|
+ for(i=0;i<NUM_CAM;i++)
|
|
|
+ {
|
|
|
+ mbSave[i] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bSave = false;
|
|
|
+ ui->actionSave_Video->setText(tr("Save Video"));
|
|
|
+ int i;
|
|
|
+ for(i=0;i<NUM_CAM;i++)
|
|
|
+ {
|
|
|
+ mbSave[i] = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|