AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
VideoCapture.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17
18#ifndef AGXOSG_VIDEOCAPTURE_H
19#define AGXOSG_VIDEOCAPTURE_H
20
22#include <agxOSG/ImageCapture.h>
23#include <agxData/BinaryData.h>
24
25#if AGX_USE_FFMPEG()
26
27extern "C"
28{
30 #include <libavutil/opt.h>
31 #include <libavcodec/avcodec.h>
32 #include <libavutil/channel_layout.h>
33 #include <libavutil/common.h>
34 #include <libavutil/imgutils.h>
35 #include <libavutil/mathematics.h>
36 #include <libavutil/samplefmt.h>
37 #include <libswscale/swscale.h>
38 #include <libavformat/avformat.h>
40}
41
42namespace agxOSG
43{
44 AGX_DECLARE_POINTER_TYPES(VideoCapture);
45 class AGXOSG_EXPORT VideoCapture : public ImageCaptureBase
46 {
47 public:
48 class DrawCallback;
49
50 public:
51
52 VideoCapture(agx::UInt width, agx::UInt height, agx::UInt fps, agxSDK::Simulation *sim = nullptr);
53
54 void init(agx::UInt width, agx::UInt height, agx::UInt fps, AVCodecID codec);
55
56 typedef agx::Callback2<agx::UInt8 *, size_t> DataCallback;
57
58 void setDataCallback(DataCallback callback);
59
60 agxData::BinaryData *writeHeader();
61
62 void setFilename(const agx::String& filename);
63
64 agx::String getFilename() const;
65
66 void setMovieFPS(agx::UInt fps);
67
68 void finalizeMovie();
69
70 protected:
71 virtual ~VideoCapture();
72
73 private:
74
75 void finalize();
76
77 bool encode(AVFrame *frame);
78
79 virtual void writeImage(osg::Image *image, agx::Index index);
80 static int writePacket(void *opaque, uint8_t *buf, int buf_size);
81
82 private:
83 AVFormatContext * m_formatContext;
84 AVOutputFormat * m_format;
85 AVCodecContext * m_codecContext;
86 AVCodec * m_codec;
87 AVStream * m_stream;
88 AVFrame * m_frame;
89 SwsContext * m_swsContext;
90 DataCallback m_dataCallback;
91 unsigned char * m_fragmentBuffer;
92 FILE * m_file;
93 bool m_firstFrame;
94 bool m_writingHeader;
96 agx::String m_filename;
97 agx::UInt m_videoFPS;
98 };
99
100}
101
102
103#endif
104#endif /* AGXOSG_VIDEOCAPTURE_H */
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXOSG_EXPORT
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Templated callback with two arguments.
Definition: Callback.h:140
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
uint64_t UInt
Definition: Integer.h:27
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
UInt32 Index
Definition: Integer.h:44