Path: blob/master/modules/theora/editor/movie_writer_ogv.h
10278 views
/**************************************************************************/1/* movie_writer_ogv.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "servers/audio_server.h"33#include "servers/movie_writer/movie_writer.h"3435#include <theora/theoraenc.h>36#include <vorbis/codec.h>37#include <vorbis/vorbisenc.h>3839class MovieWriterOGV : public MovieWriter {40GDCLASS(MovieWriterOGV, MovieWriter)4142uint32_t mix_rate = 48000;43AudioServer::SpeakerMode speaker_mode = AudioServer::SPEAKER_MODE_STEREO;44String base_path;45uint32_t frame_count = 0;46uint32_t fps = 0;47uint32_t audio_ch = 0;48uint32_t audio_frames = 0;4950Ref<FileAccess> f;5152// Vorbis quality -0.1 to 1 (-0.1 yields smallest files but lowest fidelity; 1 yields highest fidelity but large files. '0.2' is a reasonable default).53float audio_quality = 0.5;5455// Bitrate target for Theora video.56int video_bitrate = 0;5758// Theora quality selector from 0 to 1.0 (0 yields smallest files but lowest video quality. 1.0 yields highest fidelity but large files).59float video_quality = 0.75;6061// Video stream keyframe frequency (one every N frames).62ogg_uint32_t keyframe_frequency = 64;6364// Sets the encoder speed level. Higher speed levels favor quicker encoding over better quality per bit. Depending on the encoding65// mode, and the internal algorithms used, quality may actually improve with higher speeds, but in this case bitrate will also66// likely increase. The maximum value, and the meaning of each value, are implementation-specific and may change depending on the67// current encoding mode.68int speed = 4;6970// Take physical pages, weld into a logical stream of packets.71ogg_stream_state to;7273// Take physical pages, weld into a logical stream of packets.74ogg_stream_state vo;7576// Theora encoding context.77th_enc_ctx *td;7879// Theora bitstream information.80th_info ti;8182// Theora comment information.83th_comment tc;8485// Vorbis bitstream information.86vorbis_info vi;8788// Vorbis comment information.89vorbis_comment vc;9091// Central working state for the packet->PCM decoder.92vorbis_dsp_state vd;9394// Local working space for packet->PCM decode.95vorbis_block vb;9697// Video buffer.98uint8_t *y, *u, *v;99th_ycbcr_buffer ycbcr;100101bool audio_flag = false;102bool video_flag = false;103ogg_page audio_page;104ogg_page video_page;105ogg_page backup_page;106unsigned int backup_page_size = 0;107unsigned char *backup_page_data = nullptr;108109void write_to_file(bool p_finish = false);110void push_audio(const int32_t *p_audio_data);111void push_video(const Ref<Image> &p_image);112void pull_audio(bool p_last = false);113void pull_video(bool p_last = false);114void save_page(ogg_page page);115void restore_page(ogg_page *page);116117inline int ilog(unsigned _v) {118int ret;119for (ret = 0; _v; ret++) {120_v >>= 1;121}122return ret;123}124125protected:126virtual uint32_t get_audio_mix_rate() const override;127virtual AudioServer::SpeakerMode get_audio_speaker_mode() const override;128virtual void get_supported_extensions(List<String> *r_extensions) const override;129130virtual Error write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path) override;131virtual Error write_frame(const Ref<Image> &p_image, const int32_t *p_audio_data) override;132virtual void write_end() override;133134virtual bool handles_file(const String &p_path) const override;135136public:137MovieWriterOGV();138};139140141