HowTo: Live streaming video/audio from VLC to your Android device (self.Android)
2011-10-08 15:27
525 查看
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.
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).
The general command-line you need to run VLC with is as follows:
(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
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
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.
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
If you're on Windows create a batch file (a text file with the extension ".bat") with the above command-line, but replace
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:
(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
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
4000
when you try to bookmark them. Dolphin Browser (Android Market), however, bookmarks them just fine.)
see here (or ask below) for more info, and don't forget to edit the .hosts file in the
- just ask in the comments if you'd like more details.
Happy streaming!
(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=5000delays 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 fileIf 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 %9and 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
4000
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\httpdirectory 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!
相关文章推荐
- How to download streaming audio or video media from the internet using the MMS protocol?
- Android Streaming Live Camera Video to Web Page
- react-native爬坑之旅-unable to load script from assets'index.android.bundle'.Make sure your bundle is pa
- How to install Google Apps (GApps) on your Android Device / Phone
- How to stream video to your android phone 如何将视频远程传输至你的android手机?
- All you need to know about tethering with your Android device
- ffmpeg 音频转换: use ffmpeg convert the audio from stereo to mono without changing the video part
- From Zero to Boot: Porting Android to your ARM platform
- 3 Possible Ways for Real-Time Video Streaming Between Camera and Android Device Read more at http://
- How to retrieve the Device Unique ID from android device
- How to export apk from Android device?
- Belkin introduces WeMo light switch, control your household lighting from your Android device
- From Zero to Boot: Porting Android to your ARM platform
- Uploading audio, video or image files from Android to php server.
- Streaming live video from ios(ios 流媒体)
- with ffmpeg to encode video for live streaming and for recording to files for on-demand playback
- Android Video Playback----from Framework to Driver
- How To Create a Full Android Phone or Tablet Backup Without Rooting or Unlocking Your Device
- How to distribute your own Android library through jCenter and Maven Central from Android Studio
- To fetch EDID from android device