Apple

iTunes sharing over the internet using Back to my Mac and ssh port forwarding

Monday, February 8th, 2010

I was at work the other week, doing a repetitive task of the sort that provides an opportunity to listen to music. I’d recently purchased an album and had stored it in the iTunes library on my home computer, but had not yet loaded the new songs onto my iPhone. There had to be a way to make iTunes at home share its music to my work computer so that I could listen to the new music. A few internet searches turned up some interesting information as well as a solution.

The crippled feature to be healed and exploited

Apple’s iTunes software has the ability to share selected playlists or entire libraries of music to other computers on a local network running iTunes. This means that if you have a large collection of music on your desktop computer, you can browse and listen to music from its library from a different room, streamed to your laptop. Or if you work in an office, and your coworkers have iTunes running on their machines and set to share, their shared libraries will automatically appear in the left column of iTunes running on your machine and you can play from them. It all works very seamlessly, on a local network. Possibly due to agreements made between apple and the recording industry, the sharing feature only works between computers on a local network, not between computers on the internet at large.

How iTunes sharing works

When a user tells iTunes to enable sharing in that application’s preferences, iTunes advertises that service on port 3689 of the local network using “Bonjour“, the name for Apple’s implementation of the Zeroconf standard. Bonjour is used by iTunes, iPhoto, and other applications to advertise and to find servers on a local network, such as within a home or office.

If a copy of iTunes is running on any other computers that are on the local network, those instances of iTunes will notice the advertisement of an iTunes share on the network, and will display the name of that iTunes share in the left column of the window. The user can then click that shared Library and play songs from it on their computer. The playlists and songs stream over the network from the sharer to the sharee. Unfortunately in my case, iTunes running on my laptop at work couldn’t see the iTunes share served from my computer at home, because my home computer is miles away and not connected to the same local network as my laptop.

Bringing the remote network closer

The following link pointed the way to a solution:1

REMOTE ITUNES SHARING

I recognized a familiar Unix trick in their tip: Port forwarding over a secure shell connection. Of course! If one could make a secure shell connection (abbreviated in the command “ssh”) to a remote computer, one could then do what’s called “port forwarding”, and forward all communications on a port on the remote machine to a port on the local machine. This would transport both the advertisement of the iTunes share and the actual sharing itself from the remote network to the local network. I’d never actually executed port forwarding over ssh before, but I’d heard of it, and between their example and the man page for the ’ssh’ command, it all became clear. The tip first requires that one knows the IP address of the remote computer, and then shows the command to connect to the remote machine, grab any communications on port 3689 (the port used by iTunes sharing), transport it encrypted to the local machine, and repeat it on port 36890 of the local machine. The command looks like this (hover your mouse over any portion of the command to see an explanation of that portion):

$ ssh -fNL *:36890:127.0.0.1:3689 USER@REMOTE-HOST

After that command successfully concludes, the iTunes share on the remote computer will be accessible to computers on the local network, except they won’t be able to see that it’s there. The second command in their document uses OS X’s built-in “dns-sd” command to advertise that there is an iTunes share on port 36890 of the local computer. It is this advertisement that will make the iTunes share appear in the sidebars of any copy of iTunes running on the network:

$ dns-sd -R "Remote iTunes" _daap._tcp local 36890 &

I was confident that this would all work, but for one snag. Like most people, my home computer only has an address on its local network, it doesn’t have its own internet address. The computer is connected to a router. The router has an IP address on the internet and an IP address on the local network and uses what’s called “Network Address Translation” to distribute connections from the outside internet to all the computers on the local network. If I tried to connect to the IP address of my home connection, I’d be connecting to the router, not my home computer with its trove of music. Luckily a solution was within reach.

Locating the remote computer using Back to My Mac

I recently purchased a “MobileMe” subscription, which includes a service called “Back to my Mac“. I’ll let Apple’s marketing folk, who’ve obviously seen Buckaroo Banzai, explain “Back to My Mac” for me:

Wherever you go, there’s your Mac.

Back to My Mac puts any Mac OS X Leopard- or Snow Leopard-based Mac you use within easy reach. MobileMe finds your remote Mac computers over the Internet and displays them in the Finder on the Mac you’re using. So you can connect from anywhere with just a click. Edit and save documents, open applications, and move folders. With Back to My Mac Screen Sharing, you can control your remote Mac as though you’re sitting in front of it.

I have been using the Back to My Mac service to copy files to and from my remote computer from work, and to occasionally take control of my home computer’s screen from work. The service must be punching through the router using port-forwarding and registering a temporary domain name for my home computer which can be accessed from the outside internet. I figured that if I could find out this domain name, it would be worth a try to use it to connect from work to the home computer and set up ssh port forwarding of the iTunes share. A search turned up this article:

10.5: How to use ssh using ‘Back to My Mac’

The writer of that article explains exactly how to determine the Back to My Mac domain name at which one can find their remote computer. When I tried the first method described, it did not work. As it turns out, that method works for short computer names, but my home computer’s name is long, and Back to My Mac truncates it and adds a few random (?) numbers when assigning the domain name. The second method they mention does work. I can easily determine the name assigned to my remote machine by choosing “Shell > New Remote Connection…” in the Terminal application’s menubar. In the “New Remote Connection” window that appears, I choose ’ssh’ in the service column and my remote computer’s name in the ‘Server’ column. There, in the field at the bottom of the New Remote Connection window will appear the command for making a ssh connection to my home computer. It’s not the same ssh connection command that will be used to do port forwarding, but the last portion of it does show me the exact domain name that will resolve to my home computer.

Victory

Whenever I feel the mood, I can now run the following two commands and then sit at work listening to streaming music stored on my home computer:

$ ssh -fNL :36890:127.0.0.1:3689 myComputerName.myMobileMeID.members.mac.com.

$ dns-sd -R "Zach's Remote iTunes FTW" _daap._tcp local 36890 &



Thanks Y’all

Thank yous are due to the writers of:
  1. All the solutions written below involve the use of the Terminal application and the command-line. If you’ve never played with such, give it a shot. Stop kvetching and open /Applications/Utilities/Terminal. You paid for a Unix operating system when you bought your Mac, you might as well try exploring some of its inner awesomeness. []

FCP howto: Use Batch Export to create a directory of still frames from a bin of clips

Wednesday, February 3rd, 2010

If you’ve got a bunch of clips in a Final Cut Pro Browser window, and you’d like to quickly generate a still frame for each clip, you can use the “Still Image” feature of FCP’s ancient “Batch Export” feature to automate much of the process. Here’s how:

Rt Overlays (Ignored By Utest)
1. Choose a representative frame in each clip. (Click any of these images to see them nice and big.

Making Stills From Fcp Step 2
2. Send the clips to FCP’s Batch Export feature and bring up its “Settings” window.

Exporting Stills From Fcp Step 3
3. Choose the destination for the exported files and set Batch Export to create still images.

The result will be a folder full-resolution PNG images, each named after its parent clip, deposited in the chosen destination folder.

I often end up processing directories full of such uncompressed images further using the excellent command-line Imagemagick utilities using the tcsh shell’s1 “foreach” command to iterate through all the images.2 It generally goes a little something like this:

$ tcsh3
% cd directory_of_images4
% foreach foo (*.png)5
foreach? convert -geometry 330x800 "$foo" "$foo:r.jpg"6
foreach? rm "$foo"7
foreach? end8

The result of this command is a set of JPEG-compressed images, one per clip selected in step 2, each resized proportionally to fit within a 330×800 rectangle.

  1. This is also easy to do with OS X’s default bash shell, but I’m more fluent in tcsh. []
  2. You may prefer GraphicConverter, Photoshop, or MS Paint. Imagemagick combined with the command line is mad fast for both image transformations and automatically renaming files. []
  3. Switching to the tcsh for this because I have yet to internalize Bash's foreach syntax. []
  4. If you're unfamiliar with command lines and shells, please note that the "%" character here represents the tcsh command-prompt, the "$" in the previous line represents the typical Bash command-prompt. Don't type these characters in your commands, they're just here for show. []
  5. "foo" is a placeholder of my choosing. There's nothing special about the string "foo". You can replace it with anything you like, such as "image", "placeholder", or "your_mom". Just make sure to use the same string in place of all the "$foo" commands below. []
  6. Each time tcsh iterates through your commands, it will replace the string "$foo" with the filename of an image from the set chosen by "*.png", which is every file in the directory ending in ".png". Adding a ":r" to "$foo" indicates that tcsh should expand the filename but leave off the period and filename extension –in this case "$foo:r.jpg" removes ".png" from the file and adds ".jpg" in its place. The quotes around "$foo" are optional if your filenames do not contain spaces or special characters. []
  7. Removing the original png file because all I ever wanted were the tiny JPEGs. []
  8. One more note from Captain Obvious: If you try to copy and paste any of these commands, be sure not to copy and paste the superscript numbers that lead to these footnotes. []

assistant editor Unix tricks

Monday, January 25th, 2010
It’s time to take apart some Final Cut Pro xml and add some newly received VFX clips to the VFX database. One of these days, I’ll explain all of these steps and how they might be useful in other workflows. For now, enjoy a look at a relaxing vacation from graphical user interfaces and mouse-clicks; A trip to the Terminal. If you have any Unix or XML knowledge, there might be something of interest in here.

Assistant-2:20100125 CAB$ xmlstarlet sel -t -m "//children/clip"\
-v "name" -o "," \
-v "out - in" -o "," -v "in" -o "," -v "out" -o ","\
-v "media/video/track/clipitem/start" -o "," \
-v "media/video/track/clipitem/end" -o ","\
-v "media/video/track/clipitem/file/timecode/frame" -o ","\
-v "media/video/track/clipitem/file/name" -o ","\
-v "media/video/track/clipitem/file/timecode/string" -o ","\
-v "media/video/track/clipitem/file/timecode/reel/name"\
-n 20100123_vfx_received.xml | tee 20100123_vfx_received.csv

52A-2_01_VFX_v1,178,0,178,0,178,,52A-2_01_VFX_v1.mov,,
52A-2_02_VFX_v1,141,0,141,0,141,,52A-2_02_VFX_v1.mov,,
52B-2_01_VFX_v1,152,0,152,0,152,,52B-2_01_VFX_v1.mov,,
53-3A_01_VFX_v4,307,0,307,0,307,,53-3A_01_VFX_v4.mov,,
54-3A_01_VFX_v1,188,0,188,0,188,,54-3A_01_VFX_v1.mov,,
C100_C016_0920LS_03_VFX_v1,102,0,102,0,102,,C100_C016_0920LS_03_VFX_v1.mov,,
C102_C011_0903RU_03_VFX_v1,79,0,79,0,79,,C102_C011_0903RU_03_VFX_v1.mov,,
C102_C011_0903RU_04_VFX_v4,256,0,256,0,256,,C102_C011_0903RU_04_VFX_v4.mov,,
C102_C011_0903RU_05_VFX_v2,200,0,200,0,200,,C102_C011_0903RU_05_VFX_v2.mov,,
C102_C011_0903RU_06_VFX_v2,147,0,147,0,147,,C102_C011_0903RU_06_VFX_v2.mov,,

Assistant-2:20100125 CAB$ cd thumbs/
Assistant-2:thumbs CAB$ tcsh
[Assistant-2:additions/20100125/thumbs] CAB% foreach foo (*.png)
foreach? convert -geometry 330x800 "$foo" "$foo:r.jpg"
foreach? rm "$foo"
foreach? end
[Assistant-2:additions/20100125/thumbs] CAB%

The starting point is a bin of clips in an FCP project. I’ve exported that bin as FCP XML, and have also batch exported the clips inside it as stills (to PNG, the default). The commands above are the meat of the process. Then the comma-separated-value list of clips I generate with the xmlstarlet command gets imported into an openoffice (or Excel) spreadsheet (a step I’ve ommitted here), and is massaged into a csv format for import into a Filemaker Pro database of VFX clips. Finally I import the thumbnails for each clip into the database. Fun stuff, pretty much.

The iPhone app “Brushes” is still kicking my ass

Tuesday, July 21st, 2009
Brushes Viewer

I’ve posted a few sketches I’ve made using the fantastic iPhone app “Brushes” to this blog, usually by exporting the images at iPhone resolution to the iPhone’s photo album, then emailing the images to my posterous blog using the phone’s built-in mail application. It’s a fun and seamless workflow.

But in the process I sell Brushes short. The application is capable of much higher quality image exports.

12.brushes
Jul 21 2009
Brushes
(52.56 K)
Tiff
(15.8 MB)
As one paints, Brushes keeps track of each stroke as a vector, not as a series of altered pixels tied to the screen resolution. While painting, one can undo and redo a massive number of strokes (all of them, I think). When finished, one can transfer the resulting “.brushes” files to a Mac, play back each and every stroke to watch the painting form onscreen, and most importantly can have the strokes rendered to several different image file types at much higher resolution than the iPhone’s screen –all using the free “Brushes Viewer” application.

If you’re curious what a Brushes file looks like when rendered at high resolution, or would like a Brushes file to test with the Brushes Viewer app, I’ve placed all my Brushes sketches in this gallery, formatted as in the example at right. Each sketch is available its original Brushes file and an exported 1920×2800 TIFF file.

And here’s a time-lapse movie of one the creation of those sketches, rendered out of Brushes Viewer. I’m having too much fun with this stuff.

Kludging the Future

Sunday, July 12th, 2009
Yesterday I watched a movie, and it was the future. The details of the process by which I watched a movie are a little complicated and hackneyed, but the spirit of filmwatching future was in the room right there with me in so many ways:
  1. The film: The King of Kong. This surprisingly riveting documentary film focuses primarily on an intense rivalry between the world’s two best players of the classic arcade game “Donkey Kong”.

    Why this is the future? Professional video game journalism has taken off1, and professional video gaming will follow. One day its popularity will eclipse that of football2. Howard Stern and friends may laugh at some of the wackier folk on display in The King of Kong, but video games are starting to move away from the sorts of repetitious action that favor people who these days get classified socially as geeks or diagnosed by professionals as OCD, Aspergers, &c. Nerds have already ascended to create the information economy3, next they’ll take over the world of sports, and the jocks who adapt and survive will be or become a little nerdier than those of today.

  2. The player: I watched the film in Mac OS X’s built-in media center application Front Row, using the Understudy plugin to allow me to use the simple Front Row interface to browse to and watch films using Netflix’s instant streaming service. Movies and TV shows, streamed over the internet, at high quality, for a low monthly fee; This service is already good enough to start beating out premium cable subscriptions for geeks on a budget. Streaming entertainment has begun to slip from the future4 category into the present.
    Understudy screenshot
    Imagine this image displayed up on a large-screen TV. That’s what Front Row’s main menu looks like after the Understudy plugin is installed. I’d show what Understudy’s menu looks like, and a netflix queue displayed in Front Row using the plugin, but Netflix is down at the moment so I can’t do so.
  3. The controller: Since my mac lacks an infra-red receiver, I could not use Apple’s simple remote control to navigate my way around Front Row. But why use an infra-red remote when my phone itself is a portable touchscreen device connected via wifi to the same network as my computer media center? Instead of ancient tech, I used an iPhone application called Air Mouse Pro, which communicates with a server application running on my computer5 over the local network. With this application, I could not only send keystrokes from my phone that were equivalent to the arrows, volume, and menu keys on the normal Apple remote, but I could also launch and exit Front Row, move and click the mouse pointer, and type anything at all on a virtual keyboard. All this without worrying about my distance from the media center or a need to maintain a line of sight between and IR emitter and receiver.6 Fortuitously, in my hour of need it came to pass that Air Mouse Pro was on sale for $1.99 (down from its normal price of $5.99, for one week). If it’s still on sale at this price, you can find it here: Air Mouse Pro SALE. Here’s a randomly-selected video review of this app from youtube, in case you’re curious how it works.

    So I streamed video to my media center and controlled playback over a network using a wifi touchscreen device. This is the slightly kludgy present, and a sign of things to come. You and your grandmother will all be watching movies and TV this way in a few years.

  1. As the career of videogaming journalist and The Daily of the University of Washington alumnus Jason Ocampo can attest. []
  2. by “football” I mean the sport played with a truncated icosahedron or the other sport also called football that uses a prolate spheroid []
  3. I typed it, but I’m not actually sure what it means. Maybe one too few buzzwords? Information Economy? “Hey farmer, I’ll trade you this metadata-encrusted search result for that pound of soybeans…” []
  4. There’s just something so delightfully obnoxious about the capitalized phrase “the future”, don’t you think? []
  5. The Air Mouse server application is available for both Windows and Mac []
  6. I probably could have accomplished much of the same with a vnc application, but most of them are more expensive, and I wasnt sure how the vnc application would interact with applications that play hardware-accelerated video such as Front Row. []

My 3-headed editing setup

Friday, July 3rd, 2009

Posted via web from Zachary’s posterous

A funky vertical panorama shot and stitched from 3 photographs on my iPhone with the AutoStitch app. The monitor at bottom is my DIY Cintiq, which has yet to be encased and prettified.It’s fed VGA (!)1 from a USB-DVI adapter.

This non-hardware-accelerated display works fine as extra space for displaying bins.

  1. the monitor was an ancient model that a friend was throwing out []

I ♡ the iPhone on-screen keyboard

Friday, June 19th, 2009
I frequently hear people who don’t have or use iPhones complaining that the iPhone’s onscreen keyboard is one of the device’s serious shortcomings and wishing aloud that it had a tiny hardware keyboard instead.

I have years of experience using the tiny hardware keyboards on my smartphones1, and from my perspective these criticisms are far off-base. I’m faster at typing on the iPhone, with about the same level of accuracy. I think most iPhone keyboard complainants would recant if they spent a week poking at one.

My opinion of the keyboard is very positive. The iPhone’s text input method is extremely well designed and usable, with both fantastic visual feedback and intelligent auto-correction. Other companies who consider including an onscreen keyboard on their mobile devices2 would do well to copy its strong points.

Here’s a little clip of some random iPhone typing. The clip looks a bit odd because to make it I balanced my Creative Vado HD camera on one of those “helping hands” devices to use its magnifying glass, resulting in a sharp but amusingly distorted image. I don’t think the typing speed on display here is exceptional, and I’m usually more accurate. Speed and accuracy were impaired due to a recording setup which imposed physical constraints –I had to move my finger around at a strange angle in the small space between the magnifier and iPhone and could not see the letters pop or words form without leaning my head at a strange angle3, normally I hold the iPhone in one hand and type with the other. But forgetting these issues, the clip does show, to my mind, that the iPhone keyboard can be used to type with reasonable speed and accuracy. And it’s fun.

iPhone 3G Typing Demo from ZachFine on Vimeo.

  1. Handspring Treo 300, Palm Treo 600, and Palm Treo 650 []
  2. I’m looking at you Google Android (I was very disappointed when I tried an Android onscreen keyboard the other day, it was so non-responsive it didn’t even register most of my keypresses []
  3. I basically typed this blind, only checking periodically to check for error. This is actually a good way to go when typing on the iphone, as if you let go and just use the force more often than not you end up with the exact words you were trying to type in much less time than it would take to be super-careful about your keypresses. []

The beauty of SeaTac intl airport

Thursday, June 18th, 2009

edit: I’m wrong about the resolution issue — see correction and link to a full-resolution 2729×733 180º panorama at the end of this post.

I just shot and stitched a panorama while waiting for a ride. Though the Autostitch iPhone app does a great job, I can’t help but wish it would save the resulting panoramas to the photo library at full resolution.
 
The screenshot of the app displaying a section of the finished panorama is at least twice the resolution inside the app as is the version it saves. If the iPhone APIs limit the resolution at which apps can export to the photo library, perhaps autostitch could save to its own db and offer some other method of export (email, built-in webserver a la ‘Brushes’, flickr export?).
 
Regardless this one limitation, ‘AutoStitch’ is a lot of fun, and is well worth its $1.99 price.

Posted via email from Zachary’s posterous

– Edit 2009-06-19 12:32am –
It appears that AutoStitch does save its panoramas at full resolution to the iPhone’s photo library, but the photo library doesn’t display the images at full resolution. Nor does the iPhone’s mail client send the photos at the original resolution, instead it scales them to be much smaller.

I used the ‘Multi-Photo’ email application, which can send multiple photos via email without resizing, to send this panorama to myself.1 Click the thumbnail below if you’d like to view the panorama at its full 2729×733 resolution.

thumbnail of airport arrivals pickup zone panorama
Click this thumbnail to see the full-res pano.

  1. Were I home and not out traveling, I’m sure the full-res photo would have easily synced to my home computer’s iPhoto library over USB, but that’s not an option in the field. []

free iPhone Application Programming class

Friday, June 12th, 2009
Screenshot of the listing for the iPhone Application Programming class in iTunes U.
Apple’s iTunes music store has a section of free podcasts called “iTunes U”, which feature lecture media (videos, audio, PDF notes) for classes at a number of universities.

Someone recently mentioned to me that Stanford University’s “iPhone Application Programming” class1 is available2.

I’m thinking I may try to work my way through this set of lessons for a few reasons:

  • It would be good for me to gain a better grasp of object oriented programming principles.
  • The iPhone looks like a fun platform for which to program, with rich APIs that run the gamut from UI to animations to data storage (with SQLite as an option!).
  • I’ve been running a lot of iPhone apps lately, and thinking of apps that should exist and might be interesting to develop.
  • Free development tools, based in part on the gnu C compiler, with which I’m already a little familiar.
  • If I managed to program anything worthwhile, there are a ton of potential users, and distribution (and sales if it’s a commercial app) would be remarkably easy due to the existence of the app store.

I’m amazed by the apparent number of other classes available for free download in “iTunes U”. I look forward to one day having enough spare time to actually look through more of them.

  1. If iTunes is installed on your computer, clicking that link will take you to the page in iTunes from which you can download individual classes or subscribe to the entire feed. []
  2. I noticed that the class is co-taught by Alan Cannistraro, a former coworker of mine. It’s nice to see a familiar name. []

An error message I’d love to see improved in Snow Leopard

Tuesday, April 7th, 2009
OS X's "disk is in use" error dialog

Oh how I hate the above error message. It’s not that it’s completely uninformative, but it’s a perfect case of “so close but yet so far”…

Anyone who uses as many external disks on a Mac as I do is apt to occasionally have trouble properly unmounting and ejecting those disks1. Before unmounting a disk, it’s necessary to stop accessing files on the disk. This is often an easy thing to do –if I’ve loaded a file from an external disk into an application, I just close the document or quit the application entirely. If I’ve goofed and am still using files on the drive, OS X will refuse to unmount the drive and will display the error dialog I’ve pasted above.2

But often it’s less than obvious which application or function built-in to the operating system is using a file on the drive. There are applications that don’t play nice, and keep file handles open to files on a disk even after you’ve closed all documents that use those files3. There are functions built into the operating system that access files on a disk without calling any attention to themselves. This error message could and should be a hell of a lot more informative and useful.

A simple set of commands in Terminal4 can reveal which application is using a file on a particular disk. Since this information is available, is incredibly useful, and can be quickly retrieved in the Terminal, I see no reason that it is not just included in the initial error message. Telling me that a disk is still in use is not nearly as useful as telling me that a disk is still in use by Microsoft Word, or that a disk is still being shared with another computer.

In this case, the terminal command “lsof | egrep -i 400Gb” reported that a process named “smbd” was still using the drive. Since I’m a Unix geek this is useful information to me, but since OS X tries to also be useful to people who wouldn’t know a Samba daemon if it ate their grandmother, this process should be simplified. In an ideal world, the error message above would read “The disk ‘400Gb_Thing’ is in use by OS X’s Windows file sharing. Would you like to stop sharing this drive and eject it?” and would feature both “OK” and “Cancel Ejection” buttons.

This is a no-brainer. Apple, please fix. Thanks.

Technorati Tags: , , , , , , , , ,

  1. It’s a good idea to actually unmount disks prior to unplugging them, modern filesystems need to be given a proper send-off before disconnection to keep the data in good shape. []
  2. Windows users (and I am one), please refrain from feeling smug at this tale of Mac woe. Don’t get me started on the Windows “Safely Remove Hardware” dialogue and how much fun it is to try to remember the model numbers of each of my external drives so that I can find them in that list. It’s unconscionable that this feature wasn’t redesigned for Windows Vista. They must have used a single USB drive as the test case. []
  3. I often just have to quit Final Cut Pro before ejecting a drive for this reason, sometimes it just won’t let go of a file even when all FCP projects have been closed and I’m looking at an empty Browser []
  4. ”lsof | egrep -i portion-of-disk-name”, or in this case “lsof | egrep -i 400Gb”, without the quotes. []

Bad Behavior has blocked 284 access attempts in the last 7 days.