AGX Dynamics  2.37.2.0
VideoFFMPEGPipeCapture.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 
18 #ifndef AGXOSG_VIDEOFFMPEGPIPECAPTURE_H
19 #define AGXOSG_VIDEOFFMPEGPIPECAPTURE_H
20 
21 #include <agxOSG/ImageCapture.h>
22 #include <agxOSG/ExternalProcess.h>
23 
24 typedef void *HANDLE;
25 
26 namespace agxOSG
27 {
36  {
37  public:
38  class DrawCallback;
39 
41  enum class OutputCodec : agx::UInt32
42  {
43  H264 = 0,
44  H264RGB = 1,
45  XVID = 2
46  };
47 
48  // Codec hashFunc
49  struct CodecHash
50  {
51  template <typename T>
53  {
54  return static_cast<agx::UInt32>(t);
55  }
56  };
57 
60  static CodecStringConversionMap OutputCodecStrings;
61 
62  public:
64 
70  VideoFFMPEGPipeCapture(agx::UInt width, agx::UInt height, agx::Real fps, agxSDK::Simulation *sim = nullptr);
71 
73  void init();
74 
76  void setFilename(const agx::String& filename);
77 
79  void setVideoPostFix(const agx::String& postFix);
80 
82  agx::String getVideoPostFix() const;
83 
85  agx::String getFilename() const;
86 
88  void setVideoFPS(agx::Real videoFPS);
89 
91  agx::Real getVideoFPS() const;
92 
94  void setVideoCRF(agx::UInt crf);
95 
97  agx::UInt getVideoCRF() const;
98 
100  void setImageCaptureFPS(agx::Real imageFPS);
101 
103  agx::Real getImageCaptureFPS();
104 
106  void setEnableLossless(bool enable);
107 
109  bool getEnableLossless() const;
110 
112  void setOutputVideoCodec(OutputCodec codec);
113 
115  OutputCodec getOutputCodec() const;
116 
118  bool hasActiveVideo() const;
119 
124  bool stopProcess();
125 
126  protected:
127  virtual ~VideoFFMPEGPipeCapture();
128 
129  void startExternalFFMPEGProcess();
130 
131  void closeExternalFFMPEGProcess();
132 
133  agx::String generatePipeName() const;
134 
135  agx::String getPipeName() const;
136 
137  agx::String getFFMPEGBinaryPath() const;
138 
139  agx::String getCompleteFileName() const;
140 
141  private:
142 
143  virtual void writeImage(osg::Image *image, agx::Index index);
144 
145  private:
146  agx::String m_filename;
147  agx::String m_videoPostFix;
148  agx::Real m_videoFPS;
149  agx::String m_pipeName;
150  OutputCodec m_outputCodec;
151  agx::UInt m_crf;
152  agx::UInt m_numWrittenFramesToPipe;
153  bool m_firstFrame;
154  bool m_enableLossless;
155 
156 #ifdef _MSC_VER
157  HANDLE hPipe;
158 #else
159  FILE* m_fifo;
160 #endif
161  agxOSG::ExternalProcessRef m_imageServerProcess;
162  };
163 }
164 
165 #endif /* AGXOSG_VideoFFMPEGPipeCapture_H */
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
void * HANDLE
#define AGXOSG_EXPORT
agx::HashTable< OutputCodec, agx::String, CodecHash > CodecStringConversionMap
Map for storing codec string conversion for FFMPEG.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
uint32_t UInt
Definition: Integer.h:34
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
UInt32 Index
Definition: Integer.h:52
static CodecStringConversionMap OutputCodecStrings
OutputCodec
Enum describing the different types of codecs that are available.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
uint32_t UInt32
Definition: Integer.h:40