使用 C++ 的视频流
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1825338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Video streaming using c++
提问by Amer
I'm going to build an application in c++ that creates stream of photos and then sends them as video stream to another application. any ideas about how can i start? what I mean is, what libraries should i use and what the encoding? I'm thinking about MJPEG, and UDP or RTP as protocol.... any help would be greatly appreciated.
我将在 C++ 中构建一个应用程序,该应用程序创建照片流,然后将它们作为视频流发送到另一个应用程序。关于如何开始的任何想法?我的意思是,我应该使用哪些库以及编码是什么?我正在考虑将 MJPEG、UDP 或 RTP 作为协议......任何帮助将不胜感激。
采纳答案by unwind
If your input data is just a bunch of random images, not video, you're not going to do "video streaming". You're just going to be sending a bunch of full images. No need to involve video encoding technology, just do the simplest possible transmission of images. Video encoders rely on each frame having various relationships to the previous, as is common in actual video. For inputs of random images, they're not going to be able to compress that much, and single-frame compression (e.g. JPEG/PNG/whatever) is very likely already going to be applied to your input data.
如果您的输入数据只是一堆随机图像,而不是视频,那么您就不会进行“视频流”。你只是要发送一堆完整的图像。无需涉及视频编码技术,只做最简单的图像传输。视频编码器依赖于与前一帧具有各种关系的每一帧,这在实际视频中很常见。对于随机图像的输入,它们将无法压缩那么多,并且单帧压缩(例如 JPEG/PNG/任何)很可能已经应用于您的输入数据。
Probably easiest to send the contents of each file, together with the original filename, and have the receiving client re-create the file on disk, and use existing disk-oriented libraries to open and decode the image.
可能最容易发送每个文件的内容以及原始文件名,并让接收客户端在磁盘上重新创建文件,并使用现有的面向磁盘的库来打开和解码图像。
You should probably just use TCP for this, nothing in your requirements that indicate you need to use the more complicated and error-prone UDP/RTP-based solutions.
您可能应该为此使用 TCP,您的要求中没有任何内容表明您需要使用更复杂且容易出错的基于 UDP/RTP 的解决方案。
回答by Bj?rn Pollex
For the streaming part you can use Live555. It should cover all you need. That still leaves the problem of generating an MJpeg Stream. I can only guess here, FFMpegmight be what you are looking for (as I see it also covers streaming, so you might only need this one). I think that MJpeg is very suited for you application. As for the TCP or UDP, that depends on how you want to use it. UDP makes sense if you want to make your stream Multicast, otherwise I would prefer TCP, because it is more reliable.
对于流媒体部分,您可以使用Live555。它应该涵盖您需要的所有内容。这仍然存在生成 MJpeg 流的问题。我只能在这里猜测,FFMpeg可能是您正在寻找的(因为我看到它也涵盖了流媒体,所以您可能只需要这个)。我认为 MJpeg 非常适合您的应用程序。至于 TCP 或 UDP,那取决于您想如何使用它。如果你想让你的流多播,UDP 是有意义的,否则我更喜欢 TCP,因为它更可靠。
Hope these are some useful hints.
希望这些是一些有用的提示。
回答by Himanshu
Use ffmpeg library for encoding your stream and use RTP/RTSP stack to stream them.
使用 ffmpeg 库对您的流进行编码,并使用 RTP/RTSP 堆栈来流式传输它们。