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