简体   繁体   English

通过WiFi从一部Android手机直播视频

[英]Live-stream video from one android phone to another over WiFi

I have searched the internet for days now on how to implement a video streaming feature from an android phone to another android phone over a WiFi connection but I can't seem to find anything useful. 我已经在互联网上搜索了几天如何通过WiFi连接从Android手机到另一个Android手机实现视频流功能,但我似乎找不到任何有用的东西。 I looked on android developers for sample code, stackoverflow, google, android blogs but nothing. 我看了Android开发人员的示例代码,stackoverflow,谷歌,Android博客,但没有。 All I can find are some sort of phone-to-desktop or desktop-to-phone solutions for streaming, but nothing that I can borrow in my implementation. 我能找到的只是某种用于流媒体的手机到桌面或桌面到手机的解决方案,但我在实施中无需借用。

I need to control a robot using an arduino ADK, so I am using 2 phones, one which will be mounted on the robot and another which will receive the video stream from the robot. 我需要使用arduino ADK控制机器人,因此我使用2个电话,一个将安装在机器人上,另一个将接收来自机器人的视频流。 I am mentioning this because I am trying to achieve the smallest delay between the broadcast time and the viewing time. 我提到这个是因为我试图在广播时间和观看时间之间实现最小的延迟。

I am writing 2 apps, one master app to control the robot(from the handheld phone) which will control the slave app and receive the stream, and the second slave app which will run on the robot-strapped phone, controlling the motors/actuators/streaming to master app. 我正在编写2个应用程序,一个用于控制机器人的主应用程序(来自手持电话),它将控制从应用程序并接收流,以及第二个从应用程序,它将在机器人绑定的手机上运行,​​控制电机/执行器/流媒体到主应用程序。 I can not use third party apps unfortunately. 不幸的是,我不能使用第三方应用程序。 I need to integrate the video stream code into my 2 apps. 我需要将视频流代码集成到我的2个应用程序中。

What options are there for achieving this? 实现这一目标有哪些选择? Also is it very hard to do because I never worked with videostreaming, tough I am doing pretty good in both Java and Android development. 这也很难做到,因为我从未使用过视频流,我在Java和Android开发方面做得非常好。 How should I encode/decode the stream, how do I initiate the connection, will I need to work with UDP instead of TCP/IP ? 我应该如何编码/解码流,如何启动连接,是否需要使用UDP而不是TCP / IP? I really don't know where to start, with no sample code anywhere. 我真的不知道从哪里开始,没有任何示例代码。 I am pretty sure this can be achieved. 我很确定这可以实现。 I just can't find anything useful to get me started in the right direction. 我找不到任何有用的东西让我开始朝着正确的方向前进。

I stumbled across spydroid but it is using VLC on a desktop so its no good for me. 我偶然发现spydroid,但它在桌面上使用VLC,所以对我没有好处。


EDIT: Check out Cagney Moreau's blog . 编辑:查看Cagney Moreau的博客 He goes into details about implementing this. 他详细介绍了如何实现这一点。

If you do not need the recording and playback functionality in your app, using off-the-shelf streaming app and player is a reasonable choice. 如果您不需要在应用中使用录制和播放功能,则使用现成的流媒体应用和播放器是一个合理的选择。

If you do need them to be in your app, however, you will have to look into MediaRecorder API (for the server/camera app) and MediaPlayer (for client/player app). 但是,如果您确实需要它们在您的应用程序中,则必须查看MediaRecorder API(用于服务器/相机应用程序)和MediaPlayer (用于客户端/播放器应用程序)。

Quick sample code for the server: 服务器的快速示例代码:

// this is your network socket
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
mCamera = getCameraInstance();
mMediaRecorder = new MediaRecorder();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// this is the unofficially supported MPEG2TS format, suitable for streaming (Android 3.0+)
mMediaRecorder.setOutputFormat(8);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mediaRecorder.setOutputFile(pfd.getFileDescriptor());
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
mMediaRecorder.prepare();
mMediaRecorder.start();

On the player side it is a bit tricky, you could try this: 在玩家方面它有点棘手,你可以试试这个:

// this is your network socket, connected to the server
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(pfd.getFileDescriptor());
mMediaPlayer.prepare();
mMediaPlayer.start();

