Skip to content

请求添加venc多通道的支持,但由于libmaixcam_lib是闭源的,所以无法由社区贡献完整的实现 #96

@mcpanl

Description

@mcpanl

由于sg2002支持多通道venc,但是我们在代码中写死了只使用通道1,所以h264编码和rtsp无法同时运行,即使在代码中修改为不同的通道,也会出现初始化错误或运行时错误,例如无效的通道号、h264和h265无法在同一时间使用(但实际上用的确实都是h264)

我尝试修改MaixCDK的源码,在构造函数中添加选择通道号,并将所有的Encoder相关的MMF_VENC_CHN改为了_venc_channel

-    Encoder::Encoder(std::string path, int width, int height, image::Format format, VideoType type, int framerate, int gop, int bitrate, int time_base, bool capture, bool block) {
+    Encoder::Encoder(std::string path, int width, int height, image::Format format, VideoType type, int framerate, int gop, int bitrate, int time_base, bool capture, bool block, int venc_channel) {
         _path = path;
         _width = width;
         _height = height;
@@ -239,6 +239,34 @@ namespace maix::video
         _start_encode_ms = 0;
         _encode_started = false;
         _block = block;
+        _venc_channel = venc_channel;
+
+
+
+        printf("************************************\n");
+        printf("********* VENC CHANNEL = %d *********\n", _venc_channel);
+
+    printf("Encoder Private Members:\n");
+    printf("_path: %s\n", _path.c_str());
+    printf("_width: %d\n", _width);
+    printf("_height: %d\n", _height);
+    printf("_format: %d\n", static_cast<int>(_format));
+    printf("_type: %d\n", static_cast<int>(_type));
+    printf("_framerate: %d\n", _framerate);
+    printf("_gop: %d\n", _gop);
+    printf("_bitrate: %d\n", _bitrate);
+    printf("_time_base: %d\n", _time_base);
+    printf("_need_capture: %s\n", _need_capture ? "true" : "false");
+    printf("_capture_image: %p\n", _capture_image);
+    printf("_camera: %p\n", _camera);
+    printf("_bind_camera: %p\n", _bind_camera);
+    printf("_start_encode_ms: %ld\n", _start_encode_ms);
+    printf("_encode_started: %s\n", _encode_started ? "true" : "false");
+    printf("_block: %s\n", _block ? "true" : "false");
+    printf("_venc_channel: %d\n", _venc_channel);
+
+        printf("************************************\n");
+
 
         err::check_bool_raise(format == image::Format::FMT_YVU420SP, "Encoder only support FMT_YVU420SP format!");
         video::VideoType video_type = _get_video_type(path.c_str(), type);
@@ -264,7 +292,7 @@ namespace maix::video
                     err::check_raise(err::ERR_RUNTIME, "init mmf failed!");
                 }
 
-                if (0 != mmf_add_venc_channel_v2(MMF_VENC_CHN, &cfg)) {
+                if (0 != mmf_add_venc_channel_v2(_venc_channel, &cfg)) {

但是即便如此,编译运行后仍然无法实现两个编码器同时工作

************************************
********* VENC CHANNEL = 2 *********
Encoder Private Members:
_path: 
_width: 1280
_height: 720
_format: 8
_type: 9
_framerate: 60
_gop: 50
_bitrate: 3000000
_time_base: 1000
_need_capture: false
_capture_image: 0
_camera: 0
_bind_camera: 0
_start_encode_ms: 0
_encode_started: false
_block: true
_venc_channel: 2
************************************

************************************
********* VENC CHANNEL = 1 *********
Encoder Private Members:
_path: 
_width: 640
_height: 480
_format: 8
_type: 9
_framerate: 30
_gop: 50
_bitrate: 3000000
_time_base: 1000
_need_capture: false
_capture_image: 0
_camera: 0
_bind_camera: 0
_start_encode_ms: 0
_encode_started: false
_block: true
_venc_channel: 1
************************************
264 and 265 encoding can only use one at the same time!
-- [E] Exception: : Runtime error: mmf venc init failed!



maix multi-media driver released.
ISP Vipipe(0) Free pa(0x8a52c000) va(0x0x3fefe3b000)
# 

通过查看私有so的信息,期望咱们能够在libmaixcam_lib.so中支持多通道,感谢!

(base) satuo@satuo-INVALID:~$ readelf -p .rodata libmaixcam_lib.so | grep "encoding can only use one at the same time"
  [  2908]  264 and 265 encoding can only use one at the same time!^M
(base) satuo@satuo-INVALID:~$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions