Skip to content

EM2860 编程接口

V4L2 API(Linux)

EM2860 在 Linux 下使用标准 V4L2 (Video4Linux2) 编程接口。

打开设备

c
#include <fcntl.h>
#include <linux/videodev2.h>

int fd = open("/dev/video0", O_RDWR);
if (fd < 0) {
    perror("Failed to open device");
    return -1;
}

查询设备能力

c
struct v4l2_capability cap;
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) {
    printf("Driver: %s\n", cap.driver);   // "em28xx"
    printf("Card: %s\n", cap.card);       // "EM2860 Video Capture"
    printf("Bus: %s\n", cap.bus_info);    // "usb-xxx"
}

设置视频格式

c
struct v4l2_format fmt = {0};
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = 720;
fmt.fmt.pix.height = 576;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;

if (ioctl(fd, VIDIOC_S_FMT, &fmt) == -1) {
    perror("VIDIOC_S_FMT");
}

支持的像素格式

格式说明可用性
YUYVYUV 4:2:2 打包格式默认支持
UYVYYUV 4:2:2 打包格式(字节序反转)部分内核

DirectShow(Windows)

在 Windows 下,EM2860 通过标准 DirectShow Filter 暴露接口。

OpenCV 集成

python
import cv2

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)  # Windows
# 或
cap = cv2.VideoCapture(0)  # Linux (V4L2)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 720)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 576)

while True:
    ret, frame = cap.read()
    if not ret:
        break
    cv2.imshow('EM2860', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

FFmpeg 命令行

bash
# 采集 5 秒视频
ffmpeg -f v4l2 -video_size 720x576 -i /dev/video0 -t 5 output.mp4

# 采集单帧截图
ffmpeg -f v4l2 -video_size 720x576 -i /dev/video0 -vframes 1 capture.jpg

视端威科技 — 视频处理芯片与智能视觉解决方案提供商