gpt4 book ai didi

c++ - OpenCV 从命名管道 (fifo) 到 ffplay

转载 作者:搜寻专家 更新时间:2023-10-31 01:33:57 25 4
gpt4 key购买 nike

我一直在使用 C++ 从 OpenCV 处理视频。我尝试将图像从 OpenCV 处理后传输到命名管道,最终目标是使用带有 VLC 或 NodeJS 服务器的网络服务器重新发布流。

我卡住的地方是 OpenCV 的输出似乎没有正确处理。视频总是有伪影,即使它应该是原始视频。

enter image description here

int main(int argc, char** argv)
{

VideoCapture camera(argv[1]);

float fps = 15;

// VLC raw video
printf("Run command:\n\ncat /tmp/myfifo | cvlc --demux=rawvideo --rawvid-fps=%4.2f --rawvid-width=%.0f --rawvid-height=%.0f --rawvid-chroma=RV24 - --sout \"#transcode{vcodec=h264,vb=200,fps=30,width=320,height=240}:std{access=http{mime=video/x-flv},mux=ffmpeg{mux=flv},dst=:8081/stream.flv}\""
,fps
,camera.get(CV_CAP_PROP_FRAME_WIDTH)
,camera.get(CV_CAP_PROP_FRAME_HEIGHT)
);


// ffplay raw video
printf("Run command:\n\ncat /tmp/myfifo | ffplay -f rawvideo -pixel_format bgr24 -video_size %.0fx%.0f -framerate %4.2f -i pipe:"
,camera.get(CV_CAP_PROP_FRAME_WIDTH)
,camera.get(CV_CAP_PROP_FRAME_HEIGHT)
,fps
);

int fd;
int status;

char const * myFIFO = "/tmp/myfifo";

if ((status = mkfifo(myFIFO, 0666)) < 0) {
// printf("Fifo mkfifo error: %s\n", strerror(errno));
// exit(EXIT_FAILURE);
} else {
cout << "Made a named pipe at: " << myFIFO << endl;
}

cout << "\n\nHit any key to continue after running one of the previously listed commands..." << endl;
cin.get();

if ((fd = open(myFIFO,O_WRONLY|O_NONBLOCK)) < 0) {
printf("Fifo open error: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}

while (true)
{
if (waitKey(1) > 0)
{
break;
}

Mat colorImage;
camera >> colorImage;

// method: named pipe as matrix writes data to the named pipe, but image has glitch
size_t bytes = colorImage.total() * colorImage.elemSize();

if (write(fd, colorImage.data, bytes) < 0) {
printf("Error in write: %s \n", strerror(errno));
}
}

close(fd);

exit(EXIT_SUCCESS);
}

最佳答案

它在我的身上运行良好...如果您从 open() 调用中删除 O_NONBLOCK

此外,而不是使用:

cat /tmp/myfifo | ffplay .... -i pipe:

你可以简单地使用:

ffplay ... -i /tmp/myfifo

关于c++ - OpenCV 从命名管道 (fifo) 到 ffplay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40454019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com