AGX Dynamics  2.38.0.2
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 
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 */
agxOSG::VideoFFMPEGPipeCapture::CodecHash
Definition: VideoFFMPEGPipeCapture.h:49
agx::UInt
uint64_t UInt
Definition: Integer.h:27
agx::Real
double Real
Definition: Real.h:42
agxOSG::VideoFFMPEGPipeCapture::CodecStringConversionMap
agx::HashTable< OutputCodec, agx::String, CodecHash > CodecStringConversionMap
Map for storing codec string conversion for FFMPEG.
Definition: VideoFFMPEGPipeCapture.h:59
agx::ref_ptr< ExternalProcess >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
ExternalProcess.h
agx::Index
UInt32 Index
Definition: Integer.h:44
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:926
agxOSG::ImageCaptureBase
Definition: ImageCapture.h:41
agxOSG::VideoFFMPEGPipeCapture::OutputCodec
OutputCodec
Enum describing the different types of codecs that are available.
Definition: VideoFFMPEGPipeCapture.h:41
agxOSG::VideoFFMPEGPipeCapture::OutputCodecStrings
static CodecStringConversionMap OutputCodecStrings
Definition: VideoFFMPEGPipeCapture.h:60
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::AgXString< std::string >
HANDLE
void * HANDLE
Definition: VideoFFMPEGPipeCapture.h:24
agx::init
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
agxOSG::VideoFFMPEGPipeCapture::CodecHash::operator()
agx::UInt32 operator()(T t) const
Definition: VideoFFMPEGPipeCapture.h:52
ImageCapture.h
agx::UInt32
uint32_t UInt32
Definition: Integer.h:32
AGXOSG_EXPORT
#define AGXOSG_EXPORT
agxOSG::VideoFFMPEGPipeCapture
Definition: VideoFFMPEGPipeCapture.h:35