@@ -33,7 +33,7 @@ static PyObject* VideoSource_read(NvCodec* Self)
3333 AVPacket *packet = av_packet_alloc ();
3434 if (videoSource_read (m_handle, packet) < 0 ){
3535 av_packet_free (&packet);
36- return NULL ;
36+ return Py_None ;
3737 }
3838 PyObject* rtn = PyBytes_FromStringAndSize ((const char *)packet->data , packet->size );
3939 av_packet_free (&packet);
@@ -105,23 +105,31 @@ static PyObject* VideoDecoder_decode(NvCodec* Self, PyObject* pArgs)
105105
106106 unsigned char * data;
107107 int len;
108- if (!PyArg_ParseTuple (pArgs, " y#" , &data, &len)){
108+ unsigned int type = 0 ;
109+ if (!PyArg_ParseTuple (pArgs, " y#|I" , &data, &len, &type)){
109110 PyErr_SetString (PyExc_ValueError, " Parse the argument FAILED! You should video byte data!" );
110- return NULL ;
111+ return Py_None ;
111112 }
112113
113- videoFrameList* list = videoDecoder_decode (m_handle, data, len);
114+ PyObject* rtn = Py_BuildValue (" []" );
115+ char error_str[128 ];
116+ videoFrameList* list = videoDecoder_decode (m_handle, data, len, error_str);
114117 if (list == NULL ){
115- Py_INCREF (Py_None);
116- return Py_None;
118+ if (error_str[0 ] != NULL ){
119+ PyErr_Format (PyExc_ValueError, " %s" , error_str);
120+ return NULL ;
121+ }
122+ return rtn;
117123 }
118124
119- PyObject* rtn = Py_BuildValue (" []" );
120125 npy_intp dims[3 ] = {(npy_intp)(list->height ), (npy_intp)(list->width ), 4 };
121126 PyObject* tempFrame;
122127 for (int i = 0 ;i<list->length ;i++){
123128 tempFrame = PyArray_SimpleNewFromData (3 , dims, NPY_UINT8, list->pFrames + (i*(list->perFrameSize )));
124129 PyArray_ENABLEFLAGS ((PyArrayObject*) tempFrame, NPY_ARRAY_OWNDATA);
130+ if (type != 0 ){
131+ tempFrame = PyArray_SwapAxes ((PyArrayObject*)tempFrame, 0 , 1 );
132+ }
125133 PyList_Append (rtn, tempFrame);
126134 }
127135 videoFrameList_destory (&list);
0 commit comments