Skip to content

Commit

Permalink
* fix venc bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed May 23, 2024
1 parent cb08d57 commit 4feeded
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion components/vision/include/maix_video.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace maix::video
* @return raw data
* @maixpy maix.video.Frame.to_bytes
*/
Bytes *to_bytes(bool copy) {
Bytes *to_bytes(bool copy = false) {
Bytes *b = NULL;
if (copy) {
b = new Bytes(_data, _data_size, true, true);
Expand Down
27 changes: 17 additions & 10 deletions components/vision/port/maixcam/maix_video_mmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ namespace maix::video
switch (_type) {
case VIDEO_H265_CBR:
{
if (0 != mmf_init()) {
err::check_raise(err::ERR_RUNTIME, "init mmf failed!");
}

if (0 != mmf_enc_h265_init(MMF_VENC_CHN, _width, _height)) {
err::check_raise(err::ERR_RUNTIME, "init mmf enc failed!");
}
Expand All @@ -64,8 +68,13 @@ namespace maix::video
.gop = _gop,
.intput_fps = _framerate,
.output_fps = _framerate,
.bitrate = _bitrate,
.bitrate = _bitrate / 1000,
};

if (0 != mmf_init()) {
err::check_raise(err::ERR_RUNTIME, "init mmf failed!");
}

if (0 != mmf_add_venc_channel(MMF_VENC_CHN, &cfg)) {
err::check_raise(err::ERR_RUNTIME, "mmf venc init failed!");
}
Expand Down Expand Up @@ -205,7 +214,6 @@ namespace maix::video
}
} else { // encode from camera
if (!this->_bind_camera) {
log::warn("You need use bind_camera() function to bind the camera!\r\n");
goto _exit;
}

Expand Down Expand Up @@ -315,23 +323,23 @@ namespace maix::video
err::check_raise(err::ERR_RUNTIME, "get venc config failed!\r\n");
}

int img_w = img->width();
int img_h = img->height();
image::Format img_fmt = img->format();
int img_w = width;
int img_h = height;
int mmf_fmt = format;
if (img_w != cfg.w
|| img->height() != cfg.h
|| img->format() != mmf_invert_format_to_maix(cfg.fmt)) {
|| img_h != cfg.h
|| mmf_fmt != cfg.fmt) {
log::warn("image size or format is incorrect, try to reinit venc!\r\n");
mmf_del_venc_channel(MMF_VENC_CHN);
cfg.w = img_w;
cfg.h = img_h;
cfg.fmt = mmf_invert_format_to_mmf(img_fmt);
cfg.fmt = mmf_invert_format_to_mmf(mmf_fmt);
if (0 != mmf_add_venc_channel(MMF_VENC_CHN, &cfg)) {
err::check_raise(err::ERR_RUNTIME, "mmf venc init failed!\r\n");
}
_width = img_w;
_height = img_h;
_format = img_fmt;
_format = (image::Format)mmf_invert_format_to_maix(mmf_fmt);
}

if (mmf_venc_push(MMF_VENC_CHN, (uint8_t *)data, width, height, format)) {
Expand Down Expand Up @@ -819,7 +827,6 @@ namespace maix::video
}
} else { // encode from camera
if (!this->_bind_camera) {
log::warn("You need use bind_camera() function to bind the camera!\r\n");
goto _exit;
}

Expand Down
4 changes: 3 additions & 1 deletion examples/video_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ int _main(int argc, char* argv[])
int width = 640;
int height = 480;
video::VideoType type = video::VIDEO_H264_CBR;
video::Encoder e = video::Encoder(width, height, image::Format::FMT_YVU420SP, type);
video::Encoder e = video::Encoder(2560, 1440, image::Format::FMT_YVU420SP, type);
camera::Camera cam = camera::Camera(width, height, image::Format::FMT_YVU420SP);

while(!app::need_exit()) {
Expand All @@ -270,6 +270,7 @@ int _main(int argc, char* argv[])
bool capture = true;
video::Encoder e = video::Encoder(width, height, image::Format::FMT_YVU420SP, type, framerate, gop, bitrate, time_base, capture);
camera::Camera cam = camera::Camera(width, height, image::Format::FMT_YVU420SP);
display::Display disp = display::Display();
e.bind_camera(&cam);

char *file = (char *)"output.h264";
Expand All @@ -279,6 +280,7 @@ int _main(int argc, char* argv[])
while(!app::need_exit()) {
video::Frame *frame = e.encode();
image::Image *img = e.capture();
disp.show(*img);
printf("frame data:%p size:%ld pts:%ld dts:%ld\r\n",
frame->data(), frame->size(), frame->get_pts(), frame->get_dts());
printf("image size:%d\r\n", img->data_size());
Expand Down

0 comments on commit 4feeded

Please sign in to comment.