使用 Android 将实时视频流传输到服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22245537/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:42:32  来源:igfitidea点击:

Transfer real-time video stream to server using Android

androidvideovideo-streaming

提问by hguser

We have to capture the real-time video using Android Camera, and send them to the server, then other users would read them through the browser or something else.

我们必须使用 Android Camera 捕获实时视频,并将它们发送到服务器,然后其他用户将通过浏览器或其他方式读取它们。

I have Googled and searched at SO, and there are some examples about video stream app like:

我在 SO 上进行了 Google 搜索和搜索,并且有一些关于视频流应用程序的示例,例如:

1 Android-eye: https://github.com/Teaonly/android-eye

1 安卓眼:https: //github.com/Teaonly/android-eye

2 Spydroid-ipcamera:https://code.google.com/p/spydroid-ipcamera/

2 Spydroid-ipcamera:https: //code.google.com/p/spydroid-ipcamera/

However it seems that they have different environments, most of the apps will start an HTTP server for stream requests, then the client will visit the page through the local network and see the video.

不过好像他们的环境不同,大部分的app都会启动一个HTTP服务器来处理流请求,然后客户端会通过本地网络访问页面并查看视频。

Then the video stream source and the server are both the device like this: enter image description here

那么视频流源和服务器都是这样的设备: 在此处输入图片说明

But we need the internet support like this: enter image description here

但是我们需要这样的互联网支持: 在此处输入图片说明

So I wonder if there are any alternative ideas.

所以我想知道是否有任何替代的想法。

回答by Behnam

I can see you have designed the three stages correctly, in your second diagram.

我可以看到您在第二张图中正确设计了三个阶段。

So what you need is to determine how to choose among these protocols and how to interface them. No one can give you a complete solution but having completed an enterprise project on Android Video Streaming I will try to straighten your sight towards your goal.

因此,您需要确定如何在这些协议中进行选择以及如何连接它们。没有人可以给你一个完整的解决方案,但在完成了一个关于 Android Video Streaming 的企业项目后,我会努力让你的视线朝着你的目标前进。

enter image description here

在此处输入图片说明

There are three parts in your picture, I'll elaborate from left to right:

你的图分三部分,我从左到右详细说明:

1. Android Streamer Device

1.安卓流媒体设备

Based on my experience, I can say Android does well sending Camera streams over RTP, due to native support, while converting your video to FLV gives you headache. (In many cases, e.g. if later you want to deliver the stream on to the Android devices.)

根据我的经验,由于本机支持,我可以说 Android 通过 RTP 发送相机流的效果很好,而将视频转换为 FLV 会让您头疼。(在许多情况下,例如,如果稍后您想将流传送到 Android 设备上。)

So I would suggest building up on something like spyDroid.

所以我建议建立像spyDroid这样的东西

2. Streaming Server

2. 流媒体服务器

There are tools like Wowza Serverwhich can get a source stream and put it on the output of the server for other clients. I guess VLC can do this too, via File-->Stream menu, an then putting the RTSP video stream address from your spyDroid based app. But I have not tried it personally.

有像Wowza Server这样的工具可以获取源流并将其放在服务器的输出上以供其他客户端使用。我想 VLC 也可以做到这一点,通过 File-->Stream 菜单,然后从基于 spyDroid 的应用程序中放置 RTSP 视频流地址。但我没有亲自尝试过。

Also it is not a hard work to implement your own streamer server.

此外,实现您自己的流媒体服务器并不是一项艰巨的工作。

I'll give you an example:

我给你举个例子:

For Implementation of an HLS server, you just need three things:

对于 HLS 服务器的实现,您只需要三件事:

  1. Video files, segmented into 10 second MPEG2 chunks. (i.e. .ts files)
  2. An m3U8 playlist of the chunks.
  3. A Web Server with a simple WebService that deliver the playlist to the Clients (PC, Android, iPhone, mostly every device) over HTTP. The clients will then look up the playlist file and ask for the appropriate chunks on their according timing. Because nearly all players have built-in HLS support.
  1. 视频文件,分割成 10 秒的 MPEG2 块。(即 .ts 文件)
  2. 块的 m3U8 播放列表。
  3. 带有简单 WebService 的 Web 服务器,通过 HTTP 将播放列表传送到客户端(PC、Android、iPhone,主要是所有设备)。然后客户端将查找播放列表文件并根据他们的时间要求适当的块。因为几乎所有播放器都内置了 HLS 支持。

3. The Client-Side

3. 客户端

Based on our comments, I suggest you might want to dig deeper into Android Video Streaming.

根据我们的评论,我建议您可能想要更深入地研究 Android Video Streaming。

To complete a project this big, you need much more research. For example you should be able to distinguish RTP from RTSP and understand how they are related to each other.

要完成这么大的项目,您需要进行更多的研究。例如,您应该能够区分 RTP 和 RTSP,并了解它们之间的关系。

Read my answer hereto get a sense of state-of-the-art Video Streaming and please feel free to ask for more.

在这里阅读我的回答以了解最先进的视频流,请随时提出更多要求。

Hope you got the big picture of the journey ahead,

希望你对未来的旅程有大局观,

Good Luck and Have Fun

祝好运并玩得开心点

回答by David Jashi

Quite a general question, but I will try to give you a direction for research:

相当普遍的问题,但我会尝试为您提供研究方向:

First of all you will need answer several questions:

首先你需要回答几个问题:

1) What is the nature and purpose of a video stream? Is it security application, where details in stills are vital (then you will have to use something like MJPEG codec) or it will be viewed only in motion?

1) 视频流的性质和目的是什么?它是安全应用程序,其中静止图像的细节至关重要(那么您将不得不使用 MJPEG 编解码器之类的东西)还是只能在运动中查看?

2) Are stream source, server and clients on the same network, so that RTSPmight be used for more exact timing, or WAN will be involved and something more stable like HTTP should be used?

2) 流源、服务器和客户端是否在同一网络上,以便RTSP可以用于更精确的计时,或者会涉及 WAN 并且应该使用更稳定的东西,如 HTTP?

3) What is the number of simultaneous output connection? In other words, is it worth to pay for something like Wowzawith transcoding add-on(and maybe nDVRtoo) or Flussonic, or simple solution like ffserverwill suffice?

3)同时输出连接数是多少?换句话说,是否值得为像Wowza 这样的带有转码附加组件(也可能是nDVR)或Flussonic 的东西付费,或者像ffserver这样的简单解决方案就足够了?

To cut long story short, for a cheap and dirty solution for couple of viewers, you may use something like IP Webcam-> ffserver-> VLC for Androidand avoid writing your own software.

长话短说,对于几个观众来说,这是一个廉价而肮脏的解决方案,您可以使用类似IP 网络摄像头-> ffserver-> VLC for Android 之类的东西,避免编写自己的软件。

回答by Gaskoin

You can handle it this way:

你可以这样处理:

Prepare the camera preview in the way described here. The Cameraobject has a setPreviewCallbackmethod in which you register the preview callback. This callback provides data buffer (byte array) in YUV format that you can stream to your server.

按照此处描述的方式准备相机预览。该相机对象有一个setPreviewCallback在您注册的预览回调方法。此回调提供 YUV 格式的数据缓冲区(字节数组),您可以将其流式传输到您的服务器。