Blender V5.0
movie_write.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#ifdef WITH_FFMPEG
12
13# include <cstdint>
14/* Note: include cmath before ffmpeg headers, since both of them define
15 * M_PI and other macros. This is to avoid warnings about macro redefinition
16 * if later including cmath (MSVC 2019). */
17# if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
18# define _USE_MATH_DEFINES
19# endif
20# include <cmath> // IWYU pragma: keep
21
22extern "C" {
23# include <libavcodec/codec_id.h>
24# include <libavformat/avformat.h>
25# include <libavutil/buffer.h>
26# include <libavutil/channel_layout.h>
27# include <libavutil/imgutils.h>
28# include <libavutil/mastering_display_metadata.h>
29# include <libavutil/opt.h>
30# include <libavutil/rational.h>
31# include <libavutil/samplefmt.h>
32
33# include "ffmpeg_compat.h"
34}
35
36# ifdef WITH_AUDASPACE
37# include <AUD_Types.h>
38# endif
39
40struct Scene;
41struct ReportList;
42struct StampData;
43
44struct MovieWriter {
45 int ffmpeg_type = 0;
46 AVCodecID ffmpeg_codec = {};
47 AVCodecID ffmpeg_audio_codec = {};
48 int ffmpeg_video_bitrate = 0;
49 int ffmpeg_audio_bitrate = 0;
50 int ffmpeg_gop_size = 0;
51 int ffmpeg_max_b_frames = 0;
52 int ffmpeg_autosplit_count = 0;
53 bool ffmpeg_autosplit = false;
54 bool ffmpeg_preview = false;
55
56 int ffmpeg_crf = 0; /* set to 0 to not use CRF mode; we have another flag for lossless anyway. */
57 int ffmpeg_preset = 0; /* see eFFMpegPreset */
58 int ffmpeg_profile = 0;
59
60 AVFormatContext *outfile = nullptr;
61 AVCodecContext *video_codec = nullptr;
62 AVCodecContext *audio_codec = nullptr;
63 AVStream *video_stream = nullptr;
64 AVStream *audio_stream = nullptr;
65 AVFrame *current_frame = nullptr; /* Image frame in output pixel format. */
66 int video_time = 0;
67
68 /* Image frame in Blender's own pixel format, may need conversion to the output pixel format. */
69 AVFrame *img_convert_frame = nullptr;
70 SwsContext *img_convert_ctx = nullptr;
71
72 uint8_t *audio_input_buffer = nullptr;
73 uint8_t *audio_deinterleave_buffer = nullptr;
74 int audio_input_samples = 0;
75 double audio_time = 0.0;
76 double audio_time_total = 0.0;
77 bool audio_deinterleave = false;
78 int audio_sample_size = 0;
79
80 StampData *stamp_data = nullptr;
81
82# ifdef WITH_AUDASPACE
83 AUD_Device *audio_mixdown_device = nullptr;
84# endif
85};
86
87bool movie_audio_open(MovieWriter *context,
88 const Scene *scene,
89 int start_frame,
90 int mixrate,
91 float volume,
92 ReportList *reports);
93void movie_audio_close(MovieWriter *context, bool is_autosplit);
94
95AVStream *alloc_audio_stream(MovieWriter *context,
96 int audio_mixrate,
97 int audio_channels,
98 AVCodecID codec_id,
99 AVFormatContext *of,
100 char *error,
101 int error_size);
102void write_audio_frames(MovieWriter *context, double to_pts);
103
104#endif /* WITH_FFMPEG */
static void error(const char *str)