Skip to content
0.2.0-dev Download ZIP
96 lines ·4.1 KB Raw
1/**************************************************************************/
2/* movie_writer.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#pragma once
32
33#include "core/io/image.h"
34#include "core/templates/local_vector.h"
35#include "servers/audio/audio_server.h" // IWYU pragma: keep. Bind GDVIRTUAL0RC_REQUIRED.
36#include "servers/audio/audio_server_enums.h"
37
38class MovieWriter : public Object {
39 GDCLASS(MovieWriter, Object);
40
41 uint64_t fps = 0;
42 uint64_t mix_rate = 0;
43 uint32_t audio_channels = 0;
44
45 // The output resolution, which can differ from the window size.
46 // Used as a base for resizing all subsequent frames if their resolution differs.
47 Vector2i movie_size;
48
49 float cpu_time = 0.0f;
50 float gpu_time = 0.0f;
51 uint64_t encoding_time_usec = 0;
52
53 String project_name;
54
55 LocalVector<int32_t> audio_mix_buffer;
56
57 enum {
58 MAX_WRITERS = 8
59 };
60 static MovieWriter *writers[];
61 static uint32_t writer_count;
62
63protected:
64 virtual uint32_t get_audio_mix_rate() const;
65 virtual AuSE::SpeakerMode get_audio_speaker_mode() const;
66
67 virtual Error write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path);
68 virtual Error write_frame(const Ref<Image> &p_image, const int32_t *p_audio_data);
69 virtual void write_end();
70
71 GDVIRTUAL0RC_REQUIRED(uint32_t, _get_audio_mix_rate)
72 GDVIRTUAL0RC_REQUIRED(AuSE::SpeakerMode, _get_audio_speaker_mode)
73
74 GDVIRTUAL1RC_REQUIRED(bool, _handles_file, const String &)
75 GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_supported_extensions)
76
77 GDVIRTUAL3R_REQUIRED(Error, _write_begin, const Size2i &, uint32_t, const String &)
78 GDVIRTUAL2R_REQUIRED(Error, _write_frame, const Ref<Image> &, GDExtensionPtr<const int32_t>)
79 GDVIRTUAL0_REQUIRED(_write_end)
80
81 static void _bind_methods();
82
83public:
84 virtual bool handles_file(const String &p_path) const;
85 virtual void get_supported_extensions(List<String> *r_extensions) const;
86
87 static void add_writer(MovieWriter *p_writer);
88 static MovieWriter *find_writer_for_file(const String &p_file);
89
90 void begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path);
91 void add_frame();
92
93 static void set_extensions_hint();
94
95 void end();
96};