Blender V4.3
bpy_app_ffmpeg.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_utildefines.h"
10#include <Python.h>
11
12#include "bpy_app_ffmpeg.hh"
13
15
16#ifdef WITH_FFMPEG
17extern "C" {
18# include <libavcodec/avcodec.h>
19# include <libavdevice/avdevice.h>
20# include <libavformat/avformat.h>
21# include <libavutil/avutil.h>
22# include <libswscale/swscale.h>
23}
24#endif
25
26static PyTypeObject BlenderAppFFmpegType;
27
28#define DEF_FFMPEG_LIB_VERSION(lib) \
29 {(#lib "_version"), ("The " #lib " version as a tuple of 3 numbers")}, \
30 { \
31 (#lib "_version_string"), ("The " #lib " version formatted as a string") \
32 }
33
34static PyStructSequence_Field app_ffmpeg_info_fields[] = {
35 {"supported", "Boolean, True when Blender is built with FFmpeg support"},
36
38 DEF_FFMPEG_LIB_VERSION(avdevice),
39 DEF_FFMPEG_LIB_VERSION(avformat),
42 {nullptr},
43};
44
45#undef DEF_FFMPEG_LIB_VERSION
46
47static PyStructSequence_Desc app_ffmpeg_info_desc = {
48 /*name*/ "bpy.app.ffmpeg",
49 /*doc*/ "This module contains information about FFmpeg blender is linked against",
50 /*fields*/ app_ffmpeg_info_fields,
51 /*n_in_sequence*/ ARRAY_SIZE(app_ffmpeg_info_fields) - 1,
52};
53
54static PyObject *make_ffmpeg_info()
55{
56 PyObject *ffmpeg_info;
57 int pos = 0;
58
59#ifdef WITH_FFMPEG
60 int curversion;
61#endif
62
63 ffmpeg_info = PyStructSequence_New(&BlenderAppFFmpegType);
64 if (ffmpeg_info == nullptr) {
65 return nullptr;
66 }
67
68#if 0 /* UNUSED */
69# define SetIntItem(flag) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, PyLong_FromLong(flag))
70#endif
71#ifndef WITH_FFMPEG
72# define SetStrItem(str) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, PyUnicode_FromString(str))
73#endif
74#define SetObjItem(obj) PyStructSequence_SET_ITEM(ffmpeg_info, pos++, obj)
75
76#ifdef WITH_FFMPEG
77# define FFMPEG_LIB_VERSION(lib) \
78 { \
79 curversion = lib##_version(); \
80 SetObjItem( \
81 PyC_Tuple_Pack_I32({curversion >> 16, (curversion >> 8) % 256, curversion % 256})); \
82 SetObjItem(PyUnicode_FromFormat( \
83 "%2d, %2d, %2d", curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \
84 } \
85 (void)0
86#else
87# define FFMPEG_LIB_VERSION(lib) \
88 { \
89 SetStrItem("Unknown"); \
90 SetStrItem("Unknown"); \
91 } \
92 (void)0
93#endif
94
95#ifdef WITH_FFMPEG
96 SetObjItem(PyBool_FromLong(1));
97#else
98 SetObjItem(PyBool_FromLong(0));
99#endif
100
101 FFMPEG_LIB_VERSION(avcodec);
102 FFMPEG_LIB_VERSION(avdevice);
103 FFMPEG_LIB_VERSION(avformat);
104 FFMPEG_LIB_VERSION(avutil);
105 FFMPEG_LIB_VERSION(swscale);
106
107#undef FFMPEG_LIB_VERSION
108
109 if (UNLIKELY(PyErr_Occurred())) {
110 Py_DECREF(ffmpeg_info);
111 return nullptr;
112 }
113
114// #undef SetIntItem
115#undef SetStrItem
116#undef SetObjItem
117
118 return ffmpeg_info;
119}
120
122{
123 PyObject *ret;
124
125 PyStructSequence_InitType(&BlenderAppFFmpegType, &app_ffmpeg_info_desc);
126
128
129 /* prevent user from creating new instances */
130 BlenderAppFFmpegType.tp_init = nullptr;
131 BlenderAppFFmpegType.tp_new = nullptr;
132 /* Without this we can't do `set(sys.modules)` #29635. */
133 BlenderAppFFmpegType.tp_hash = (hashfunc)_Py_HashPointer;
134
135 return ret;
136}
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
#define DEF_FFMPEG_LIB_VERSION(lib)
static PyTypeObject BlenderAppFFmpegType
static PyStructSequence_Desc app_ffmpeg_info_desc
PyObject * BPY_app_ffmpeg_struct()
static PyStructSequence_Field app_ffmpeg_info_fields[]
#define FFMPEG_LIB_VERSION(lib)
static PyObject * make_ffmpeg_info()
#define SetObjItem(obj)
return ret