What's new
Apple iPad Forum 🍎

Welcome to the Apple iPad Forum, your one stop source for all things iPad. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

HOWTO: Stream videos to Apple TV 2, using iPad under Ubuntu

DrHouse

iPF Noob
Joined
Jan 17, 2011
Messages
644
Reaction score
21
Location
Quebec
Website
www.ws4dl.org
Playing around with my iPad/iPhone and Ubuntu, I got an idea that could help Ubuntu Users who have an Apple TV 2...

The goal is to be able to stream any movie (mp4 format) from a local drive using the iPad/iPhone as the streamer to the Apple TV 2. First, I looked as a few free apps to see what was possible. In the end, I needed to download the movie on my device and then stream to the Apple TV 2. That's not what I wanted to do. I want the stream directly from the remote disk without having to download the file on my device.

So I figured out that some websites allow AirPlay to be used on their website... After a few searches, I found out how to embed a video in a webpage, so it would be airplayable using the iOS device. Here is the basic HTML 5 code:

Code:
<video controls='true' width='120' height='80' x-webkit-airplay='allow' src='somemovie.mp4'></video>
Next step was to create a webpage that would scan a folder, and embed all those movies into a HTML page...

So to make it quick, I created a small bash script to do the job. Of course, PHP or other web language can be used to do the same job, but I wanted to do a fast proof of concept...

Here is the script:

Code:
#!/bin/bash
echo "<HTML>">index.html
echo "<body>">>index.html
echo "<H3>Movies List</h3>">>index.html
for f in *.m4v; do
echo "$f<br>">>index.html
echo "<video controls='true' width='120' height='80' x-webkit-airplay='allow' src='$f'></video><br>">>index.html
done
echo "</body>">>index.html
echo "</HTML>">>index.html
You have to install Apache2 to have a webserver, and create a symlink in "/var/www/" that will point to your videos folder

Code:
sudo ln -s /home/patrick/Videos /var/www/videos
Run the script in the folder of your videos so it will create a file called "index.html". Then, using your iDevice, goto "http://192.168.1.6/videos" (Put your own ip adress, of course!)

The results will give you this (using my iPhone):

attachment.php


Then just play any movie and activate AirPlay towards your Apple TV 2...

This is a pretty basic script, but a lot more can be done. If you use some language like PHP, then you could scan dynamically for sub-folders, any supported media type, have more details about each movie, etc...

So that means for Ubuntu fellows, iTunes is not needed anymore if you want to watch your local movies on your Apple TV 2!

Have fun!
 

Attachments

  • IMG_0253.PNG
    IMG_0253.PNG
    44.2 KB · Views: 8,227
OP
DrHouse

DrHouse

iPF Noob
Joined
Jan 17, 2011
Messages
644
Reaction score
21
Location
Quebec
Website
www.ws4dl.org
AirPlay using pure HTML for Apache2 (or else)

Ok, I've made some more tests using my Ubuntu Laptop, an external USB hardrive and, yep, movies...

Since I was using an external hardrive, I had to give Apache2 my credentials so it could read my USB drive. Surely there is a better way, but, this is a proof of concept...

I've modified the script to create a lighther index.html page since the iPad is trying to create a thumbnail of all movies. This was giving some bottle neck on the USB drive. To solve that issue, I created a webpage called "viewer.html" which takes as parameter "movie" making it easy to reuse for each movie. No PHP is needed since all is done in javascript.

So basically, you run the script "updateFolder.sh" in the folder containing the movies (mp4/m4v). This will create a file "index.html". You have also to copy the "viewer.html" at the same location (Yes, I know, it could have been created automatically...).

In Apache2, make sure that the symlink is pointing to your movie folder. So the URL http://192.168.1.6/movies will end up loading the index.html file.

I used Apache2, but any webserver should work. Actually, it would even work in Windows with IIS but you would have to convert the script file to VBS or CMD file (Not just renaming it...)

Then, with your Safari on the iPad, you load that webpage, and you will have a list of all your movies. Click on one of them, and the viewer.html will be loaded with the title you selected. Click "Play" and watch your movie on your iPad, or redirect using AirPlay.

See attachements for the scripts and html files...
 

Attachments

  • AirPlayWithHTML.zip
    837 bytes · Views: 653

Most reactions

Latest posts

Top