-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
title: MaixPy Playback Video | ||
update: | ||
- date: 2024-08-19 | ||
author: lxowalle | ||
version: 1.0.0 | ||
content: Initial document | ||
--- | ||
|
||
## Introduction | ||
|
||
This document provides instructions for using the Play Video feature. | ||
|
||
`MaixPy` supports playing `h264`, `mp4` and `flv` video formats, note that currently only `avc` encoded `mp4` and `flv` files are supported. | ||
|
||
## Play `MP4` video | ||
|
||
An example of playing an `mp4` video, the path to the video file is `/root/output.mp4`. | ||
|
||
```python | ||
from maix import video, display, app | ||
|
||
disp = display.Display() | ||
d = video.Decoder('/root/output.mp4') | ||
print(f'resolution: {d.width()}x{d.height()} bitrate: {d.bitrate()} fps: {d.fps()}') | ||
d.seek(0) | ||
while not app.need_exit(): | ||
img = d.decode_video() | ||
if not img: | ||
d.seek(0) | ||
continue | ||
print(d.last_pts()) | ||
disp.show(img) | ||
``` | ||
|
||
Steps: | ||
|
||
1. Import the module and initialise the camera | ||
|
||
```python | ||
from maix import video, display, app | ||
disp = display.Display() | ||
``` | ||
|
||
- `disp = display.Display()` is used to initialise the display to show the decoded image | ||
|
||
|
||
2. Initialise the `Decoder` module | ||
|
||
```python | ||
d = video.Decoder('/root/output.mp4') | ||
``` | ||
|
||
- `d = video.Decoder(‘/root/output.mp4’)` is used to initialise the decoder and set the path to the video file that needs to be played. If you need to play `flv` files, you can fill in the path of the file with `flv` suffix, such as `{your_file_path}.flv`, if you need to play `h264` files, you can fill in the path of the file with `h264` suffix, such as `{your_file_path}.h264` | ||
|
||
3. Set the decoding location | ||
|
||
```python | ||
d.seek(0) | ||
``` | ||
|
||
- can be used to set the position of the video to be played, in seconds. | ||
|
||
4. Get the decoded image | ||
|
||
```python | ||
img = d.decode_video() | ||
``` | ||
|
||
- Each call returns an image frame and saves it to `img`. Currently decoding can only support outputting images in `NV21` format | ||
|
||
5. Display the decoded image | ||
|
||
```python | ||
disp.show(img) | ||
``` | ||
|
||
6. Done, see [API documentation](https://wiki.sipeed.com/maixpy/api/maix/video.html) for more usage of `Decoder`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: MaixPy 播放视频 | ||
update: | ||
- date: 2024-08-19 | ||
author: lxowalle | ||
version: 1.0.0 | ||
content: 初版文档 | ||
--- | ||
|
||
## 简介 | ||
|
||
本文档提供播放视频功能的使用方法。 | ||
|
||
`MaixPy`支持播放`h264`、`mp4`、`flv`格式的视频,需要注意目前只支持`avc`编码的`mp4`和`flv`文件 | ||
|
||
|
||
## 播放`MP4`视频 | ||
|
||
一个播放`mp4`视频的示例,视频文件路径为`/root/output.mp4` | ||
|
||
```python | ||
from maix import video, display, app | ||
|
||
disp = display.Display() | ||
d = video.Decoder('/root/output.mp4') | ||
print(f'resolution: {d.width()}x{d.height()} bitrate: {d.bitrate()} fps: {d.fps()}') | ||
d.seek(0) | ||
while not app.need_exit(): | ||
img = d.decode_video() | ||
if not img: | ||
d.seek(0) | ||
continue | ||
print(d.last_pts()) | ||
disp.show(img) | ||
``` | ||
|
||
步骤: | ||
|
||
1. 导入模块并初始化摄像头 | ||
|
||
```python | ||
from maix import video, display, app | ||
disp = display.Display() | ||
``` | ||
|
||
- `disp = display.Display()`用来初始化显示屏,用于显示解码的图像 | ||
|
||
|
||
2. 初始化`Decoder`模块 | ||
|
||
```python | ||
d = video.Decoder('/root/output.mp4') | ||
``` | ||
|
||
- `d = video.Decoder('/root/output.mp4')`用来初始化解码器,并设置需要播放的视频文件路径。如果你需要播放`flv`文件,则可以填写`flv`为后缀的文件路径,例如`{your_file_path}.flv`,如果你需要播放`h264`文件,则可以填写`h264`为后缀的文件路径,例如`{your_file_path}.h264` | ||
|
||
3. 设置解码的位置 | ||
|
||
```python | ||
d.seek(0) | ||
``` | ||
|
||
- 可以用来设置播放视频的位置,单位是秒 | ||
|
||
4. 获取解码后的图像 | ||
|
||
```python | ||
img = d.decode_video() | ||
``` | ||
|
||
- 每次调用都会返回一帧图像,并保存到`img`。目前解码后只能支持输出`NV21`格式的图像 | ||
|
||
5. 显示解码后的图像 | ||
|
||
```python | ||
disp.show(img) | ||
``` | ||
|
||
6. 完成,更多`Decoder`的用法请看[API文档](https://wiki.sipeed.com/maixpy/api/maix/video.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from maix import video, display, app | ||
|
||
disp = display.Display() | ||
d = video.Decoder('/root/output.mp4') | ||
print(f'resolution: {d.width()}x{d.height()} bitrate: {d.bitrate()} fps: {d.fps()}') | ||
d.seek(0) | ||
while not app.need_exit(): | ||
img = d.decode_video() | ||
if not img: | ||
d.seek(0) | ||
continue | ||
print(d.last_pts()) | ||
disp.show(img) |