HowTo: Live streaming video/audio from VLC to your Android device (self.Android)

HowTo: Live streaming video/audio from VLC to your Android device (self.Android)

submitted 1 year ago by Shaper_pmp to Android

sorry, this has been archived and can no longer be voted on

I've been messing around trying to get VLC to automatically stream a copy of whatever it was playing to my HTC Magic (myTouch) across the local network, and a friend pointed out r/android may be interested in how to do so (so thank him if it's useful ;-).

This is Windows-centric because that's what I'm running, but it should be pretty obvious how to adapt it for Linux.

Notes

  • As space in self.posts is limited I'll just run through the basics here - if anyone wants more details on a particular step just ask and I'll try to answer it in the comments.
  • There are lots of VLC examples out there of how to transcode files for Android, and there are lots of examples of how to stream transcoded files, and there are lots of examples of how to transcode and stream which only specify certain parameters (which means some files will still refuse to transcode/stream properly, eg if framerate is unspecified and their frame-rate is wrong). This config is intended to specify every parameter necessary to convert any video into an android-compatible format - it's not perfect yet (the occasional file still fail to transcode when you open it), but I'll update this post if/when I manage to iron out the last few missing options).

VLC

Download the latest version of VLC - it should work with older versions, but you may have to change "oldhttp" to "http" on some older versions of VLC.

The general command-line you need to run VLC with is as follows:

"\path-to-vlc\vlc.exe" [filename1] [[filename2]...] -I qt -vv -f --extraintf oldhttp --sout "#duplicate{dst='display{delay=5000}',dst='transcode{fps=15,vcodec=mp4v,vb=500,scale=1,width=352,height=240,acodec=mp4a,ab=128,channels=2,samplerate=22050,deinterlace,audio-sync}:gather:rtp{sdp=rtsp://:1234/stream.sdp}'}" --sout-keep --no-sout-rtp-sap --no-sout-standard-sap"

(Where filename1, filename2 (etc) are the files you want to stream.)

This starts vlc and splits the input video file into two streams. One is displayed in a normal VLC window, while the other is resized and transcoded to MP4 (H.263 and AAC sound) and streamed out to the network via RTSP.

It also enables the 'http' interface, so you can use a web browser (or the excellent - and free! - VLC Remote from the Android Market) to start/stop the stream by remote control from your phone.

Things to note:

  • Transcoding takes some time, so the transcoded stream lags a few seconds behind the streamed one (about 5, on most of the systems I've tried it on). To keep them synchronised the delay=5000 delays output of the desktop stream by enough time (5000 milliseconds, = 5 seconds) for the transcoded stream to catch up. It makes the desktop window a tad unresponsive (videos pause for five seconds before playing, and the movie controls like play/pause take five seconds to take effect), so if you want a more responsive desktop window and don't care about synchronising the stream to the desktop version, just remove the whole {delay=5000}.
  • The transcoded stream is resized to 352x240 for display on mobile devices - you can increase this resolution, but be aware that Android only likes videos in certain resolutions and (as far as I can tell) VLC's H.263 encoder only likes to output videos in certain resolutions, so you have to find one that both the encoder and android are happy with.
  • We're transcoding to H.263 rather than H.264 because we're doing it in real-time - H.264 requires a lot more processor muscle to encode, and in my experiments few machines could encode it fast enough to keep up. For comparison, even my 15 year-old AMD Athlon 1800 XP can encode H.263 fast enough.
  • The resulting transcoded RTSP stream is available at rtsp://your-desktop-ip-address:1234/stream.sdp

An easy way to make this convenient is to create a batch file/shell-script/shortcut to either containing the above command-line on your desktop, then drag-and-drop files you want to watch onto it.

Android

Android can play RTSP streams, but for some reason only correctly recognises them as video streams when you click a link on a web page in the browser, not when they're typed into the browser's location box.

Hence you have to create an HTML file somewhere you can access it (on a local web server or on your SD card) that contains a hyperlink to rtsp://your-desktop-ip-address:1234/stream.sdp, then load that page in your browser and click the link in it to get the stream playing in the media player. It's an annoying wrinkle, but necessary (at least in Android 1.6).

Refinements

Desktop icon/batch file

If you're on Windows create a batch file (a text file with the extension ".bat") with the above command-line, but replace [filename1] [[filename2]...] with %1 %2 %3 %4 %5 %6 %7 %8 %9 and stick it on your desktop. You can now drag-and-drop up to nine files on the batch file and VLC will enqueue, play, transcode and stream all of them in order. (Batch files make it awkward to access the tenth and subsequent parameters, so if anyone knows how to specify "all parameters" in a batch file please let me know, or I'm going to have to write a perl script or something just for this tiny annoyance <:-)

