Video Transcoding for the iPad

When I first started syncing pictures to my iPad, I noticed that videos didn’t sync. After some research, it turns out that the video/audio format used by my Canon SD960 IS, I kind of put it on the back burner and ignored it. Now that I have an iPad 2, I bought iMovie and wanted to do a little video editing this weekend. Unfortunately the only clips that I had on my iPad were taken with my iPhone 4.

After a bit of futzing around with AppleScript, I slapped together 2 scripts to transcode my videos into 720 p and suitable for use on my iPad. The big issues I found is that QuickTime Player (the one with Snow Leopard) changed the AppleScript syntax and exports asynchronously. For non-techies, this means that the export basically happens in the background. This created a problem as I don’t know when each export ends; I need this information so that I can change the date on the exported file to match the original file as well only running around 10 exports going at once (too many running basically slows down the system).

So here’s what I did:

  1. Created a new folder on the Desktop called Movies and dragged all my movies from iPhoto.
  2. Created a second folder on the Desktop called NewMovies.
  3. Opened AppleScript Editor and used the following script and saved it as an application.
    property exportFolder : (path to desktop folder as Unicode text) & "NewMovies:"
    
    on run
    	choose folder with prompt "Change video files from these folders:" with multiple selections allowed
    	open (result)
    end run
    
    on open droppedItems
    	tell application "QuickTime Player"
    		activate
    		close every window
    	end tell
    	
    	set numExports to 0
    	
    	repeat with thisItem in droppedItems
    		if (folder of (info for thisItem without size)) is true then
    			list folder thisItem without invisibles
    			
    			repeat with thisFile in (result)
    				if (numExports < 10) then
    					tell application "QuickTime Player"
    						open ((thisItem as Unicode text) & thisFile)
    						try
    							export front document in (exportFolder & thisFile) using settings preset "HD 720p"
    						on error errorMsg number errorNum
    							display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "OK" default button 1 with icon caution
    						end try
    						
    						set numExports to numExports + 1
    						close front document
    					end tell
    				end if
    			end repeat
    		end if
    	end repeat
    end open
    
  4. I then created a second script that changes the date on the exported files and then deletes the originals.
    property exportFolder : (path to desktop folder as Unicode text) & "NewMovies:"
    
    on run
    	choose folder with prompt "Change video files from these folders:" with multiple selections allowed
    	open (result)
    end run
    
    on open droppedItems
    	repeat with thisItem in droppedItems
    		if (folder of (info for thisItem without size)) is true then
    			list folder thisItem without invisibles
    			
    			repeat with thisFile in (result)
    				try
    					set fileExists to no
    					tell application "Finder"
    						if exists (exportFolder & thisFile) then
    							set fileExists to yes
    						end if
    					end tell
    					
    					if fileExists = yes then
    						set file_ to POSIX path of (exportFolder & thisFile)
    						set fileInfo to info for ((thisItem as Unicode text) & thisFile) as alias
    						set oldDate to creation date of fileInfo
    						set format_string to "<><><><><>"
    						set new_creation_date to format_date(oldDate, format_string)
    						do shell script "touch -t " & new_creation_date & " " & quoted form of file_
    						tell application "Finder"
    							delete ((thisItem as Unicode text) & thisFile)
    						end tell
    					end if
    				end try
    			end repeat
    			
    		end if
    	end repeat
    end open
    

    NOTE that you also need you to grab some AppleScript code for date formatting and put it in the above script.

  5. I ran the first script, let the transcoding finish, then ran the second script. Unfortunately I had to repeat this a large number of times to transcode all my videos.

So now I have all my videos in a format that works on the iPad. When I import new movies, I’m going to run them through these scripts before I put them in iPhoto. Another benefit of doing this now is that all my videos are in the same format and will buy me a few more years using H.264 and AAC for encoding; all my videos were in random formats some requiring special codecs to play that who knows how long they’ll be around.

While I wish this process was more straightforward and took less time, I’m glad that I undertook this so that I can start playing with iMovie on my iPad.

One Reply to “Video Transcoding for the iPad”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.