如何在 C++ 中使用 ffmpeg 流式传输 opencv Mat
How to stream a opencv Mat with ffmpeg in c++
我是新来的。我正在尝试使用 ffmpeg 在 LAN 上流式传输一些使用 opencv 处理的图像。
我看到了这个:
Pipe raw OpenCV images to FFmpeg
但它对我不起作用,它只会产生噪音。我认为我发送的数据格式不正确。
我也看看这个:
但是(查看最后一个答案)选项 -f jpeg_pipe 给我错误。
我现在在做什么:
- 我有一个名为 "composedImage"
的 RGB 垫
- 我发送输出:
std::cout << 组合图像;
输出是由逗号分隔的像素值
- 然后我调用:
./例子 | ffmpeg -f rawvideo -pixel_format bgr24 -video_size 160x120 -framerate 20 -i - -f udp://192.168.1.79:1234
- 我尝试使用 VLC(没用)和 ffplay 阅读:
ffplay -f rawvideo -pixel_format 灰色 -video_size 160x120 -framerate 30 udp://192.168.1.79:1234
这里看起来很简单:
http://ffmpeg.org/ffmpeg-formats.html#rawvideo
我也试过写图发了,还是有错误。可能它会在图像完成之前尝试发送。
感谢您的帮助。
我设法进行了流式传输,尽管质量不佳,也许一些 ffmpeg 专家可以帮助解决 ffmpeg 命令问题。
#include <iostream>
#include <opencv2/opencv.hpp>
#include <vector>
using namespace cv;
int main() {
VideoCapture cap("Your video or stream goes here");
Mat frame;
std::ios::sync_with_stdio(false);
while (cap.read(frame)) {
for (size_t i = 0; i < frame.dataend - frame.datastart; i++)
std::cout << frame.data[i];
}
return 0;
}
然后像
一样将其通过管道传输到 ffmpeg
./test | ffmpeg -f rawvideo -pixel_format bgr24 -video_size 1912x796 -re -framerate 20 -i - -f mpegts -preset ultrafast udp://127.0.0.1:1234
然后用 ffplay mpv 或其他什么播放它
ffplay udp://127.0.0.1:1234
我是新来的。我正在尝试使用 ffmpeg 在 LAN 上流式传输一些使用 opencv 处理的图像。
我看到了这个:
Pipe raw OpenCV images to FFmpeg
但它对我不起作用,它只会产生噪音。我认为我发送的数据格式不正确。
我也看看这个:
我现在在做什么:
- 我有一个名为 "composedImage" 的 RGB 垫
- 我发送输出: std::cout << 组合图像; 输出是由逗号分隔的像素值
- 然后我调用:
./例子 | ffmpeg -f rawvideo -pixel_format bgr24 -video_size 160x120 -framerate 20 -i - -f udp://192.168.1.79:1234
- 我尝试使用 VLC(没用)和 ffplay 阅读:
ffplay -f rawvideo -pixel_format 灰色 -video_size 160x120 -framerate 30 udp://192.168.1.79:1234
这里看起来很简单: http://ffmpeg.org/ffmpeg-formats.html#rawvideo
我也试过写图发了,还是有错误。可能它会在图像完成之前尝试发送。
感谢您的帮助。
我设法进行了流式传输,尽管质量不佳,也许一些 ffmpeg 专家可以帮助解决 ffmpeg 命令问题。
#include <iostream>
#include <opencv2/opencv.hpp>
#include <vector>
using namespace cv;
int main() {
VideoCapture cap("Your video or stream goes here");
Mat frame;
std::ios::sync_with_stdio(false);
while (cap.read(frame)) {
for (size_t i = 0; i < frame.dataend - frame.datastart; i++)
std::cout << frame.data[i];
}
return 0;
}
然后像
一样将其通过管道传输到 ffmpeg./test | ffmpeg -f rawvideo -pixel_format bgr24 -video_size 1912x796 -re -framerate 20 -i - -f mpegts -preset ultrafast udp://127.0.0.1:1234
然后用 ffplay mpv 或其他什么播放它
ffplay udp://127.0.0.1:1234