Skip to content

Commit

Permalink
make get_frame return None when no more frame to decode
Browse files Browse the repository at this point in the history
  • Loading branch information
Tee0125 committed Mar 22, 2018
1 parent f95f525 commit 1e4cd0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions PyDemux/Video.py
Expand Up @@ -6,12 +6,14 @@ def __init__(self, filename):
self.ctx = _demux.open(filename)

def get_frame(self):
frame, w, h = _demux.get_frame(self.ctx)
result = _demux.get_frame(self.ctx)

if frame is not None:
return Image.frombytes("RGB", (w, h), frame)
else:
return None
if result is None:
return none

frame, w, h, = result

return Image.frombytes("RGB", (w, h), frame)

def __del__(self):
if self.ctx is not None:
Expand Down
4 changes: 4 additions & 0 deletions _py.c
Expand Up @@ -70,8 +70,12 @@ static PyObject* get_frame_wrapper(PyObject* self, PyObject* args)
if (!PyArg_ParseTuple(args, "l", &ctx))
return NULL;

// demux frame
frame = demux_get_frame(ctx);

if (!frame)
Py_RETURN_NONE;

// convert RGB array to python string
width = demux_get_width(ctx);
height = demux_get_height(ctx);
Expand Down

0 comments on commit 1e4cd0e

Please sign in to comment.