简体   繁体   English

使用ffmpeg从服务器流式传输视频帧

[英]Streaming video frames from server with ffmpeg

I am sending frames of a video in form of JPEG images to my server on RMTP stream. 我在RMTP流上将JPEG图像形式的视频帧发送到我的服务器。 At server side, I want to connect the stream (ip + port) to ffmpeg so that it can grab images from stream and create a video stream from them. 在服务器端,我想将流(ip +端口)连接到ffmpeg,以便它可以从流中获取图像并从中创建视频流。

Actually my server is listening on an IP and port for incoming frames. 实际上我的服务器正在侦听传入帧的IP和端口。 This part is done. 这部分完成了。 Where I am stuck is that how to convert these frames to a video stream using ffmpeg. 我遇到的问题是如何使用ffmpeg将这些帧转换为视频流。 Can anyone please tell me how to achieve this? 任何人都可以告诉我如何实现这一目标? I know image2pipe is what I should go with but I have not found its syntax and documentation on Google. 我知道image2pipe是我应该使用的,但我还没有在Google上找到它的语法和文档。

At the server side , you can invoke the cmd-line line application ffmpeg to do the heavy lifting for you and stream the data . 在服务器端 ,您可以调用cmd-line行应用程序ffmpeg为您执行繁重的工作并流式传输数据

At the client side , there are 2 approaches I want to discuss: 在客户端 ,我想讨论两种方法:

Approach 1 : use ffplay on the iPhone to connect to the server and display the video stream. 方法1 :使用iPhone上的ffplay连接服务器并显示视频流。

Pros : this is the easiest and fastest solution! 优点 :这是最简单,最快速的解决方案!

FFmpeg was ported to the iPhone by some people a long time ago, so you can just invoke ffplay from the iPhone, tell it to connect to the server and the job is done! 有些人很久以前就把FFmpeg移植到了iPhone上 ,所以你可以从iPhone调用ffplay ,告诉它连接到服务器并完成工作! Check Streaming a simple RTP audio stream from FFmpeg for a quick example. 检查流式传输来自FFmpeg的简单RTP音频流,以获得快速示例。

Cons : It seems that there are legal issues involved on this matter , so some people do not recommend distributing your app with FFmpeg. 缺点 :似乎在这个 问题上 涉及 法律问题 ,因此有些人不建议使用FFmpeg分发您的应用程序。

Approach 2 : write an application similar to ffplay for the iPhone. 方法2 :为iPhone编写类似于ffplay的应用程序。

Pros : You can have custom encode/decode procedures to protect the data being broadcasted and make everyone else in the world use your player to watch the stream. 优点 :您可以使用自定义编码/解码程序来保护正在广播的数据,并让世界上的其他人使用您的播放器来观看流。

If you are streaming a real JPEG (with headers and all, just like a regular JPEG file), the first thing you need is use a networking library to allow your application to connect to server and retrieve the data. 如果您要传输真正的JPEG(带有标题和所有标题,就像普通的JPEG文件一样),您首先需要使用网络库来允许您的应用程序连接到服务器并检索数据。

I suggest that for every new connection your server receives, it sends a custom header (a few bytes) informing the client about the size of each frame that is being sent (so the client knows the size of each frame). 我建议,对于服务器接收的每个新连接,它会发送一个自定义标头(几个字节),通知客户端正在发送的每个帧的大小(因此客户端知道每个帧的大小)。

After that, the app will need to use another library to interpret the incoming data as a JPEG frame/file. 之后,应用程序将需要使用另一个库将传入的数据解释为JPEG帧/文件。 I can think of OpenCV right now, but I'm sure you can find smaller libraries. 我现在可以想到OpenCV,但我相信你可以找到更小的库。 Maybe iOS offers a framework for this, but I really don't know. 也许iOS为此提供了一个框架,但我真的不知道。

Once your application has access to all the useful information that each frame carries (ie, image dimension and pixels) your app will create an UIImage with this information for every frame that arrives from the network, to be able to display them on the screen . 一旦您的应用程序访问了每个框架携带的所有有用信息(即图像尺寸和像素),您的应用程序将为从网络到达的每个帧创建一个包含此信息UIImage ,以便能够在屏幕上显示它们

Cons : You will have to create an application from scratch and probably learn a few new APIs on the way. 缺点 :您必须从头开始创建应用程序,并且可能会在途中学习一些新的API。

In fact there is 2 methods: 实际上有两种方法:

ffmpeg -i "rtmp://localhost/etc" out.flv

or 要么

rtmpdump -v -r rtmp://localhost/etc | ffmpeg -i - out.flv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM