Delete first second of .mov

Hello all.

I’ve run across a problem. Before switching to Mac, all my movies were encoded with divx in an .avi container. Once I got a Mac and an Apple TV, I needed a way to import them all to iTunes without having to re-encode them all to a suitable format. What I found was an app called Apple TV Fooler.

iTunes checks only the first frame of each movie for compatibility and so that’s all that would need to be changed.

Essentially, Apple TV Fooler is a droplet that adds a 1 second blank movie (H.264, AAC) to beginning of each movie and then saved them as .mov. I was then able to import them to iTunes and (after installing the proper codecs) play them on the Apple TV.

However, now I am thinking of purchasing a Mac Mini and creating a more dynamic Media Center. I’d like use the Plex software, but it has a problem with playing the files with the added clip at the beginning.

So, in short, I’m in need of an AppleScript that will delete the first second of each movie and then save it.

If need be, I can post the code to the Apple TV Fooler.

Thanks for any help!

Hi mdburke,

I found your problem quite challenging and so I decided to spent some time to solve it. As I don’t like scripting QuickTime very much, I opted for a combination of an AppleScript droplet and a foundation tool written in Obj-C utilizing the QTKit.

If you are interested in the source code of the foundation tool, then you can study it right here.

Before using my scripting solution on many files, I absolutely recommend to use it on some sample files first! Please note, that the script in it current state will not create a new movie file, but rather update the existing original file! This is IMPORTANT!

To use and test the AppleScript droplet, please first download the foundation tool, unzip it and place it onto your desktop. Then save the AppleScript code below as an application bundle in Script Editor. Now you can drag and drop QuickTime movie files onto the script and it will remove the first second of each movie.

The script was tested on Mac OS X 10.5.5, but should also work on 10.4


property mytitle : "remsec"

on open droppeditems
	try
		set droppedfiles to {}
		repeat with droppeditem in droppeditems
			set iteminfo to info for droppeditem
			if not folder of iteminfo then
				set droppedfiles to droppedfiles & (droppeditem as Unicode text)
			end if
		end repeat
		
		if droppedfiles is {} then return
		
		set countdroppedfiles to length of droppedfiles
		set stringlist to ""
		repeat with i from 1 to countdroppedfiles
			set droppedfile to item i of droppedfiles
			if i is not equal to countdroppedfiles then
				set stringlist to stringlist & (quoted form of POSIX path of droppedfile) & space
			else
				set stringlist to stringlist & (quoted form of POSIX path of droppedfile)
			end if
		end repeat
		
		set foundationtoolpath to quoted form of POSIX path of (((path to desktop) as Unicode text) & "remsec")
		-- a more convenient way to operate the script is to place the remsec foundation tool right inside the script bundle:
		-- set foundationtoolpath to quoted form of POSIX path of (((path to me) as Unicode text) & "Contents:Resources:remsec")
		set command to foundationtoolpath & space & stringlist
		set output to do shell script command
	on error errmsg number errnum
		tell me
			activate
			display dialog "Sorry, an error occured:" & return & return & errmsg & return & "(" & errnum & ")" buttons {"OK"} default button 1 with icon stop giving up after 30 with title mytitle
		end tell
	end try
end open

Wow, it worked perfectly!

Thanks a lot! Not only did it work, but it worked instantly - much faster than the Apple TV Fooler.

You are a savior.

EDIT: And oddly enough, the resulting movie file is still able to be imported and played via iTunes!

Although the foundation tool CLI is doubtless the most efficient method,
there is also a pure AppleScript solution


on open theFiles
	repeat with aFile in theFiles
		tell application "QuickTime Player"
			open aFile
			tell document 1
				set selection end to duration
				set selection start to time scale -- the value of time scale represents one second
				trim
				close saving yes
			end tell
		end tell
	end repeat
end open