Commit 9b7f4a1c authored by Ken Martin's avatar Ken Martin

add ffmpegvideosource and test

Requires a compilation of ffmpeg and the test uses
a public domain vp9 test file
parent 9a850c75
......@@ -46,6 +46,12 @@ MACRO(FFMPEG_FIND varname shortname headername)
DOC "Location of FFMPEG Headers"
)
# on windows sometimes ffmpeg is built as lib<name>.a files
if (WIN32)
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a")
list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "lib")
endif()
FIND_LIBRARY(FFMPEG_${varname}_LIBRARIES
NAMES ${shortname}
PATHS
......@@ -107,6 +113,7 @@ FFMPEG_FIND(LIBAVFORMAT avformat avformat.h)
FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h)
FFMPEG_FIND(LIBAVCODEC avcodec avcodec.h)
FFMPEG_FIND(LIBAVUTIL avutil avutil.h)
FFMPEG_FIND(LIBSWRESAMPLE swresample swresample.h)
FFMPEG_FIND(LIBSWSCALE swscale swscale.h) # not sure about the header to look for here.
SET(FFMPEG_FOUND "NO")
......
......@@ -2,6 +2,7 @@ find_package(FFMPEG)
include(vtkTestFFMPEG)
set(Module_SRCS
vtkFFMPEGVideoSource.cxx
vtkFFMPEGWriter.cxx
)
......@@ -21,8 +22,11 @@ set_source_files_properties( vtkFFMPEGWriter.cxx
PROPERTIES COMPILE_DEFINITIONS __STDC_CONSTANT_MACROS
)
set(_ffmpeg_libs ${FFMPEG_LIBAVFORMAT_LIBRARIES} ${FFMPEG_LIBAVCODEC_LIBRARIES}
set(_ffmpeg_libs
${FFMPEG_LIBAVFORMAT_LIBRARIES}
${FFMPEG_LIBAVCODEC_LIBRARIES}
${FFMPEG_LIBAVUTIL_LIBRARIES}
${FFMPEG_LIBSWRESAMPLE_LIBRARIES}
)
if(NOT VTK_FFMPEG_HAS_IMG_CONVERT)
......
vtk_add_test_cxx(vtkIOFFMPEGCxxTests tests
NO_VALID
TestFFMPEGWriter.cxx
TestFFMPEGVideoSource.cxx
TestFFMPEGWriter.cxx,NO_VALID
)
vtk_test_cxx_executable(vtkIOFFMPEGCxxTests tests)
/*=========================================================================
Program: Visualization Toolkit
Module: TestFFMPEGVideoSource.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCamera.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkActor.h"
#include "vtkPolyDataMapper.h"
#include "vtkNew.h"
#include "vtkPlaneSource.h"
#include "vtkTexture.h"
#include "vtkRegressionTestImage.h"
#include "vtkTestUtilities.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkLookupTable.h"
#include "vtkFFMPEGVideoSource.h"
int TestFFMPEGVideoSource(int argc, char* argv[])
{
vtkNew<vtkActor> actor;
vtkNew<vtkRenderer> renderer;
vtkNew<vtkPolyDataMapper> mapper;
renderer->SetBackground(0.2, 0.3, 0.4);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(300, 300);
renderWindow->AddRenderer(renderer);
renderer->AddActor(actor);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow);
const char* fileName =
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/tracktor.webm");
vtkNew<vtkFFMPEGVideoSource> video;
video->SetFileName(fileName);
delete [] fileName;
vtkNew<vtkTexture> texture;
texture->SetInputConnection(video->GetOutputPort());
actor->SetTexture(texture);
vtkNew<vtkPlaneSource> plane;
mapper->SetInputConnection(plane->GetOutputPort());
actor->SetMapper(mapper);
video->Initialize();
int fsize[3];
video->GetFrameSize(fsize);
plane->SetOrigin(0,0,0);
plane->SetPoint1(fsize[0], 0, 0);
plane->SetPoint2(0, fsize[1], 0);
renderWindow->Render();
for (int i = 0; i < 10; ++i)
{
video->Grab();
renderWindow->Render();
}
int retVal = vtkRegressionTestImage( renderWindow );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
193862d2c8db823387b7a9b44f78788d28f8e7b0926b0335b36e6f4ea8beccdea5611c6e102ae712902c3e1f41db3e2341598b0d48d6e8597ca004ac167e5ded
......@@ -2,12 +2,18 @@ vtk_module(vtkIOFFMPEG
TEST_DEPENDS
vtkTestingCore
vtkImagingSources
vtkRenderingOpenGL2
vtkTestingRendering
vtkInteractionStyle
KIT
vtkIO
DEPENDS
vtkIOMovie
vtkIOVideo
PRIVATE_DEPENDS
vtkCommonCore
vtkCommonDataModel
vtkCommonMisc
)
\ No newline at end of file
vtkCommonSystem
vtksys
)
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFFMPEGVideoSource.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkFFMPEGVideoSource
* @brief Reader for ffmpeg supported formats
*
*
* @sa
* vtkVideoSource
*/
#ifndef vtkFFMPEGVideoSource_h
#define vtkFFMPEGVideoSource_h
#include "vtkIOFFMPEGModule.h" // For export macro
#include "vtkVideoSource.h"
#include "vtkMultiThreader.h" // for ivar
class vtkFFMPEGVideoSourceInternal;
class VTKIOFFMPEG_EXPORT vtkFFMPEGVideoSource : public vtkVideoSource
{
public:
static vtkFFMPEGVideoSource *New();
vtkTypeMacro(vtkFFMPEGVideoSource,vtkVideoSource);
/**
* Standard VCR functionality: Record incoming video.
*/
void Record() override;
/**
* Standard VCR functionality: Play recorded video.
*/
void Play() override;
/**
* Standard VCR functionality: Stop recording or playing.
*/
void Stop() override;
/**
* Grab a single video frame.
*/
void Grab() override;
//@{
/**
* Request a particular frame size (set the third value to 1).
*/
void SetFrameSize(int x, int y, int z) override;
void SetFrameSize(int dim[3]) override {
this->SetFrameSize(dim[0], dim[1], dim[2]); };
//@}
/**
* Request a particular frame rate (default 30 frames per second).
*/
void SetFrameRate(float rate) override;
/**
* Request a particular output format (default: VTK_RGB).
*/
void SetOutputFormat(int format) override;
/**
* Initialize the driver (this is called automatically when the
* first grab is done).
*/
void Initialize() override;
/**
* Free the driver (this is called automatically inside the
* destructor).
*/
void ReleaseSystemResources() override;
//@{
/**
* Specify file name of the video
*/
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
//@}
/**
* The internal function which actually does the grab. You will
* definitely want to override this if you develop a vtkVideoSource
* subclass.
*/
void InternalGrab() override;
protected:
vtkFFMPEGVideoSource();
~vtkFFMPEGVideoSource();
int DecodePacket(int *got_frame);
static void *RecordThread(
vtkMultiThreader::ThreadInfo *data);
vtkFFMPEGVideoSourceInternal *Internal;
char *FileName;
bool EndOfFile;
private:
vtkFFMPEGVideoSource(const vtkFFMPEGVideoSource&) = delete;
void operator=(const vtkFFMPEGVideoSource&) = delete;
};
#endif
......@@ -316,7 +316,7 @@ protected:
int Playing;
float FrameRate;
int FrameCount;
int FrameIndex;
double StartTimeStamp;
double FrameTimeStamp;
......@@ -349,7 +349,16 @@ protected:
int FrameBufferExtent[6];
int FrameBufferSize;
// where the current frame is, note this decreases in time
// increasing values are older frames
int FrameBufferIndex;
// number of frames from the beginning sort of,
// it does wrap, sometimes
int FrameIndex;
void **FrameBuffer;
double *FrameBufferTimeStamps;
......
45b7bbdfdb87b307511ae70aced6afbebcd10b494f18803feda8b385ef664c5b9db61b8a4782648b224e54bce5a0a8a298ba9b08724818022b07699b0e3ac35b
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