This answer is hella long because your comments seem to indicate that your main interest is AppleScript itself, not converting videos from FLV to MP4. If this is the case, I strongly recommend starting with a good AppleScript reference, reading carefully and learning to use the tools available to you (especially Script Editor and application dictionaries). Trying to learn a new language by modifying existing applications is not good for debugging and can end in very bad things like cargo cult programming. That said,
I'd start by opening QuickTime Player's dictionary (
File->
Open Dictionary... in Script Editor) to see what commands are available. In my version of QuickTime Player (7.6.4), there's an
export
command in the QuickTime Player Suite:
export v : Export a movie or track to a file
export reference : the movie or track to export
to file : the destination file
as AIFF/Apple TV/AVI/BMP/DV stream/Fast Start QTVR Movie/FLC/hinted
movie/image sequence/interframe compressed VR object movie/iPhone/
iPhone cellular/iTunes/MuLaw/MPEG2/MPEG4/picture/QuickTime media
link/QuickTime movie/QuickTime TeXML/standard MIDI/System 7 sound/
text file/ThreeGPP/wave : the desired file type
[using default settings/most recent settings] : the export settings
to use
[using settings preset string] : the name of the export settings
preset to use
[using settings file] : the file containing the export settings
[replacing boolean] : should the original file be deleted first?
A little Googling suggests that the "iPhone" file type refers to a .m4v file, so a first step might be replacing save first document in target_path as ".m4v"
with export first document to target_path as iPhone
. Looking through the dictionary a little more, though, shows that there's also a can export
command:
can export v : Determine if a movie or track can be exported to the desired
type
can export reference : the movie or track to export
as AIFF/Apple TV/AVI/BMP/DV stream/Fast Start QTVR Movie/FLC/hinted
movie/image sequence/interframe compressed VR object movie/iPhone/
iPhone cellular/iTunes/MuLaw/MPEG2/MPEG4/picture/QuickTime media
link/QuickTime movie/QuickTime TeXML/standard MIDI/System 7 sound/
text file/ThreeGPP/wave : the desired file type
→ boolean : is the export supported
So we should check that it's possible to export the movie in iPhone/.m4v format before actually doing so:
if (can export first document as iPhone) then
export first document to target_path as iPhone
else
error "Cannot export " & (source_file as string) & " in .m4v (iPhone) format."
end if
If we stop here, though, we may notice that some of the output files don't play correctly beyond a certain point, because QuickTime can load files asynchronously (i.e., not all at once). We should try to check that QuickTime Player has finished loading a movie before we tell it to export; by examining the full list of load states listed in the dictionary and assuming that every movie eventually ends up in a finished state or an error state, we can add this relatively easily.
set error_states to {load state unknown, load error}
set successful_states to {loaded, complete}
repeat until load state of first document is in (error_states & successful_states)
delay 0.1
end repeat
if (load state of first document is in successful_states) then
if (can export first document as iPhone) then
export first document to target_path as iPhone
else
error "Cannot export " & (source_file as string) & " in .m4v (iPhone) format."
end if
else
error "File is not in a successful load state: " & (load state of first document as string)
end if
Best Answer
For a GUI, I suggest checking out MPEG Streamclip which does have the ability to do batch processing.
Alternatively, there are (now deprecated) command line tools available in
/usr/libexec/podcastproducer
and the replacement at/usr/bin/pcastaction
. Specifically;You can find more by running
pcastaction help encode
So a sample script to do this would be as follows: