» Linux and apple tv

Home / Linux / Linux and apple tv


pple does great in making their devices work together. The other side of the coin is that this is strictly limited to apple devices and they have to be new. So does the apple tv (generation 3) work great for me to combine with my iPhone 4S, quite good with original iPad, bad with an older MacBook pro and very bad for my Linux desktop pc. There are many solutions I found to do some magic also with a Linux operating system but i wanted a bit more comfort. That was why i created a ruby gem to offer a simple command line tool to send images and video files over the airplay protocol to an airplay device. You can find the project hosted on github and the gem hosted at rubygems. This post should give you an idea how you can use the tool and what it hopefully should bring you in near future.

First of all you have to check the ip-address of your apple tv in your network. The easiest way is to check the network settings in the apple tv menu. For private home-networks it usually should be something like 192.168.1.x. This is what you have to tell airstream (actually version 0.3.4) to know where to send the media files. For now we are ready to go…

Prerequisite is to have a running System with rubygems installed. Please notice that there is no key control support for windows yet. Maybe i will integrate later.

The airstream gem does resolve some dependencies that need additional libraries like openssl or dnssd. You will have to pre-install on your system. If you have any troubles while install please let me know, I will try to help as soon as possible.

First lets send some images to devices. First line does simple send the picture on http://i.imgur.com/3Li93l.png to the device with ip-address After that we send some local files…

The last command will send all png files in directory rofl to the device, the pictures will switch all 8 seconds. You can change the Interval with the -n option.

I choose to create a separate command for sending images because the main feature of airstream is to send video files although I wanted to offer other features.

Sending video files does work like sending image files. First call of airstream creates a configuration file where you can set default options e.g. not always to set your ip-address for the device.

For now (version 0.3.4) you can skip to the next video pressing s and quit using q I am on to integrate as much controls as possible, contact for any suggestions.

Somehow I also plan to offer direct streaming to the device which can be used in many purposes. Do not expect the solution to work playing bleeding edge games on your tv ;)

Some side-notes…
Getting the ip-address of the device, for now it was the most secure way to always communicate to the receiver. I tried with dnssd but it was not always successful in finding my device. Although I will try to integrate this feature somehow later.


Dec 04 / Keiran "Affix" Smith:

Very nice however streaming an m3u doesn't work properly. It will only play for a few seconds then stop..

Dec 06 / unused:

thx - i did not test with m3u, that is afaik mp3-playlists. please consider that audio playback is not yet implemented. hopefully i will make that work within a month. i will check it anyhow, can you provide any example file?.

Jan 08 / Magnus:

Hi, I am I correct in understanding that this can currently stream video from my linux machine to AirPlay devices like Apple TV? Also, when you say "direct streaming" do you mean mirroring of a desktop? Btw. I really hope you keep working on this project, as this os the only option I've seen out there for sending music / video from a linux machine to my Apple TV. Best wishes, Magnus.

Jan 08 / Magnus:

Just tested this out and it works great for short videos, tv-episodes and such, though I'm unsure of which formats it actually supports? Images also work without a hitch. So af Awesome! Hoever, trying anything larger (movies ~700mb) results in the loading.............. to just continue on forever, after about 15 seconds of which, the apple tv says "An error occurred loading this content." & "Try again later", but on my computer the loading... just goes on, and I have to double tap Ctrl-C to break out..

Jan 09 / unused:

Hi Magnus, the airplay protocol can basically play videos in mpeg-4 (mp4, mov, ts, m4v) format. There are still some issues with the tool, e.g. there are some situations the input capture will not work to quit the application. I'll keep on working to get it more stable, with full more features (more controls, audio, etc.). Mirroring of the screen is something I just hope to get working but it has low priority to me for the moment. If you have any issues, ideas or suggestions just contact me. You can keep track on the development on github, I was quite busy last months but I'm looking forward to get some improvements soon. Regards!.

Jan 09 / Magnus:

Your efforts are definitely appreciated! I checked up on the files I was feeding to the AppleTV and you were right about the ones working being mp4's. I will try with larger mp4's as soon as I can find some and let you know if there are any issues with those. Am I correct in assuming that for any other file formats to work "live", they would have to be re-encoded on the fly to a mp4 format then? I guess mirroring would solve any codec issues but I can very well understand your desire to focus on one thing at a time and thereof the need to prioritize :-) Thanks for the great work!.

Jan 09 / unused:

I'm afraid you will have to convert those files for now - if I find any other solution I will notice you..

Jan 11 / Magnus:

Thanks, I've had the same problem with the android app "AirSync" for the DoubleTwist player, exact same files, and had asked for their help, being then told it was a known issue. When I asked them, after reading your reply, wether this was due to the same issue with the file formats, they told me yes.. I would have liked to have know that before shelling out for the application that they simply claimed could: "Stream music, videos and photos to the Xbox 360, PS3, Sonos, and Apple TV (black model)." http://support.doubletwist.com/doubletwist/topics/streaming_larger_files_700mb_from_android_fails_while_smaller_ones_work ---- Can you perhaps enlighten me on how the mirroing technology works, if the video is somehow encoded real time, or wether it's just transmitted in an uncompressed format with a bitrate and quality thereof limited by the network capacity?.

Jan 12 / unused:

The file-size should be no problem at all, I just tested an 2.1 GB file and it worked just fine. I suppose either the file is in wrong format/codec or the video file is somehow corrupted (i usually test with mplayer). Unfortunately I did not yet succeed in finding the one solution for encoding video files for the device. If you are interested in screen mirroring you can check the unofficial airplay protocol..

Jan 13 / Magnus:

Thanks. I've tried a larger 1.4 GB file as well and it works fine as long as it's mp4. I just checked out the mirroring protocol, and hope that it gets an open source implementation one day. Would be awesome if it could be set as an external display device in Ubuntu for example..

Jan 20 / Kalle:

Thank you so much !!! Been looking for a commandline airplay sender, so I could ditch my windows machine with itunes running..

Feb 19 / Ferg:

Wicked, I've been waiting for something like this! With Fedora 18 I installed with: ' yum install avahi-compat-libdns_sd-devel rubygem-gem-nice-install ' and then gem installed airstream 0.3.7 without an issue. The pics will display (approx 3-4 seconds), but the movies won't play (I'll get an error message on the ATV). I tried several .mp4's and a .mov. I was using an up to date ATV2. Can I send you a log of some sort?.

Feb 22 / ferg:

Hey... so I found my problem, firewall... doh!! I also made an easy install guide for Fedora: http://np.reddit.com/r/Fedora/comments/1909l6/push_video_and_images_to_atv_with_linux_with/.

Feb 22 / unused:

Hi Ferg, thank you for the guide, I'm happy you could figure out the problem yourself. Actually I'm working on writing tests for the system and also to improve the output on errors. The software is published on github, you're welcome to leave a message or open issues if you have any troubles or suggestions. Regards!.

Mar 20 / Zack:

Just what I was looking for! Thank you. I look forward to SSHing commands from my phone to my desktop computer to watch my video. Btw for future installers -- if you get "unable to find dnssd header", run some libraries: sudo apt-get install libavahi-compat-libdnssd-dev.

May 10 / weruminger:

Hi. Airplay is a very good software. It is easy to use, works fine and is stable. I'd no experiance in ruby (till now), so please , is it possible to feed airplay with piped stuff like: cat myFavoriteFil.mp4 | airplay -- in standart it does not work (it seem to set a position in the given file). Any how. You'd mad a good work and if you do not have time to investigate in a solution, i'll have a look into it (may by i learn something about ruby :-) ) good luck , from Weruminger (germany).

May 10 / unused:

Hi Weruminger, it is airstream - airplay is the protocol used. You cannot pipe anything to airstream for now, but play remote or local files with airstream myFavoriteFil.mp4. If you have any questions do not hesitate to contact me (even in deutsch via mail if you want to). Regards!.

Jun 20 / mugshooter:

Hi! I got no experience with RubyGem, would you please guide me abit? I got this error while trying to "gem install airstream --------- Building native extensions. This could take a while... ERROR: Error installing airstream: ERROR: Failed to build gem native extension. /usr/bin/ruby1.8 extconf.rb checking for dns_sd.h... no unable to find dnssd header *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: ... Gem files will remain installed in /var/lib/gems/1.8/gems/dnssd-2.0 for inspection. Results logged to /var/lib/gems/1.8/gems/dnssd-2.0/ext/dnssd/gem_make.out.

Jun 24 / mugshooter:

Thanks, yeah! I did "apt-get install libavahi-compat-libdnssd-dev" and installed airstream without errors. Now I get syntax error when running any airstream command. Same error if i run "airstream --version" as "airimg http://www.img.com/ -o" Thanks for replying! Got a clue..? :) /usr/local/bin/airstream:23:in `load': /var/lib/gems/1.8/gems/airstream-0.3.7/bin/airstream:12: odd number list for Hash (SyntaxError) reciever: '', ^ /var/lib/gems/1.8/gems/airstream-0.3.7/bin/airstream:12: syntax error, unexpected ':', expecting '}' reciever: '', ^ /var/lib/gems/1.8/gems/airstream-0.3.7/bin/airstream:12: syntax error, unexpected ',', expecting $end from /usr/local/bin/airstream:23.

Jun 24 / mugshooter:

Sorry, check out the errors here :) http://pastebin.ubuntu.com/5796659/.

Sep 29 / linutec:

Hey! I'm also getting errors, trying to install your gem. My system is running with Linux Mint 15: - ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] - gem -v => 2.1.5 Getting the following error: --- sudo gem install airstream Building native extensions. This could take a while... ERROR: Error installing airstream: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb /usr/local/lib/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:53:in `require': cannot load such file -- mkmf (LoadError) from /usr/local/lib/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:53:in `require' from extconf.rb:1:in `' Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/dnssd-2.0 for inspection. Results logged to /usr/lib/ruby/gems/1.9.1/gems/dnssd-2.0/ext/dnssd/gem_make.out ---- Any hints or help would be awesome!.

Leave a Reply: