-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathh264decode.c
46 lines (35 loc) · 1.2 KB
/
h264decode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <Python.h>
#include <libavcodec/avcodec.h>
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,0,0)
#define AV_CODEC_ID_H264 CODEC_ID_H264
#endif
AVCodec *h264decoder_h264Codec;
static PyMethodDef h264decode_methods[] = {
{NULL, NULL, 0, NULL}
};
extern PyTypeObject h264decode_DecoderType;
extern PyTypeObject h264decode_YUVFrameType;
#ifndef PyMODINIT_FUNC
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC inith264decode(void)
{
avcodec_register_all();
h264decoder_h264Codec = avcodec_find_decoder(AV_CODEC_ID_H264);
if (!h264decoder_h264Codec) {
PyErr_SetString(PyExc_SystemError, "No H.264 codec found in this installation of libavcodec");
return;
}
if (PyType_Ready(&h264decode_DecoderType) < 0)
return;
if (PyType_Ready(&h264decode_YUVFrameType) < 0)
return;
PyObject *module = Py_InitModule3("h264decode", h264decode_methods,
"A simple wrapper around libavcodec to decode complete H.264 packets to YUV420p frames");
if (!module)
return;
Py_INCREF(&h264decode_DecoderType);
PyModule_AddObject(module, "Decoder", (PyObject *)&h264decode_DecoderType);
Py_INCREF(&h264decode_YUVFrameType);
PyModule_AddObject(module, "YUVFrame", (PyObject *)&h264decode_YUVFrameType);
}