From: Simon Rit Date: Thu, 22 Mar 2012 16:50:10 +0000 (+0100) Subject: Simplified video capture code X-Git-Tag: v1.3.0~70 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=ea3651a8d897fad6285b84032dd0a121ec8db2dd;p=clitk.git Simplified video capture code --- diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index a21ec08..0635d7b 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -70,6 +70,7 @@ #include #include #include +#include #ifdef VTK_USE_FFMPEG_ENCODER # include #endif @@ -2771,11 +2772,14 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) imgwriter->SetFileName(fileName.toStdString().c_str()); imgwriter->Write(); return; + } + + // Video + vtkGenericMovieWriter *vidwriter = NULL; #ifdef VTK_USE_FFMPEG_ENCODER - } else if (!strcmp(ext, ".avi")) { + if (!strcmp(ext, ".avi")) { vtkFFMPEGWriter *mpg = vtkFFMPEGWriter::New(); - mpg->SetInput(image); - mpg->SetFileName(fileName.toStdString().c_str()); + vidwriter = mpg; mpg->SetQuality(2); bool ok; int fps = QInputDialog::getInt(this, tr("Number of frames per second"), @@ -2784,28 +2788,20 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget) fps = 5; mpg->SetRate(fps); mpg->SetBitRateTolerance(int(ceil(12.0*1024*1024/fps))); - mpg->Start(); - - vvImage * vvImg = mSlicerManagers[smIndex]->GetImage(); - int nSlice = vvImg->GetVTKImages().size(); - for(int i=0; iSetNextTSlice(0); - vtkSmartPointer w2i = vtkSmartPointer::New(); - w2i->SetInput(widget->GetRenderWindow()); - w2i->Update(); - mpg->SetInput(w2i->GetOutput()); - mpg->Write(); - } - mpg->End(); - mpg->Delete(); + } #endif #ifdef VTK_USE_MPEG2_ENCODER - } else if (!strcmp(ext, ".mpg")) { + if (!strcmp(ext, ".mpg")) { vtkMPEG2Writer *mpg = vtkMPEG2Writer::New(); - mpg->SetInput(image); - mpg->SetFileName(fileName.toStdString().c_str()); - mpg->Start(); + vidwriter = mpg; + } +#endif + // Take video if not null + if(vidwriter!=NULL){ + vidwriter->SetInput(image); + vidwriter->SetFileName(fileName.toStdString().c_str()); + vidwriter->Start(); vvImage * vvImg = mSlicerManagers[smIndex]->GetImage(); int nSlice = vvImg->GetVTKImages().size(); for(int i=0; i w2i = vtkSmartPointer::New(); w2i->SetInput(widget->GetRenderWindow()); w2i->Update(); - mpg->SetInput(w2i->GetOutput()); - mpg->Write(); + vidwriter->SetInput(w2i->GetOutput()); + vidwriter->Write(); } - mpg->End(); - mpg->Delete(); -#endif - } else { - QMessageBox::information(this,tr("Problem saving screenshot !"),tr("Cannot save image.\nPlease set a file extension !!!")); + vidwriter->End(); + vidwriter->Delete(); + return; } + + QMessageBox::information(this,tr("Problem saving screenshot !"),tr("Cannot save image.\nPlease set a file extension !!!")); } } //------------------------------------------------------------------------------