Commit 5e9d6a9e authored by Arnaud Gelas's avatar Arnaud Gelas
Browse files

ENH: Correct vtkFFMPEGWriter by adding two variables.

Commit from Nicolas Rannou (Harvard Medical School).
parent ddae0eb5
......@@ -58,6 +58,8 @@ int TestFFMPEGWriter(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
w->SetInputConnection(colorize->GetOutputPort());
w->SetFileName("TestFFMPEGWriter.avi");
cout << "Writing file TestFFMPEGWriter.avi..." << endl;
w->SetBitRate(1024*1024*30);
w->SetBitRateTolerance(1024*1024*3);
w->Start();
for ( cc = 2; cc < 99; cc ++ )
{
......
......@@ -157,29 +157,43 @@ int vtkFFMPEGWriterInternal::Start()
//change DIV3 to MP43 fourCC to be easily playable on windows
//c->codec_tag = ('3'<<24) + ('4'<<16) + ('P'<<8) + 'M';
//to do playback at actual recorded rate, this will need more work see also below
c->time_base.den = this->FrameRate;
c->time_base.den = this->FrameRate;
c->time_base.num = 1;
//about one full frame per second
c->gop_size = this->FrameRate;
//allow a variable quality/size tradeoff
switch (this->Writer->GetQuality())
c->gop_size = this->FrameRate;
if( !this->Writer->GetBitRate() )
{
//allow a variable quality/size tradeoff
switch (this->Writer->GetQuality())
{
case 0:
c->bit_rate = 3*1024*1024;
break;
case 1:
c->bit_rate = 6*1024*1024;
break;
default:
c->bit_rate = 12*1024*1024;
break;
}
}
else
{
case 0:
c->bit_rate = 3*1024*1024;
break;
case 1:
c->bit_rate = 6*1024*1024;
break;
default:
c->bit_rate = 12*1024*1024;
break;
c->bit_rate = this->Writer->GetBitRate();
}
c->bit_rate_tolerance = c->bit_rate/this->FrameRate;
if(!this->Writer->GetBitRateTolerance())
{
c->bit_rate_tolerance = c->bit_rate/this->FrameRate;
}
else
{
c->bit_rate_tolerance = this->Writer->GetBitRateTolerance();
}
//apply the chosen parameters
if (av_set_parameters(this->avFormatContext, NULL) < 0)
if (av_set_parameters(this->avFormatContext, NULL) < 0)
{
vtkGenericWarningMacro (<< "Invalid output format parameters." );
return 0;
......@@ -413,6 +427,8 @@ vtkFFMPEGWriter::vtkFFMPEGWriter()
this->Internals = 0;
this->Quality = 2;
this->Rate = 25;
this->BitRate = 0;
this->BitRateTolerance = 0;
}
//---------------------------------------------------------------------------
......
......@@ -14,15 +14,15 @@
=========================================================================*/
// .NAME vtkFFMPEGWriter - Uses the FFMPEG library to write video files.
// .SECTION Description
// vtkFFMPEGWriter is an adapter that allows VTK to use the LGPL'd FFMPEG
// vtkFFMPEGWriter is an adapter that allows VTK to use the LGPL'd FFMPEG
// library to write movie files. FFMPEG can create a variety of multimedia
// file formats and can use a variety of encoding algorithms (codecs).
// This class creates .avi files containing MP43 encoded video without
// file formats and can use a variety of encoding algorithms (codecs).
// This class creates .avi files containing MP43 encoded video without
// audio.
//
// The FFMPEG multimedia library source code can be obtained from
//
// The FFMPEG multimedia library source code can be obtained from
// the sourceforge web site at http://ffmpeg.sourceforge.net/download.php
// or is a tarball along with installation instructions at
// or is a tarball along with installation instructions at
// http://www.vtk.org/files/support/ffmpeg_source.tar.gz
//
// .SECTION See Also vtkGenericMovieWriter vtkAVIWriter vtkMPEG2Writer
......@@ -59,6 +59,17 @@ public:
// Set/Get the frame rate, in frame/s.
vtkSetClampMacro(Rate, int , 1, 5000);
vtkGetMacro(Rate, int);
// Description:
// Set/Get the bit-rate
vtkSetMacro(BitRate, int);
vtkGetMacro(BitRate, int);
// Description:
// Set/Get the bit-rate tolerance
vtkSetMacro(BitRateTolerance, int);
vtkGetMacro(BitRateTolerance, int);
protected:
vtkFFMPEGWriter();
~vtkFFMPEGWriter();
......@@ -68,6 +79,8 @@ protected:
int Initialized;
int Quality;
int Rate;
int BitRate;
int BitRateTolerance;
private:
vtkFFMPEGWriter(const vtkFFMPEGWriter&); // Not implemented
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment