Torque3D Documentation / _generateds / videoEncoderPNG.cpp

videoEncoderPNG.cpp

Engine/source/gfx/video/videoEncoderPNG.cpp

More...

Classes:

class

This is a very basic "encoder" that records the video as a series of numbered PNGs Good if you're having problems with container-based formats and need extra flexibility.

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#include "videoCapture.h"
25#include "core/stream/fileStream.h"
26#include "console/console.h"
27#include "gfx/bitmap/gBitmap.h"
28
29/// This is a very basic "encoder" that records the video as a series of numbered PNGs
30/// Good if you're having problems with container-based formats and need extra flexibility.
31class VideoEncoderPNG : public VideoEncoder
32{
33   U32 mCurrentFrame;
34
35public:
36   /// Begins accepting frames for encoding
37   bool begin()
38   {
39      mPath += "\\";
40      mCurrentFrame = 0;
41
42      return true;
43   }
44
45   /// Pushes a new frame into the video stream
46   bool pushFrame( GBitmap * bitmap )
47   {
48      FileStream fs;
49      String framePath = mPath + String::ToString("%.6u.png", mCurrentFrame);
50      if ( !fs.open( framePath, Torque::FS::File::Write ) )
51      {
52         Con::errorf( "VideoEncoderPNG::pushFrame() - Failed to open output file '%s'!", framePath.c_str() );
53         return false;
54      }
55
56      //Increment
57      mCurrentFrame++;
58
59      bool result = bitmap->writeBitmap("png", fs, 0);
60      pushProcessedBitmap(bitmap);
61 
62      return result;
63   }
64
65   /// Finishes the encoding and closes the video
66   bool end()
67   {
68      return true;
69   }
70
71   void setResolution( Point2I* resolution ) 
72   {      
73      mResolution = *resolution; 
74   }
75};
76
77REGISTER_VIDEO_ENCODER(VideoEncoderPNG, PNG)
78