Unfortunately mediaplayer tends to not like this, so you have a couple of options: either (a) save data from socket to file and (after you have a bit of data) play with mediaplayer from file, or (b) make a tiny http proxy that runs locally and can accept mediaplayer's GET request, reply with HTTP headers, and then copy data from the remote server to it. 不幸的是,媒体播放器往往不喜欢这样,所以你有几个选择:(a)从socket到文件保存数据和(在你有一些数据之后)从媒体播放媒体播放器,或者(b)制作一个小的http在本地运行的代理,可以接受媒体播放器的GET请求,使用HTTP标头进行回复,然后将数据从远程服务器复制到它。 For (a) you would create the mediaplayer with a file path or file url, for (b) give it a http url pointing to your proxy. 对于(a),您将使用文件路径或文件URL创建媒体播放器,以便(b)为其指定一个指向您的代理的http URL。

See also: 也可以看看:

Stream live video from phone to phone using socket fd 使用socket fd将实时视频从手机传输到手机

MediaPlayer stutters at start of mp3 playback MediaPlayer在mp3播放开始时口吃

I did work on something like this once, but sending a video and playing it in real time is a really complex thing. 我曾经做过类似这样的事情,但发送视频并实时播放是一件非常复杂的事情。 I suggest you work with PNG's only. 我建议你只使用PNG。 In my implementation What i did was capture PNGs using the host camera and then sending them over the network to the client, Which will display the image as soon as received and request the next image from the host. 在我的实现中我所做的是使用主机摄像头捕获PNG,然后通过网络将它们发送到客户端,它将在收到后立即显示图像并从主机请求下一个图像。 Since you are on wifi that communication will be fast enough to get around 8-10 images per-second(approximation only, i worked on Bluetooth). 由于你在wifi上,通信速度足够快,每秒可以获得8-10张图像(仅近似,我使用的是蓝牙)。 So this will look like a continuous video but with much less effort. 所以这看起来像一个连续的视频,但努力更少。 For communication you may use UDP sockets(Faster and less complex) or DLNA (Not sure how that works). 对于通信,您可以使用UDP套接字(更快,更简单)或DLNA(不确定如何工作)。

You can use IP Webcam , or perhaps use DLNA. 您可以使用IP网络摄像头 ,也可以使用DLNA。 For example Samsung devices come with an app called AllShare which can share and access DLNA enabled devices on the network. 例如,三星设备附带一个名为AllShare的应用程序,可以共享和访问网络上支持DLNA的设备。 I think IP Webcam is your best bet, though. 我认为IP网络摄像头是你最好的选择。 You should be able to open the stream it creates using MX Video player or something like that. 您应该能够使用MX视频播放器或类似的东西打开它创建的流。

You can check the android VLC it can stream and play video, if you want to indagate more, you can check their GIT to analyze what their do. 你可以检查它可以流媒体和播放视频的Android VLC ,如果你想更多地传达,你可以检查他们的GIT来分析他们的行为。 Good luck! 祝好运!

暂无
暂无

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

相关问题 通过WiFi从一台Android手机到另一台Android手机的实时流视频 - Live-stream video from one android phone to another android phone over WiFi 从一部android / ios手机到另一部android / ios手机的实时流视频 - Live-stream video from one android/ios phone to another android/ios phone 通过蓝牙将视频从一台Android手机实时流向另一台 - Live-stream video from one android phone to another via bluetooth 在Android中通过网络套接字从一个手机播放实时视频流到另一个手机 - Play Live Video Stream from one Mobile to another Mobile over network Socket in android 是否可以通过 WiFi 将实时 stream 从一个应用程序发送到 Android 中的另一个应用程序 - Is it possible to send a live stream from one app to another in Android via WiFi android wifi直接实时摄像头视频流 - android wifi direct live camera video stream 来自 Exoplayer PlayerNotificationManager 的多次和频繁播放通知,用于使用 exoplayer2 播放的直播视频 - Multiple and frequent playback notifications from Exoplayer PlayerNotificationManager for live-stream video played using exoplayer2 通过wifi将视频流传输到android设备 - Stream video to android devices over wifi Stream 使用套接字 fd 从手机到手机的实时视频 - Stream live video from phone to phone using socket fd 如何首先将数据包从一个Android手机发送到wifi路由器,然后再从路由器发送到另一个Android手机? - how to send packets first to wifi router form one android phone and then from router to another android phone??
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM