It often arises that I have to edit MPEG files. This is a fairly difficult process in general but I have discovered a way to do it in QuickTime Player Pro. MPEG files are generated by EyeTV, ReplayTV, TiVo, and other TV capture devices. In general, when I want to edit one, I'm not so much interested in doing anything especially fancy. I just want to clip out the adverts and make a VideoCD or one of the related formats such as SVCD or CVD. There isn't a good MPEG editor available for the Mac yet, but with a little trickery you can get QuickTime Player Pro to perform this work for you. There is a GOP (Group-of-pictures) editor called GopChop that runs under X11, but I haven't managed to invest the time to get it going yet, although the developer's mailing list for it has been more than helpful.
It's always possible to export to a lossless codec like Pixlet, but this procedure saves a great deal of time, disk space, and it works well for me. I've tested it on several sorts of MPEG files, of both MPEG1 and MPEG2 standard, and haven't had any trouble. Also, the procedure I outline below takes advantage of another QuickTime Player Pro feature, the ability to mask various layers of the picture to get rid of the annoying analog noise that sometimes shows up at the top of the frame in TV captures. When the alternative is exporting to DV, letterboxing in iMovie, and rexporting back to MPEG1 or MPEG2 for VCD or DVD, being able to make simple edits in QTPro is a real time saver.
[robg adds: I haven't tested any of this hint...]
It is a quirk, or heck, I don't know, maybe a feature, of QuickTime Player Pro that even when an MPEG track is contained as one track in a movie, it can't be edited readily. Many of the menu functions are disabled in the Edit menu. Also, it appears that the first frame of the movie must be preserved for some reason, and this generally means that whatever sound is in that first frame is also preserved. The following procedure helps with that problem too, and yields acceptably shiny, edited movie files for further processing. To do this, you will need:
tell application "QuickTime Player"
set the selection end of the front movie to the current time
clear the front movie
end tell
I keep this one in my /Library/Scripts/ folder, and name it " Edit" with a leading space so it shows up first in the Scripts Menu. (This is installed from the utility in /Applications -> AppleScript -> InstallScriptMenu). I'm told that all the functions I'm talking about are available via AppleScript even from the non-pro version of QuickTime Player, but as I was happy to buy a license it didn't matter much to me. Specifically for editing the first frame, you want to rewind the movie fully, and then step forward by one or two frames with the arrow key. Do Edit -> Select None. Then scroll forward to where you really want the movie to start. Execute the AppleScript above. Now, when you rewind, your first couple of frames will be silent and dark, and the remaining ones will be the programming you want.
on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder "Done" of this_folder) then
make new folder at this_folder with properties ¬
{name:"Done"}
end if
set the destination_folder to folder "Done" of ¬
this_folder as alias
set the mask_folder to folder "Masks" of ¬
destination_folder as alias
set the destination_directory to POSIX path of ¬
the destination_folder
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and the ¬
name extension of the item_info is not in ¬
{"zip", "sit"} then
set the item_path to the quoted form of the ¬
POSIX path of this_item
set the audio_path to the quoted form of ¬
(destination_directory & (name of the ¬
item_info) & ".wav")
set the_script to ("/Applications/ffmpegX.app/Contents/Resources/ffmpeg -i " & ¬
item_path & " -vn -acodec pcm_s16le " & audio_path)
do shell script (the_script)
end if
set qt_open to "open -a '/Applications/QuickTime Player.app' "
set the_other_script to (qt_open & item_path)
do shell script (the_other_script)
tell application "QuickTime Player"
close (every window whose name contains "Untitled")
set {width, height} to the dimensions of the front movie
set the mask_path to the POSIX path of the mask_folder
set silent_path to "'" & mask_path & "Silence.wav'"
set bg_path to "'" & mask_path & "TV Background " & width & ".mov'"
set mask_path to "'" & mask_path & "TV Mask " & width & ".pct'"
do shell script (qt_open & bg_path & " && " & qt_open & mask_path & " ¬
&& " & qt_open & audio_path & " && " & qt_open & silent_path)
(* get a half second of silence *)
copy the front movie
close the front movie saving no
(* add the silence to the first half second of the .wav audio *)
set selection start of the front movie to 0
set selection end of the front movie to 150
replace the front movie
select all the front movie
copy the front movie
add the back movie with scaled
close the front movie saving no
(* add the mask *)
select all the front movie
copy the front movie
add the back movie with scaled
close the front movie saving no
(* add the background *)
select all the front movie
copy the front movie
close the front movie saving no
set layer of track 1 of the front movie to -4
set layer of track 3 of the front movie to -5
tell movie 1
set the operation color of track 3 to {65535, 65535, 65535}
set the transfer mode of track 3 to transparent
end tell
set sound volume of track 1 of the front movie to 0
set the movie_name to the name of the front movie & ".mov"
set the movie_file to (((destination_folder as string) & movie_name) as string)
rewind the front movie
(* add the background to evade "first frame" problem *)
add the front movie
step forward the front movie by 1
select none the front movie
save movie 1 in file movie_file
close movie 1
end tell
end repeat
end adding folder items to
Attach the script as a folder action to the folder you've created (the one that contains the "done" and "masks" folder) and any mpg file you drop into it will be processed. On my 1GHz Powerbook, the entire process executes in about 1/15 the duration of the original movie. Just about all of that is the .wav exporting. My 2x1.25 PowerMac is quite a bit faster but I haven't benchmarked it specifically.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20040213203637547