summaryrefslogtreecommitdiff
path: root/servers/movie_writer/movie_writer.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-06-30 01:31:08 +0200
committerGitHub <noreply@github.com>2022-06-30 01:31:08 +0200
commitce6c4ab86a8b8b2f381f91dd8f91f36e37f4f799 (patch)
tree0918c2cc313455b21858f6b5edf2f1f894580182 /servers/movie_writer/movie_writer.cpp
parent047cdc9a9f5ec4c0d098f04c8a9eb727f1cef318 (diff)
parentaa177fc4db953a34d1db62654c80e25415076931 (diff)
Merge pull request #62538 from Calinou/movie-writer-split-pngwav
Split MovieWriterPNGWAV into its own file
Diffstat (limited to 'servers/movie_writer/movie_writer.cpp')
-rw-r--r--servers/movie_writer/movie_writer.cpp137
1 files changed, 0 insertions, 137 deletions
diff --git a/servers/movie_writer/movie_writer.cpp b/servers/movie_writer/movie_writer.cpp
index 8560d92aa2..9f96b8cfda 100644
--- a/servers/movie_writer/movie_writer.cpp
+++ b/servers/movie_writer/movie_writer.cpp
@@ -30,7 +30,6 @@
#include "movie_writer.h"
#include "core/config/project_settings.h"
-#include "core/io/dir_access.h"
MovieWriter *MovieWriter::writers[MovieWriter::MAX_WRITERS];
uint32_t MovieWriter::writer_count = 0;
@@ -170,139 +169,3 @@ void MovieWriter::add_frame(const Ref<Image> &p_image) {
void MovieWriter::end() {
write_end();
}
-/////////////////////////////////////////
-
-uint32_t MovieWriterPNGWAV::get_audio_mix_rate() const {
- return mix_rate;
-}
-AudioServer::SpeakerMode MovieWriterPNGWAV::get_audio_speaker_mode() const {
- return speaker_mode;
-}
-
-void MovieWriterPNGWAV::get_supported_extensions(List<String> *r_extensions) const {
- r_extensions->push_back("png");
-}
-
-bool MovieWriterPNGWAV::handles_file(const String &p_path) const {
- return p_path.get_extension().to_lower() == "png";
-}
-
-String MovieWriterPNGWAV::zeros_str(uint32_t p_index) {
- char zeros[MAX_TRAILING_ZEROS + 1];
- for (uint32_t i = 0; i < MAX_TRAILING_ZEROS; i++) {
- uint32_t idx = MAX_TRAILING_ZEROS - i - 1;
- uint32_t digit = (p_index / uint32_t(Math::pow(double(10), double(idx)))) % 10;
- zeros[i] = '0' + digit;
- }
- zeros[MAX_TRAILING_ZEROS] = 0;
- return zeros;
-}
-
-Error MovieWriterPNGWAV::write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path) {
- // Quick & Dirty PNGWAV Code based on - https://docs.microsoft.com/en-us/windows/win32/directshow/avi-riff-file-reference
-
- base_path = p_base_path.get_basename();
- if (base_path.is_relative_path()) {
- base_path = "res://" + base_path;
- }
-
- {
- //Remove existing files before writing anew
- uint32_t idx = 0;
- Ref<DirAccess> d = DirAccess::open(base_path.get_base_dir());
- String file = base_path.get_file();
- while (true) {
- String path = file + zeros_str(idx) + ".png";
- if (d->remove(path) != OK) {
- break;
- }
- }
- }
-
- f_wav = FileAccess::open(base_path + ".wav", FileAccess::WRITE_READ);
- ERR_FAIL_COND_V(f_wav.is_null(), ERR_CANT_OPEN);
-
- fps = p_fps;
-
- f_wav->store_buffer((const uint8_t *)"RIFF", 4);
- int total_size = 4 /* WAVE */ + 8 /* fmt+size */ + 16 /* format */ + 8 /* data+size */;
- f_wav->store_32(total_size); //will store final later
- f_wav->store_buffer((const uint8_t *)"WAVE", 4);
-
- /* FORMAT CHUNK */
-
- f_wav->store_buffer((const uint8_t *)"fmt ", 4);
-
- uint32_t channels = 2;
- switch (speaker_mode) {
- case AudioServer::SPEAKER_MODE_STEREO:
- channels = 2;
- break;
- case AudioServer::SPEAKER_SURROUND_31:
- channels = 4;
- break;
- case AudioServer::SPEAKER_SURROUND_51:
- channels = 6;
- break;
- case AudioServer::SPEAKER_SURROUND_71:
- channels = 8;
- break;
- }
-
- f_wav->store_32(16); //standard format, no extra fields
- f_wav->store_16(1); // compression code, standard PCM
- f_wav->store_16(channels); //CHANNELS: 2
-
- f_wav->store_32(mix_rate);
-
- /* useless stuff the format asks for */
-
- int bits_per_sample = 32;
- int blockalign = bits_per_sample / 8 * channels;
- int bytes_per_sec = mix_rate * blockalign;
-
- audio_block_size = (mix_rate / fps) * blockalign;
-
- f_wav->store_32(bytes_per_sec);
- f_wav->store_16(blockalign); // block align (unused)
- f_wav->store_16(bits_per_sample);
-
- /* DATA CHUNK */
-
- f_wav->store_buffer((const uint8_t *)"data", 4);
-
- f_wav->store_32(0); //data size... wooh
- wav_data_size_pos = f_wav->get_position();
-
- return OK;
-}
-
-Error MovieWriterPNGWAV::write_frame(const Ref<Image> &p_image, const int32_t *p_audio_data) {
- ERR_FAIL_COND_V(!f_wav.is_valid(), ERR_UNCONFIGURED);
-
- Vector<uint8_t> png_buffer = p_image->save_png_to_buffer();
-
- Ref<FileAccess> fi = FileAccess::open(base_path + zeros_str(frame_count) + ".png", FileAccess::WRITE);
- fi->store_buffer(png_buffer.ptr(), png_buffer.size());
- f_wav->store_buffer((const uint8_t *)p_audio_data, audio_block_size);
-
- frame_count++;
-
- return OK;
-}
-
-void MovieWriterPNGWAV::write_end() {
- if (f_wav.is_valid()) {
- uint32_t total_size = 4 /* WAVE */ + 8 /* fmt+size */ + 16 /* format */ + 8 /* data+size */;
- uint32_t datasize = f_wav->get_position() - wav_data_size_pos;
- f_wav->seek(4);
- f_wav->store_32(total_size + datasize);
- f_wav->seek(0x28);
- f_wav->store_32(datasize);
- }
-}
-
-MovieWriterPNGWAV::MovieWriterPNGWAV() {
- mix_rate = GLOBAL_GET("editor/movie_writer/mix_rate");
- speaker_mode = AudioServer::SpeakerMode(int(GLOBAL_GET("editor/movie_writer/speaker_mode")));
-}