move ffmpeg into its own class, Renderer can now create jobs when in clusterizer mode

This commit is contained in:
2025-02-24 00:52:10 +01:00
parent 31358ff2c9
commit fcc6f8266b
13 changed files with 268 additions and 133 deletions

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */
/* Updated: 2025/02/21 14:53:36 by tomoron ### ########.fr */
/* Updated: 2025/02/23 23:39:46 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -77,6 +77,7 @@ struct Vertex {
# include "ObjParser.hpp"
# include "BVH.hpp"
# include "Clusterizer.hpp"
# include "Ffmpeg.hpp"

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/20 18:25:18 by tomoron #+# #+# */
/* Updated: 2025/02/22 23:36:23 by tomoron ### ########.fr */
/* Updated: 2025/02/23 22:41:25 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -61,10 +61,16 @@ class Clusterizer
void update(void);
bool getError(void);
void imguiRender(void);
bool isServer(void);
bool hasJobs(void);
void addJob(glm::vec3 pos, glm::vec2 dir, size_t samples);
private:
bool _isActive;
bool _isServer;
bool _error;
std::string _sceneName;
std::vector<t_job *> _jobs[3];
@ -94,7 +100,6 @@ class Clusterizer
void updatePollfds(void);
int updateBuffer(int fd);
void handleBuffer(int fd, std::vector<uint8_t> &buf);
void addJob(std::string scene, glm::vec3 pos, glm::vec2 dir, size_t samples);
void deleteClient(int fd);
int dispatchJobs(void);

44
includes/RT/Ffmpeg.hpp Normal file
View File

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Ffmpeg.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/23 23:41:18 by tomoron #+# #+# */
/* Updated: 2025/02/24 00:41:00 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FFMPEG_HPP
# define FFMPEG_HPP
#include "RT.hpp"
class Ffmpeg
{
public:
Ffmpeg(std::string filename, int fps, const AVCodec *codec);
~Ffmpeg();
void addImageToVideo(Scene &scene, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
static void updateAvailableCodecs(std::vector<const AVCodec *> &codecList, std::vector<const char *> &codecListStr, std::string filename, int mode, AVCodecID id);
private:
void convertAndAddToVid(void);
void endVideo(void);
static void fillGoodCodecList(std::vector<AVCodecID> &lst);
int64_t _pts;
AVFormatContext *_format;
AVCodecContext *_codec_context;
AVFrame *_rgb_frame;
AVFrame *_yuv_frame;
SwsContext *_sws_context;
AVStream *_stream;
AVDictionary *_codecOptions;
};
#endif

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
/* Updated: 2025/02/20 15:57:21 by tomoron ### ########.fr */
/* Updated: 2025/02/24 00:32:38 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
# define RENDERER_HPP
# include "RT.hpp"
extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
@ -26,6 +27,8 @@ class Scene;
class Window;
class Shader;
class ShaderProgram;
class Clusterizer;
class Ffmpeg;
typedef struct s_pathPoint
{
@ -41,7 +44,7 @@ class Renderer
void update(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void addTeleport(glm::vec3 from_pos, glm::vec2 from_dir, glm::vec3 to_pos, glm::vec2 to_dir);
void renderImgui(void);
void renderImgui(Clusterizer &clust);
int rendering(void) const;
bool shouldClose(void) const;
@ -54,7 +57,7 @@ class Renderer
float calcTime(glm::vec3 pos);
void addPoint(float time);
void imguiRenderSettings(void);
void imguiRenderSettings(Clusterizer &clust);
void imguiPathCreation(void);
void imguiPathNodeList(void);
@ -62,15 +65,16 @@ class Renderer
void savePath(void);
void loadPath(std::string filename);
void makeMovement(float timeFromStart, float curSplitTimeReset);
void makeMovement(float time);
void interpolateMovement(float time, glm::vec3 *pos, glm::vec2 *dir);
glm::vec2 bezierSphereInterpolate(glm::vec4 control, glm::vec2 from, glm::vec2 to, float time);
glm::vec3 hermiteInterpolate(glm::vec3 points[4], double alpha);
t_pathPoint createNextPoint(t_pathPoint from, t_pathPoint to);
void getInterpolationPoints(t_pathPoint &prev, t_pathPoint &from, t_pathPoint &to, t_pathPoint &next);
void initRender();
void createClusterJobs(Clusterizer &clust);
void fillGoodCodecList(std::vector<AVCodecID> &lst);
void updateAvailableCodecs(int mode, AVCodecID id);
void addImageToRender(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void endRender(void);
@ -82,9 +86,9 @@ class Renderer
std::string _outputFilename;
std::vector<t_pathPoint> _path;
int _curPathIndex;
int _destPathIndex;
double _curSplitStart;
size_t _curPathIndex;
size_t _destPathIndex;
double _testStartTime;
int _curSamples;
int _testMode;
long int _frameCount;
@ -105,16 +109,8 @@ class Renderer
int _codecIndex;
bool _renderSettings;
AVFormatContext *_format;
AVCodecContext *_codec_context;
AVFrame *_rgb_frame;
AVFrame *_yuv_frame;
SwsContext *_sws_context;
AVStream *_stream;
AVDictionary *_codecOptions;
std::vector<const AVCodec *> _codecList;
Ffmpeg *_ffmpegVideo;
};
#endif