If you're on linux I presume you know how to write a shell script to do it already. ;-)

I don't have a web-server handy to host the HTML file on!

In this case you'll need to create an HTML file, save it to your phone's SD card and open it in your browser.

Create an HTML file (a text file with the .html extension) containing the following:

<html><body><a href="rtsp://your-desktop-ip-address:1234/stream.sdp">Start stream</a></body></html>

and save it on your phone's SD card (you can create it on your desktop and save it to the SD card, or use ES File Manager and its built-in text editor and do it right on the phone).

Now open up your browser and go to:

content://com.android.htmlfileprovider/sdcard/path-on-your-sd-card/filename.html

(eg, if you called the HTML file "index.html" and saved it in a directory called "Streaming" on your SD card, the full URL would be content://com.android.htmlfileprovider/sdcard/Streaming/index.html... and, Windows people, remember that like Linux Android is case-sensitive.)

You should now see the HTML file displayed on your phone, and if you start a movie playing using the VLC command-line and click the link in your phone browser, you should see the video stream playing live on your phone.

(PROTIP: Android's built-in browser doesn't properly recognise content:// urls, so it seems to mangle the URL of files stored on the SD card when you try to bookmark them. Dolphin Browser (Android Market), however, bookmarks them just fine.)

Remote-Controlling VLC using Android's VLC Remote app

The only additional step you need for this is to enable and configure VLC's http interface - see here (or ask below) for more info, and don't forget to edit the .hosts file in the \path-to-vlc\http directory or VLC will only allow connections from the machine it's running on.

That's it!

That should be about it - there are other things you can do like using Any Cut (Android Market) to create a shortcut on your home screen to a custom intent that launches your HTML file in your phone's browser, but this howto is quite long enough already - just ask in the comments if you'd like more details.

Happy streaming!


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个 HTTP Live Streaming (HLS) 的视频链接,可以通过支持 HLS 的播放器进行播放,如 VLC、QuickTime、Safari 等。 您可以在浏览器中使用以下代码来嵌入播放器: ```html <video width="640" height="360" controls> <source src="http://122.224.62.26:7086/live/cameraid/1000010%2413/substream/2.m3u8" type="application/x-mpegURL"> </video> ``` 也可以使用支持 HLS 的 JavaScript 播放器库,如 Video.js、HLS.js 等。以下是一个使用 Video.js 的示例代码: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Video.js HLS Example</title> <link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet"> <script src="https://unpkg.com/video.js/dist/video.min.js"></script> <script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.min.js"></script> </head> <body> <video id="my-video" class="video-js" controls preload="auto" width="640" height="360"> <source src="http://122.224.62.26:7086/live/cameraid/1000010%2413/substream/2.m3u8" type="application/x-mpegURL"> </video> <script> var player = videojs('my-video'); player.play(); </script> </body> </html> ``` 这段代码中,我们使用 Video.js 播放器库来播放 HLS 视频。我们首先在 head 部分导入 Video.js 和 videojs-contrib-hls 库的 CSS 和 JavaScript 文件。然后在 body 部分创建一个 video 元素,并将 HLS 视频链接作为 source。在 JavaScript 部分,我们使用 videojs() 方法创建一个播放器实例,并调用 play() 方法以自动播放视频。 希望这能帮助您播放 HLS 视频。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值