Blender V5.3
movie_util.cc
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#include "BLI_map.hh"
10#include "BLI_mutex.hh"
11#include "BLI_path_utils.hh"
12#include "BLI_threads.hh"
13#include "BLI_utildefines.hh"
14
15#include "CLG_log.h"
16#include "DNA_scene_types.h"
17
18#include "MOV_enums.hh"
19#include "MOV_util.hh"
20
21#include "ffmpeg_swscale.hh"
22#include "movie_util.hh"
23#include <mutex>
24
25#ifdef WITH_FFMPEG
26# include "BLI_string.hh"
27
28extern "C" {
29# include "ffmpeg_compat.h"
30# include <libavcodec/avcodec.h>
31# include <libavdevice/avdevice.h>
32# include <libavformat/avformat.h>
33# include <libavutil/hwcontext.h>
34# include <libavutil/log.h>
35}
36#endif
37
38namespace blender {
39
40#ifdef WITH_FFMPEG
41
42static CLG_LogRef LOG = {"video.ffmpeg"};
43
44static char ffmpeg_last_error_buffer[1024];
45
46/* BLI_vsnprintf in ffmpeg_log_callback() causes invalid warning */
47# ifdef __GNUC__
48# pragma GCC diagnostic push
49# pragma GCC diagnostic ignored "-Wmissing-format-attribute"
50# endif
51
52static size_t ffmpeg_log_to_buffer(char *buffer,
53 const size_t buffer_maxncpy,
54 const char *format,
55 va_list arg)
56{
57 va_list args_cpy;
58 size_t n;
59
60 va_copy(args_cpy, arg);
61 n = BLI_vsnprintf(buffer, buffer_maxncpy, format, args_cpy);
62 va_end(args_cpy);
63
64 return n;
65}
66
67static void ffmpeg_log_callback(void * /*ptr*/, int level, const char *format, va_list arg)
68{
69 CLG_Level clg_level;
70
71 switch (level) {
72 case AV_LOG_PANIC:
73 case AV_LOG_FATAL:
74 /* ffmpeg "fatal" should not quit whole Blender; report as error. */
75 clg_level = CLG_LEVEL_ERROR;
76 break;
77 case AV_LOG_ERROR:
78 case AV_LOG_WARNING:
79 case AV_LOG_INFO:
80 /* Note: most ffmpeg internal errors/warnings are not actionable; treat them as "info"
81 * log level. */
82 clg_level = CLG_LEVEL_INFO;
83 break;
84 case AV_LOG_VERBOSE:
85 case AV_LOG_DEBUG:
86 clg_level = CLG_LEVEL_DEBUG;
87 break;
88 case AV_LOG_TRACE:
89 default:
90 clg_level = CLG_LEVEL_TRACE;
91 break;
92 }
93
94 static std::mutex mutex;
95 std::scoped_lock lock(mutex);
96
97 if (ELEM(level, AV_LOG_PANIC, AV_LOG_FATAL, AV_LOG_ERROR)) {
98 const size_t n = ffmpeg_log_to_buffer(
99 ffmpeg_last_error_buffer, sizeof(ffmpeg_last_error_buffer), format, arg);
100 /* Strip trailing \n. */
101 ffmpeg_last_error_buffer[n - 1] = '\0';
102 }
103
104 if (CLOG_CHECK(&LOG, clg_level)) {
105 /* FFmpeg calls this multiple times without a line ending, so accumulate until
106 * we reach a line ending. This will not work well with multithreading, but the
107 * output would be garbled either way. */
108 static char buffer[1024];
109 static int buffer_used = 0;
110
111 buffer_used += ffmpeg_log_to_buffer(
112 buffer + buffer_used, sizeof(buffer) - buffer_used, format, arg);
113
114 if (buffer_used >= sizeof(buffer) || (buffer_used > 0 && buffer[buffer_used - 1] == '\n')) {
115 if (buffer[buffer_used - 1] == '\n') {
116 buffer[buffer_used - 1] = '\0';
117 }
118 CLOG_STR_AT_LEVEL(&LOG, clg_level, buffer);
119 buffer_used = 0;
120 }
121 }
122}
123
124# ifdef __GNUC__
125# pragma GCC diagnostic pop
126# endif
127
128const char *ffmpeg_last_error()
129{
130 return ffmpeg_last_error_buffer;
131}
132
133static bool ffmpeg_container_has_real_video(const AVFormatContext *format_ctx)
134{
135 for (int i = 0; i < format_ctx->nb_streams; i++) {
136 const AVStream *stream = format_ctx->streams[i];
137 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
138 (stream->disposition & AV_DISPOSITION_ATTACHED_PIC) == 0)
139 {
140 return true;
141 }
142 }
143 return false;
144}
145
146bool ffmpeg_stream_counts_as_video(const AVFormatContext *format_ctx, const AVStream *stream)
147{
148 if (stream->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
149 return false;
150 }
151 if ((stream->disposition & AV_DISPOSITION_ATTACHED_PIC) == 0) {
152 return true;
153 }
154 return !ffmpeg_container_has_real_video(format_ctx);
155}
156
157static int isffmpeg(const char *filepath)
158{
159 AVFormatContext *pFormatCtx = nullptr;
160 uint i;
161 int videoStream;
162 const AVCodec *pCodec;
163
164 if (BLI_path_extension_check_n(filepath,
165 ".swf",
166 ".jpg",
167 ".jp2",
168 ".j2c",
169 ".png",
170 ".dds",
171 ".tga",
172 ".bmp",
173 ".tif",
174 ".exr",
175 ".cin",
176 ".wav",
177 nullptr))
178 {
179 return 0;
180 }
181
182 if (avformat_open_input(&pFormatCtx, filepath, nullptr, nullptr) != 0) {
183 return 0;
184 }
185
186 if (avformat_find_stream_info(pFormatCtx, nullptr) < 0) {
187 avformat_close_input(&pFormatCtx);
188 return 0;
189 }
190
191 /* Find the first video stream */
192 videoStream = -1;
193 for (i = 0; i < pFormatCtx->nb_streams; i++) {
194 if (pFormatCtx->streams[i] && pFormatCtx->streams[i]->codecpar &&
195 (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO))
196 {
197 videoStream = i;
198 break;
199 }
200 }
201
202 if (videoStream == -1) {
203 avformat_close_input(&pFormatCtx);
204 return 0;
205 }
206
207 AVCodecParameters *codec_par = pFormatCtx->streams[videoStream]->codecpar;
208
209 /* Find the decoder for the video stream */
210 pCodec = avcodec_find_decoder(codec_par->codec_id);
211 if (pCodec == nullptr) {
212 avformat_close_input(&pFormatCtx);
213 return 0;
214 }
215
216 avformat_close_input(&pFormatCtx);
217
218 return 1;
219}
220
221/* -------------------------------------------------------------------- */
222/* AVFrame de-interlacing. Code for this was originally based on FFMPEG 2.6.4 (LGPL). */
223
224# define MAX_NEG_CROP 1024
225
226# define times4(x) x, x, x, x
227# define times256(x) times4(times4(times4(times4(times4(x)))))
228
229static const uint8_t ff_compat_crop_tab[256 + 2 * MAX_NEG_CROP] = {
230 times256(0x00), 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
231 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
232 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
233 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E,
234 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
235 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
236 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
237 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E,
238 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A,
239 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
240 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82,
241 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E,
242 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A,
243 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
244 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2,
245 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE,
246 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA,
247 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
248 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE0, 0xE1, 0xE2,
249 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE,
250 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA,
251 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, times256(0xFF)};
252
253# undef times4
254# undef times256
255
256/* filter parameters: [-1 4 2 4 -1] // 8 */
257FFMPEG_INLINE void deinterlace_line(uint8_t *dst,
258 const uint8_t *lum_m4,
259 const uint8_t *lum_m3,
260 const uint8_t *lum_m2,
261 const uint8_t *lum_m1,
262 const uint8_t *lum,
263 int size)
264{
265 const uint8_t *cm = ff_compat_crop_tab + MAX_NEG_CROP;
266 int sum;
267
268 for (; size > 0; size--) {
269 sum = -lum_m4[0];
270 sum += lum_m3[0] << 2;
271 sum += lum_m2[0] << 1;
272 sum += lum_m1[0] << 2;
273 sum += -lum[0];
274 dst[0] = cm[(sum + 4) >> 3];
275 lum_m4++;
276 lum_m3++;
277 lum_m2++;
278 lum_m1++;
279 lum++;
280 dst++;
281 }
282}
283
284FFMPEG_INLINE void deinterlace_line_inplace(
285 uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum, int size)
286{
287 const uint8_t *cm = ff_compat_crop_tab + MAX_NEG_CROP;
288 int sum;
289
290 for (; size > 0; size--) {
291 sum = -lum_m4[0];
292 sum += lum_m3[0] << 2;
293 sum += lum_m2[0] << 1;
294 lum_m4[0] = lum_m2[0];
295 sum += lum_m1[0] << 2;
296 sum += -lum[0];
297 lum_m2[0] = cm[(sum + 4) >> 3];
298 lum_m4++;
299 lum_m3++;
300 lum_m2++;
301 lum_m1++;
302 lum++;
303 }
304}
305
310FFMPEG_INLINE void deinterlace_bottom_field(
311 uint8_t *dst, int dst_wrap, const uint8_t *src1, int src_wrap, int width, int height)
312{
313 const uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
314 int y;
315
316 src_m2 = src1;
317 src_m1 = src1;
318 src_0 = &src_m1[src_wrap];
319 src_p1 = &src_0[src_wrap];
320 src_p2 = &src_p1[src_wrap];
321 for (y = 0; y < (height - 2); y += 2) {
322 memcpy(dst, src_m1, width);
323 dst += dst_wrap;
324 deinterlace_line(dst, src_m2, src_m1, src_0, src_p1, src_p2, width);
325 src_m2 = src_0;
326 src_m1 = src_p1;
327 src_0 = src_p2;
328 src_p1 += 2 * src_wrap;
329 src_p2 += 2 * src_wrap;
330 dst += dst_wrap;
331 }
332 memcpy(dst, src_m1, width);
333 dst += dst_wrap;
334 /* do last line */
335 deinterlace_line(dst, src_m2, src_m1, src_0, src_0, src_0, width);
336}
337
338FFMPEG_INLINE int deinterlace_bottom_field_inplace(uint8_t *src1,
339 int src_wrap,
340 int width,
341 int height)
342{
343 uint8_t *src_m1, *src_0, *src_p1, *src_p2;
344 int y;
345 uint8_t *buf = (uint8_t *)av_malloc(width);
346 if (!buf) {
347 return AVERROR(ENOMEM);
348 }
349
350 src_m1 = src1;
351 memcpy(buf, src_m1, width);
352 src_0 = &src_m1[src_wrap];
353 src_p1 = &src_0[src_wrap];
354 src_p2 = &src_p1[src_wrap];
355 for (y = 0; y < (height - 2); y += 2) {
356 deinterlace_line_inplace(buf, src_m1, src_0, src_p1, src_p2, width);
357 src_m1 = src_p1;
358 src_0 = src_p2;
359 src_p1 += 2 * src_wrap;
360 src_p2 += 2 * src_wrap;
361 }
362 /* do last line */
363 deinterlace_line_inplace(buf, src_m1, src_0, src_0, src_0, width);
364 av_free(buf);
365 return 0;
366}
367
368int ffmpeg_deinterlace(
369 AVFrame *dst, const AVFrame *src, enum AVPixelFormat pix_fmt, int width, int height)
370{
371 int i, ret;
372
373 if (!ELEM(pix_fmt,
374 AV_PIX_FMT_YUV420P,
375 AV_PIX_FMT_YUVJ420P,
376 AV_PIX_FMT_YUV422P,
377 AV_PIX_FMT_YUVJ422P,
378 AV_PIX_FMT_YUV444P,
379 AV_PIX_FMT_YUV411P,
380 AV_PIX_FMT_GRAY8))
381 {
382 return -1;
383 }
384 if ((width & 3) != 0 || (height & 3) != 0) {
385 return -1;
386 }
387
388 for (i = 0; i < 3; i++) {
389 if (i == 1) {
390 switch (pix_fmt) {
391 case AV_PIX_FMT_YUVJ420P:
392 case AV_PIX_FMT_YUV420P:
393 width >>= 1;
394 height >>= 1;
395 break;
396 case AV_PIX_FMT_YUV422P:
397 case AV_PIX_FMT_YUVJ422P:
398 width >>= 1;
399 break;
400 case AV_PIX_FMT_YUV411P:
401 width >>= 2;
402 break;
403 default:
404 break;
405 }
406 if (pix_fmt == AV_PIX_FMT_GRAY8) {
407 break;
408 }
409 }
410 if (src == dst) {
411 ret = deinterlace_bottom_field_inplace(dst->data[i], dst->linesize[i], width, height);
412 if (ret < 0) {
413 return ret;
414 }
415 }
416 else {
417 deinterlace_bottom_field(
418 dst->data[i], dst->linesize[i], src->data[i], src->linesize[i], width, height);
419 }
420 }
421 return 0;
422}
423
424AVCodecID mov_av_codec_id_get(IMB_Ffmpeg_Codec_ID id)
425{
426 switch (id) {
428 return AV_CODEC_ID_NONE;
430 return AV_CODEC_ID_MPEG1VIDEO;
432 return AV_CODEC_ID_MPEG2VIDEO;
434 return AV_CODEC_ID_MPEG4;
436 return AV_CODEC_ID_FLV1;
438 return AV_CODEC_ID_DVVIDEO;
440 return AV_CODEC_ID_HUFFYUV;
442 return AV_CODEC_ID_H264;
444 return AV_CODEC_ID_THEORA;
446 return AV_CODEC_ID_FFV1;
448 return AV_CODEC_ID_QTRLE;
450 return AV_CODEC_ID_PNG;
452 return AV_CODEC_ID_DNXHD;
454 return AV_CODEC_ID_VP9;
456 return AV_CODEC_ID_H265;
458 return AV_CODEC_ID_AV1;
460 return AV_CODEC_ID_PRORES;
462 return AV_CODEC_ID_PCM_S16LE;
464 return AV_CODEC_ID_MP2;
466 return AV_CODEC_ID_MP3;
468 return AV_CODEC_ID_AAC;
470 return AV_CODEC_ID_AC3;
472 return AV_CODEC_ID_VORBIS;
474 return AV_CODEC_ID_FLAC;
476 return AV_CODEC_ID_OPUS;
477 }
478
480 return AV_CODEC_ID_NONE;
481}
482
483static void ffmpeg_preset_set(RenderData *rd, int preset)
484{
485 bool is_ntsc = (rd->frs_sec != 25);
486
487 switch (preset) {
489 rd->ffcodecdata.type = FFMPEG_AVI;
490 rd->ffcodecdata.codec_id_set(FFMPEG_CODEC_ID_H264);
491 rd->ffcodecdata.video_bitrate = 6000;
492 rd->ffcodecdata.gop_size = is_ntsc ? 18 : 15;
493 rd->ffcodecdata.rc_max_rate = 9000;
494 rd->ffcodecdata.rc_min_rate = 0;
495 rd->ffcodecdata.rc_buffer_size = 224 * 8;
496 rd->ffcodecdata.mux_packet_size = 2048;
497 rd->ffcodecdata.mux_rate = 10080000;
498 break;
499
502 if (preset == FFMPEG_PRESET_XVID) {
503 rd->ffcodecdata.type = FFMPEG_AVI;
504 rd->ffcodecdata.codec_id_set(FFMPEG_CODEC_ID_MPEG4);
505 }
506 else if (preset == FFMPEG_PRESET_THEORA) {
507 rd->ffcodecdata.type = FFMPEG_OGG; /* XXX broken */
508 rd->ffcodecdata.codec_id_set(FFMPEG_CODEC_ID_THEORA);
509 }
510
511 rd->ffcodecdata.video_bitrate = 6000;
512 rd->ffcodecdata.gop_size = is_ntsc ? 18 : 15;
513 rd->ffcodecdata.rc_max_rate = 9000;
514 rd->ffcodecdata.rc_min_rate = 0;
515 rd->ffcodecdata.rc_buffer_size = 224 * 8;
516 rd->ffcodecdata.mux_packet_size = 2048;
517 rd->ffcodecdata.mux_rate = 10080000;
518 break;
519
521 rd->ffcodecdata.type = FFMPEG_AV1;
522 rd->ffcodecdata.codec_id_set(FFMPEG_CODEC_ID_AV1);
523 rd->ffcodecdata.video_bitrate = 6000;
524 rd->ffcodecdata.gop_size = is_ntsc ? 18 : 15;
525 rd->ffcodecdata.rc_max_rate = 9000;
526 rd->ffcodecdata.rc_min_rate = 0;
527 rd->ffcodecdata.rc_buffer_size = 224 * 8;
528 rd->ffcodecdata.mux_packet_size = 2048;
529 rd->ffcodecdata.mux_rate = 10080000;
530 break;
531 }
532}
533
535{
537 /* Note: update properties_output.py `use_bpp` when changing this function. */
538 if (ELEM(av_codec_id,
539 AV_CODEC_ID_H264,
540 AV_CODEC_ID_H265,
541 AV_CODEC_ID_AV1,
542 AV_CODEC_ID_PRORES,
543 AV_CODEC_ID_FFV1))
544 {
545 bit_depths |= R_IMF_CHAN_DEPTH_10;
546 }
547 if (ELEM(av_codec_id, AV_CODEC_ID_H265, AV_CODEC_ID_AV1, AV_CODEC_ID_FFV1)) {
548 bit_depths |= R_IMF_CHAN_DEPTH_12;
549 }
550 if (ELEM(av_codec_id, AV_CODEC_ID_FFV1)) {
551 bit_depths |= R_IMF_CHAN_DEPTH_16;
552 }
553 return bit_depths;
554}
555
556bool MOV_codec_supports_alpha(AVCodecID av_codec_id, int ffmpeg_profile)
557{
558 if (av_codec_id == AV_CODEC_ID_PRORES) {
560 }
561 return ELEM(av_codec_id,
562 AV_CODEC_ID_FFV1,
563 AV_CODEC_ID_QTRLE,
564 AV_CODEC_ID_PNG,
565 AV_CODEC_ID_VP9,
566 AV_CODEC_ID_HUFFYUV);
567}
568
569bool MOV_codec_supports_crf(AVCodecID av_codec_id)
570{
571 return ELEM(av_codec_id,
572 AV_CODEC_ID_H264,
573 AV_CODEC_ID_H265,
574 AV_CODEC_ID_MPEG4,
575 AV_CODEC_ID_VP9,
576 AV_CODEC_ID_AV1);
577}
578
579int MOV_thread_count()
580{
581 /* ffmpeg does not recommend thread counts above 16. */
582 return std::min(BLI_system_thread_count(), 16);
583}
584
585static Mutex hw_device_lock;
586static Map<AVHWDeviceType, AVBufferRef *> hw_devices;
587
588AVBufferRef *ffmpeg_hw_device_get(const AVHWDeviceType device_type)
589{
590 std::lock_guard lock(hw_device_lock);
591 return hw_devices.lookup_or_add_cb(device_type, [&]() {
592 AVBufferRef *hw_device_ctx = nullptr;
593 const int ret = av_hwdevice_ctx_create(&hw_device_ctx, device_type, nullptr, nullptr, 0);
594 if (ret < 0) {
595 char error_str[AV_ERROR_MAX_STRING_SIZE];
596 av_make_error_string(error_str, AV_ERROR_MAX_STRING_SIZE, ret);
597 CLOG_INFO(&LOG,
598 "ffmpeg: couldn't create %s decoding device: %s",
599 av_hwdevice_get_type_name(device_type),
600 error_str);
601 }
602 return hw_device_ctx;
603 });
604}
605
606#endif /* WITH_FFMPEG */
607
608bool MOV_is_movie_file(const char *filepath)
609{
610 BLI_assert(!BLI_path_is_rel(filepath));
611
612#ifdef WITH_FFMPEG
613 if (isffmpeg(filepath)) {
614 return true;
615 }
616#else
617 UNUSED_VARS(filepath);
618#endif
619
620 return false;
621}
622
624{
625#ifdef WITH_FFMPEG
626 avdevice_register_all();
627
628 ffmpeg_last_error_buffer[0] = '\0';
629
631 av_log_set_level(AV_LOG_TRACE);
632 }
633 else if (CLOG_CHECK(&LOG, CLG_LEVEL_DEBUG)) {
634 av_log_set_level(AV_LOG_DEBUG);
635 }
636 else if (CLOG_CHECK(&LOG, CLG_LEVEL_INFO)) {
637 av_log_set_level(AV_LOG_INFO);
638 }
639
640 /* set separate callback which could store last error to report to UI */
641 av_log_set_callback(ffmpeg_log_callback);
642#endif
643}
644
646{
647#ifdef WITH_FFMPEG
648 ffmpeg_sws_exit();
649 std::lock_guard lock(hw_device_lock);
650 for (AVBufferRef *&hw_device_ctx : hw_devices.values()) {
651 av_buffer_unref(&hw_device_ctx);
652 }
653 hw_devices.clear();
654#endif
655}
656
658{
659#ifdef WITH_FFMPEG
660
661 if (imf->imtype == R_IMF_IMTYPE_FFMPEG) {
662 if (rd->ffcodecdata.type <= 0 || rd->ffcodecdata.codec_id_get() <= 0 ||
663 rd->ffcodecdata.video_bitrate <= 1)
664 {
665 ffmpeg_preset_set(rd, FFMPEG_PRESET_H264);
669 }
670 if (rd->ffcodecdata.type == FFMPEG_OGG) {
672 }
673 }
674#else
675 UNUSED_VARS(rd, imf);
676#endif
677}
678
680{
681#ifdef WITH_FFMPEG
682 return MOV_codec_valid_bit_depths(mov_av_codec_id_get(codec_id));
683#else
684 UNUSED_VARS(codec_id);
685 return R_IMF_CHAN_DEPTH_8;
686#endif
687}
688
689bool MOV_codec_supports_alpha(IMB_Ffmpeg_Codec_ID codec_id, int ffmpeg_profile)
690{
691#ifdef WITH_FFMPEG
692 return MOV_codec_supports_alpha(mov_av_codec_id_get(codec_id), ffmpeg_profile);
693#else
694 UNUSED_VARS(codec_id, ffmpeg_profile);
695 return false;
696#endif
697}
698
700{
701#ifdef WITH_FFMPEG
702 return MOV_codec_supports_crf(mov_av_codec_id_get(codec_id));
703#else
704 UNUSED_VARS(codec_id);
705 return false;
706#endif
707}
708
709} // namespace blender
#define CLOG_CHECK(clg_ref, verbose_level,...)
Definition CLG_log.h:147
CLG_Level
Definition CLG_log.h:52
@ CLG_LEVEL_ERROR
Definition CLG_log.h:56
@ CLG_LEVEL_DEBUG
Definition CLG_log.h:62
@ CLG_LEVEL_INFO
Definition CLG_log.h:60
@ CLG_LEVEL_TRACE
Definition CLG_log.h:64
#define CLOG_STR_AT_LEVEL(clg_ref, verbose_level, str)
Definition CLG_log.h:168
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
volatile int lock
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define ELEM(...)
#define FFMPEG_INLINE
#define LOG(level)
Definition log.h:97
int size(const AssetLibraryReference *library_reference)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
size_t BLI_vsnprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format, va_list arg) ATTR_PRINTF_FORMAT(3
unsigned int uint
Definition BKE_text.h:55
void MOV_init()
bool MOV_codec_supports_alpha(IMB_Ffmpeg_Codec_ID codec_id, int ffmpeg_profile)
void MOV_exit()
eImageFormatDepth MOV_codec_valid_bit_depths(IMB_Ffmpeg_Codec_ID codec_id)
bool MOV_is_movie_file(const char *filepath)
int BLI_system_thread_count()
Definition threads.cc:258
@ FFMPEG_OGG
Definition MOV_enums.hh:24
@ FFMPEG_MKV
Definition MOV_enums.hh:23
@ FFMPEG_MPEG2
Definition MOV_enums.hh:15
@ FFMPEG_AV1
Definition MOV_enums.hh:27
@ FFMPEG_AVI
Definition MOV_enums.hh:17
unsigned char uint8_t
Definition BKE_text.h:79
@ FFMPEG_PRESET_XVID
Definition MOV_enums.hh:34
@ FFMPEG_PRESET_H264
Definition MOV_enums.hh:32
@ FFMPEG_PRESET_THEORA
Definition MOV_enums.hh:33
@ FFMPEG_PRESET_AV1
Definition MOV_enums.hh:35
bool MOV_codec_supports_crf(IMB_Ffmpeg_Codec_ID codec_id)
void MOV_validate_output_settings(RenderData *rd, const ImageFormatData *imf)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
std::mutex Mutex
Definition BLI_mutex.hh:51
@ FFMPEG_CODEC_ID_PCM_S16LE
@ FFMPEG_CODEC_ID_MPEG1VIDEO
@ FFMPEG_CODEC_ID_PRORES
@ FFMPEG_CODEC_ID_MPEG4
@ FFMPEG_CODEC_ID_DNXHD
@ FFMPEG_CODEC_ID_THEORA
@ FFMPEG_CODEC_ID_QTRLE
@ FFMPEG_CODEC_ID_DVVIDEO
@ FFMPEG_CODEC_ID_HUFFYUV
@ FFMPEG_CODEC_ID_MPEG2VIDEO
@ FFMPEG_CODEC_ID_VORBIS
static CLG_LogRef LOG
Definition logging.cpp:12
@ FFM_PRORES_PROFILE_4444_XQ
@ FFM_PRORES_PROFILE_4444
bool BLI_path_extension_check_n(const char *path,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
struct FFMpegCodecData ffcodecdata