maix.video
maix.video module
You can use
maix.video
to access this module with MaixPy
This module is generated from MaixPy and MaixCDK
Module
No module
Enum
VideoType
Video type
item | describe |
---|---|
values | VIDEO_NONE: format invalid VIDEO_ENC_H265_CBR: Deprecated VIDEO_ENC_MP4_CBR: Deprecated VIDEO_DEC_H265_CBR: Deprecated VIDEO_DEC_MP4_CBR: Deprecated VIDEO_H264_CBR: Deprecated VIDEO_H265_CBR: Deprecated VIDEO_H264_CBR_MP4: Deprecated VIDEO_H265_CBR_MP4: Deprecated VIDEO_H264: VIDEO_H264_MP4: VIDEO_H264_FLV: VIDEO_H265: VIDEO_H265_MP4: |
C++ defination code:
enum VideoType { VIDEO_NONE = 0, // format invalid VIDEO_ENC_H265_CBR, // Deprecated VIDEO_ENC_MP4_CBR, // Deprecated VIDEO_DEC_H265_CBR, // Deprecated VIDEO_DEC_MP4_CBR, // Deprecated VIDEO_H264_CBR, // Deprecated VIDEO_H265_CBR, // Deprecated VIDEO_H264_CBR_MP4, // Deprecated VIDEO_H265_CBR_MP4, // Deprecated VIDEO_H264, VIDEO_H264_MP4, VIDEO_H264_FLV, VIDEO_H265, VIDEO_H265_MP4, }
MediaType
Video type
item | describe |
---|---|
values | MEDIA_TYPE_UNKNOWN: Represents an unknown media type, which is usually treated as AVMEDIA_TYPE_DATA. MEDIA_TYPE_VIDEO: Represents a video stream, such as video content encoded in H.264, MPEG-4, etc. MEDIA_TYPE_AUDIO: Represents an audio stream, such as audio content encoded in AAC, MP3, etc. MEDIA_TYPE_DATA: Represents opaque data streams that are usually continuous. This type of stream is not necessarily audio or video and may be used for other data purposes. MEDIA_TYPE_SUBTITLE: Represents a subtitle stream used for displaying text or subtitle information, such as SRT, ASS, etc. MEDIA_TYPE_ATTACHMENT: Represents attachment streams that are usually sparse. Attachment streams can include images, fonts, or other files that need to be bundled with the media. MEDIA_TYPE_NB: Represents the number of media types (count) and indicates the total number of media types defined in this enumeration. It is not a media type itself but is used for counting enumeration items. |
C++ defination code:
enum MediaType { MEDIA_TYPE_UNKNOWN = -1, // Represents an unknown media type, which is usually treated as AVMEDIA_TYPE_DATA. MEDIA_TYPE_VIDEO, // Represents a video stream, such as video content encoded in H.264, MPEG-4, etc. MEDIA_TYPE_AUDIO, // Represents an audio stream, such as audio content encoded in AAC, MP3, etc. MEDIA_TYPE_DATA, // Represents opaque data streams that are usually continuous. This type of stream is not necessarily audio or video and may be used for other data purposes. MEDIA_TYPE_SUBTITLE, // Represents a subtitle stream used for displaying text or subtitle information, such as SRT, ASS, etc. MEDIA_TYPE_ATTACHMENT, // Represents attachment streams that are usually sparse. Attachment streams can include images, fonts, or other files that need to be bundled with the media. MEDIA_TYPE_NB // Represents the number of media types (count) and indicates the total number of media types defined in this enumeration. It is not a media type itself but is used for counting enumeration items. }
Variable
Function
Class
Context
Context class
C++ defination code:
class Context
__init__
def __init__(self, media_type: MediaType, timebase: list[int]) -> None
Construct a new Video object
item | description |
---|---|
type | func |
param | media_type: enable capture, if true, you can use capture() function to get an image object timebase: Time base, used as the unit for calculating playback time. It must be an array containing two parameters, in the format [num, den], where the first parameter is the numerator of the time base, and the second parameter is the denominator of the time base. |
static | False |
C++ defination code:
Context(video::MediaType media_type, std::vector<int> timebase)
set_image
def set_image(self, image: maix.image.Image, duration: int = 0, pts: int = 0, last_pts: int = 0) -> None
Set image info
item | description |
---|---|
type | func |
param | image: image data duration: Duration of the current image. unit: timebase pts: The start time of this image playback. If it is 0, it means this parameter is not supported. unit: timebase last_pts: The start time of the previous image playback. It can be used to ensure the playback order. If it is 0, it means this parameter is not supported. unit: timebase |
static | False |
C++ defination code:
void set_image(image::Image *image, int duration = 0, uint64_t pts = 0, uint64_t last_pts = 0)
image
def image(self) -> maix.image.Image
Retrieve the image data to be played.
item | description |
---|---|
type | func |
attention | Note that if you call this interface, you are responsible for releasing the memory of the image, and this interface cannot be called again. |
static | False |
C++ defination code:
image::Image *image()
media_type
def media_type(self) -> MediaType
Get the media type to determine whether it is video, audio, or another media type.
item | description |
---|---|
type | func |
static | False |
C++ defination code:
video::MediaType media_type()
pts
def pts(self) -> int
Get the start time of the current playback., in units of time base.
item | description |
---|---|
type | func |
static | False |
C++ defination code:
uint64_t pts()
last_pts
def last_pts(self) -> int
Get the start time of the previous playback, in units of time base.
item | description |
---|---|
type | func |
static | False |
C++ defination code:
uint64_t last_pts()
timebase
def timebase(self) -> list[int]
Get the time base.
item | description |
---|---|
type | func |
static | False |
C++ defination code:
std::vector<int> timebase()
duration
def duration(self) -> int
Duration of the current frame. unit: timebase
item | description |
---|---|
type | func |
static | False |
C++ defination code:
int duration()
duration_us
def duration_us(self) -> int
Duration of the current frame. unit: us
item | description |
---|---|
type | func |
static | False |
C++ defination code:
uint64_t duration_us()
Frame
Frame class
C++ defination code:
class Frame
to_bytes
def to_bytes(*args, **kwargs)
Get raw data of packet
item | description |
---|---|
type | func |
param | copy: if true, will alloc memory and copy data to new buffer |
return | raw data |
static | False |
C++ defination code:
Bytes *to_bytes(bool copy = false)
size
def size(self) -> int
Get raw data size of packet
item | description |
---|---|
type | func |
return | size of raw data |
static | False |
C++ defination code:
size_t size()
is_valid
def is_valid(self) -> bool
Check packet is valid
item | description |
---|---|
type | func |
return | true, packet is valid; false, packet is invalid |
static | False |
C++ defination code:
bool is_valid()
set_pts
def set_pts(self, pts: int) -> None
Set pts
item | description |
---|---|
type | func |
param | pts: presentation time stamp. unit: time_base |
static | False |
C++ defination code:
void set_pts(uint64_t pts)
set_dts
def set_dts(self, dts: int) -> None
Set dts
item | description |
---|---|
type | func |
param | dts: decoding time stamp. unit: time_base |
static | False |
C++ defination code:
void set_dts(uint64_t dts)
set_duration
def set_duration(self, duration: int) -> None
Set duration
item | description |
---|---|
type | func |
param | duration: packet display time. unit: time_base |
static | False |
C++ defination code:
void set_duration(uint64_t duration)
get_pts
def get_pts(self) -> int
Set pts
item | description |
---|---|
type | func |
param | pts: presentation time stamp. unit: time_base |
return | pts value |
static | False |
C++ defination code:
uint64_t get_pts()
get_dts
def get_dts(self) -> int
Set dts
item | description |
---|---|
type | func |
param | dts: decoding time stamp. unit: time_base |
return | dts value |
static | False |
C++ defination code:
uint64_t get_dts()
get_duration
def get_duration(self) -> int
Get duration
item | description |
---|---|
type | func |
return | duration value |
static | False |
C++ defination code:
uint64_t get_duration()
type
def type(self) -> VideoType
Get frame type
item | description |
---|---|
type | func |
return | video type. @see video::VideoType |
static | False |
C++ defination code:
video::VideoType type()
Packet
Packet class
C++ defination code:
class Packet
__init__
def __init__(self, data: int, len: int, pts: int = -1, dts: int = -1, duration: int = 0) -> None
Packet number (pair of numerator and denominator).
item | description |
---|---|
type | func |
param | data: src data pointer, use pointers directly without copying. Note: this object will try to free this memory len: data len pts: presentation time stamp. unit: time_base dts: decoding time stamp. unit: time_base duration: packet display time. unit: time_base |
static | False |
C++ defination code:
Packet(uint8_t *data, int len, uint64_t pts = -1, uint64_t dts = -1, int64_t duration = 0)
get
def get(self) -> list[int]
Get raw data of packet
item | description |
---|---|
type | func |
return | raw data |
static | False |
C++ defination code:
std::vector<uint8_t> get()
data
def data(self) -> int
Get raw data of packet
item | description |
---|---|
type | func |
return | raw data |
static | False |
C++ defination code:
uint8_t *data()
data_size
def data_size(self) -> int
Get raw data size of packet
item | description |
---|---|
type | func |
return | size of raw data |
static | False |
C++ defination code:
size_t data_size()
is_valid
def is_valid(self) -> bool
Check packet is valid
item | description |
---|---|
type | func |
return | true, packet is valid; false, packet is invalid |
static | False |
C++ defination code:
bool is_valid()
set_pts
def set_pts(self, pts: int) -> None
Set pts
item | description |
---|---|
type | func |
param | pts: presentation time stamp. unit: time_base |
return | true, packet is valid; false, packet is invalid |
static | False |
C++ defination code:
void set_pts(uint64_t pts)
set_dts
def set_dts(self, dts: int) -> None
Set dts
item | description |
---|---|
type | func |
param | dts: decoding time stamp. unit: time_base |
return | true, packet is valid; false, packet is invalid |
static | False |
C++ defination code:
void set_dts(uint64_t dts)
set_duration
def set_duration(self, duration: int) -> None
Set duration
item | description |
---|---|
type | func |
param | duration: packet display time. unit: time_base |
return | true, packet is valid; false, packet is invalid |
static | False |
C++ defination code:
void set_duration(uint64_t duration)
Encoder
Encode class
C++ defination code:
class Encoder
__init__
def __init__(self, path: str = '', width: int = 2560, height: int = 1440, format: maix.image.Format = ..., type: VideoType = ..., framerate: int = 30, gop: int = 50, bitrate: int = 3000000, time_base: int = 1000, capture: bool = False, block: bool = True) -> None
Construct a new Video object
item | description |
---|---|
type | func |
param | width: picture width. this value may be set automatically. default is 2560. height: picture height. this value may be set automatically. default is 1440. format: picture format. default is image::Format::FMT_YVU420SP. @see image::Format type: video encode/decode type. default is ENC_H265_CBR. @see EncodeType framerate: frame rate. framerate default is 30, means 30 frames per second for video. 1/time_base is not the average frame rate if the frame rate is not constant. gop: for h264/h265 encoding, the interval between two I-frames, default is 50. bitrate: for h264/h265 encoding, used to limit the bandwidth used by compressed data, default is 3000kbps time_base: frame time base. time_base default is 1000, means 1/1000 ms (not used) capture: enable capture, if true, you can use capture() function to get an image object block: This parameter determines whether encoding should block until it is complete. If set to true, it will wait until encoding is finished before returning. If set to false, it will return the current encoding result on the next call. |
static | False |
C++ defination code:
Encoder(std::string path = "", int width = 2560, int height = 1440, image::Format format = image::Format::FMT_YVU420SP, video::VideoType type = video::VideoType::VIDEO_H264, int framerate = 30, int gop = 50, int bitrate = 3000 * 1000, int time_base = 1000, bool capture = false, bool block = true)
bind_camera
def bind_camera(self, camera: maix.camera.Camera) -> maix.err.Err
Bind camera
item | description |
---|---|
type | func |
param | camera: camera object |
return | error code, err::ERR_NONE means success, others means failed |
static | False |
C++ defination code:
err::Err bind_camera(camera::Camera *camera)
encode
def encode(self, img: maix.image.Image = ...) -> Frame
Encode image.
item | description |
---|---|
type | func |
param | img: the image will be encode. if the img is NULL, this function will try to get image from camera, you must use bind_camera() function to bind the camera. |
return | encode result |
static | False |
C++ defination code:
video::Frame *encode(image::Image *img = maix::video::Encoder::NoneImage)
capture
def capture(self) -> maix.image.Image
Capture image
item | description |
---|---|
type | func |
attention | Each time encode is called, the last captured image will be released. |
return | error code |
static | False |
C++ defination code:
image::Image *capture()
width
def width(self) -> int
Get video width
item | description |
---|---|
type | func |
return | video width |
static | False |
C++ defination code:
int width()
height
def height(self) -> int
Get video height
item | description |
---|---|
type | func |
return | video height |
static | False |
C++ defination code:
int height()
type
def type(self) -> VideoType
Get video encode type
item | description |
---|---|
type | func |
return | VideoType |
static | False |
C++ defination code:
video::VideoType type()
framerate
def framerate(self) -> int
Get video encode framerate
item | description |
---|---|
type | func |
return | frame rate |
static | False |
C++ defination code:
int framerate()
gop
def gop(self) -> int
Get video encode gop
item | description |
---|---|
type | func |
return | gop value |
static | False |
C++ defination code:
int gop()
bitrate
def bitrate(self) -> int
Get video encode bitrate
item | description |
---|---|
type | func |
return | bitrate value |
static | False |
C++ defination code:
int bitrate()
time_base
def time_base(self) -> int
Get video encode time base
item | description |
---|---|
type | func |
return | time base value |
static | False |
C++ defination code:
int time_base()
Decoder
Decoder class
C++ defination code:
class Decoder
__init__
def __init__(self, path: str, format: maix.image.Format = ...) -> None
Construct a new decoder object
item | description |
---|---|
type | func |
param | path: Path to the file to be decoded. Supports files with .264 and .mp4 extensions. Note that only mp4 files containing h.264 streams are supported. format: Decoded output format, currently only support YUV420SP |
static | False |
C++ defination code:
Decoder(std::string path, image::Format format = image::Format::FMT_YVU420SP)
decode_video
def decode_video(self, block: bool = True) -> Context
Decode the video stream, returning the image of the next frame each time.
item | description |
---|---|
type | func |
param | block: Whether it blocks or not. If true, it will wait for the decoding to complete and return the current frame. If false, it will return the result of the previous frame's decoding. If the previous frame's decoding result is empty, it will return an unknown Context, and you can use the media_type method of the Context to determine if a valid result exists. |
return | Decoded context information. default is true. |
static | False |
C++ defination code:
video::Context * decode_video(bool block = true)
width
def width(self) -> int
Get the video width
item | description |
---|---|
type | func |
return | video width |
static | False |
C++ defination code:
int width()
height
def height(self) -> int
Get the video height
item | description |
---|---|
type | func |
return | video height |
static | False |
C++ defination code:
int height()
bitrate
def bitrate(self) -> int
Get the video bitrate
item | description |
---|---|
type | func |
return | bitrate value |
static | False |
C++ defination code:
int bitrate()
fps
def fps(self) -> int
Get the video fps
item | description |
---|---|
type | func |
return | fps value |
static | False |
C++ defination code:
int fps()
seek
def seek(self, time: float = -1) -> float
Seek to the required playback position
item | description |
---|---|
type | func |
param | time: timestamp value, unit: s |
return | return the current position, unit: s |
static | False |
C++ defination code:
double seek(double time = -1)
duration
def duration(self) -> float
Get the maximum duration of the video. If it returns 0, it means it cannot be predicted.
item | description |
---|---|
type | func |
return | duration value, unit: s |
static | False |
C++ defination code:
double duration()
timebase
def timebase(self) -> list[int]
Get the time base.
item | description |
---|---|
type | func |
static | False |
C++ defination code:
std::vector<int> timebase()
Video
Video class
C++ defination code:
class Video
__init__
def __init__(self, path: str = '', width: int = 2560, height: int = 1440, format: maix.image.Format = ..., time_base: int = 30, framerate: int = 30, capture: bool = False, open: bool = True) -> None
Construct a new Video object
item | description |
---|---|
type | func |
param | path: video path. the path determines the location where you load or save the file, if path is none, the video module will not save or load file. xxx.h265 means video format is H265, xxx.mp4 means video format is MP4 width: picture width. this value may be set automatically. default is 2560. height: picture height. this value may be set automatically. default is 1440. format: picture pixel format. this value may be set automatically. default is FMT_YVU420SP. time_base: frame time base. time_base default is 30, means 1/30 ms framerate: frame rate. framerate default is 30, means 30 frames per second for video. 1/time_base is not the average frame rate if the frame rate is not constant. capture: enable capture, if true, you can use capture() function to get an image object open: If true, video will automatically call open() after creation. default is true. |
static | False |
C++ defination code:
Video(std::string path = std::string(), int width = 2560, int height = 1440, image::Format format = image::Format::FMT_YVU420SP, int time_base = 30, int framerate = 30, bool capture = false, bool open = true)
open
def open(self, path: str = '', fps: float = 30.0) -> maix.err.Err
Open video and run
item | description |
---|---|
type | func |
param | path: video path. the path determines the location where you load or save the file, if path is none, the video module will not save or load file. xxx.h265 means video format is H265, xxx.mp4 means video format is MP4 fps: video fps |
return | error code, err::ERR_NONE means success, others means failed |
static | False |
C++ defination code:
err::Err open(std::string path = std::string(), double fps = 30.0)
close
def close(self) -> None
Close video
item | description |
---|---|
type | func |
static | False |
C++ defination code:
void close()
bind_camera
def bind_camera(self, camera: maix.camera.Camera) -> maix.err.Err
Bind camera
item | description |
---|---|
type | func |
param | camera: camera object |
return | error code, err::ERR_NONE means success, others means failed |
static | False |
C++ defination code:
err::Err bind_camera(camera::Camera *camera)
encode
def encode(self, img: maix.image.Image = ...) -> Packet
Encode image.
item | description |
---|---|
type | func |
param | img: the image will be encode. if the img is NULL, this function will try to get image from camera, you must use bind_camera() function to bind the camera. |
return | encode result |
static | False |
C++ defination code:
video::Packet *encode(image::Image *img = maix::video::Video::NoneImage)
decode
def decode(self, frame: Frame = None) -> maix.image.Image
Decode frame
item | description |
---|---|
type | func |
param | frame: the frame will be decode |
return | decode result |
static | False |
C++ defination code:
image::Image *decode(video::Frame *frame = nullptr)
finish
def finish(self) -> maix.err.Err
Encode or decode finish
item | description |
---|---|
type | func |
return | error code |
static | False |
C++ defination code:
err::Err finish()
capture
def capture(self) -> maix.image.Image
Capture image
item | description |
---|---|
type | func |
attention | Each time encode is called, the last captured image will be released. |
return | error code |
static | False |
C++ defination code:
image::Image *capture()
is_recording
def is_recording(self) -> bool
Check if video is recording
item | description |
---|---|
type | func |
return | true if video is recording, false if not |
static | False |
C++ defination code:
bool is_recording()
is_opened
def is_opened(self) -> bool
Check if video is opened
item | description |
---|---|
type | func |
return | true if video is opened, false if not |
static | False |
C++ defination code:
bool is_opened()
is_closed
def is_closed(self) -> bool
check video device is closed or not
item | description |
---|---|
type | func |
return | closed or not, bool type |
static | False |
C++ defination code:
bool is_closed()
width
def width(self) -> int
Get video width
item | description |
---|---|
type | func |
return | video width |
static | False |
C++ defination code:
int width()
height
def height(self) -> int
Get video height
item | description |
---|---|
type | func |
return | video height |
static | False |
C++ defination code:
int height()