Skip to content

Commit

Permalink
update generator doc
Browse files Browse the repository at this point in the history
  • Loading branch information
taoboyang authored and sfeiwong committed Sep 15, 2023
1 parent 39a4896 commit 25e57e8
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@ weight: 1
The generator method has common similarities and differences, mainly using ```start()``` (usually ```run()```):

```python
frames = (
bmf. graph()
.decode({'input_path': "../files/img.mp4"})['video']
.ff_filter('scale', 299, 299) # or you can use '.scale(299, 299)'
.start() # this will return a packet generator
pkts = (
bmf.graph()
.decode({'input_path': "../files/big_bunny_10s_30fps.mp4"})['video']
.ff_filter('scale', 299, 299) # or you can use '.scale(299, 299)'
.start() # this will return a packet generator
)
```

The generated frames can be used like iterators:

```python
for i, frame in enumerate(frames):
# convert frame to a nd array
if frame is not None:
np_frame = frame.to_ndarray(format='rgb24')

# we can add some more processing here, e.g. predicting
print('frame', i, 'shape', np_frame.shape)
else:
break
for i, pkt in enumerate(pkts):
# convert frame to a nd array
if pkt.is_(bmf.VideoFrame) and i < 10:
vf = pkt.get(bmf.VideoFrame)
rgb = mp.PixelInfo(mp.kPF_RGB24)
np_vf = vf.reformat(rgb).frame().plane(0).numpy()
# we can add some more processing here, e.g. predicting
print("frame", i, "shape", np_vf.shape)
else:
break
```

If you need the complete code, you can refer to [test_generator.py](#tbytodo)

0 comments on commit 25e57e8

Please sign in to comment.