Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Edit MPEG files using QuickTime Player Pro Apps
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:
  1. QuickTime Player Pro.
  2. ffmpeg, an open source command line tool. Although there are several versions around that will do the job I'm fondest of the version buried in the ffmpegX.app package that can be downloaded from here.
  3. A collection of masks. These are PICT files, sized to standard frame sizes, with black at the parts you want to cover and white at the parts you don't. They are used to cover the analog noise at the top of the frame.
  4. A collection of Background movies. These are very short movies that you use to cover up the first frame.
  5. A moment of silence. Since the first frame can't be deleted, any audio shows up in the first frame as well and might make an unpleasant noise. Create it in .wav format.
In general terms, here's what you do:
  1. Export the sound from the file in WAV format using ffmpeg.
  2. Open the .wav file in QuickTime Player Pro. Double-clicking the file may open it in iTunes, which you don't want, so be careful. Click on the selection end marker (that's the small triangle BELOW the progess bar, with the point facing to the right) and make sure that it is open rather than solid. Hit the right arrow twice, which should move the marker to 15 frames from the beginning.
  3. Open a .wav file containing a half second of silence. Select all of it, switch to the exported .wav file, and choose "replace" off the Edit menu. Now select all of the exported .wav file.
  4. Open your .mpg file in QuickTime Player Pro. Select Edit -> Add Scaled. You now have a movie container with two tracks: an MPEG muxed track and a "sound track".
  5. Open the Background movie corresponding to your movie displayed frame size (typically 640 x 480 or 320 x 240). Rewind the movie to the beginning and add it in with the Edit menu (Edit -> Add). Here, it's important to select "Add" not "Add scaled". You're trying to cover up the first frame so that you don't have to look at it, not cover up the whole thing.
  6. Open your mask file corresponding to the movie displayed frame size, select all, and close it. Add this to the movie as well, using Edit -> Add Scaled. You now have a movie container which contains four tracks: An MPEG Muxed Track, a Sound Track, a Video Track 1, and a Video Track 2. The layers correspond to the order we added these tracks.
  7. Open the Movie Properties window (Movie -> Open Movie Properties). Select MPEG Muxed Track from the left pulldown. Select Volume from the right pulldown. Run the volume for this track to zero. You have a separate sound track for this file, and you don't want to listen to the one on the MPEG track anymore.
  8. Select Video Track 2 from the left pulldown. Select "Graphics Mode" from the right pulldown. Choose "transparent" from the window, and click on the "Color..." button. A standard color window will appear, from which you will want to select white. I use the gray scale slider selection and run it all the way to the right, but other choices will also work. Basically you're telling QuickTime Player Pro to show you everything that is underneath the white part of your mask, and obscure everything else.
  9. Save the movie. You now have a movie container which is ready for editing in QuickTime Player Pro. There is one snag, though: The Edit -> Clear selection is still grayed out. I believe the presence of MPEG tracks disables this in the player. I work around this as follows. Using the mouse or just play commands, I put the current time cursor at the beginning of the commercials I want to delete. I then choose Edit -> Select None. This snaps the selection beginning and ending markers to the current time. I repeat my search through the programming to find the selection's end. Then I execute the following AppleScript:
    
    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.
  10. Save your edited film.
Now you're ready to do anything with this new .mov file you can do in general with a .mov file. For example, you could drag it into a sequence in the outstanding VCD Builder application, for use in making a VCD or SVCD. You could send it to the GUI version of ffmpegX and create a Half-D1, VCD, or DVD elementary stream film for use in VCD, SVCD or DVD authoring. You could use the Toast VideoCD Export, MPEG2 Export, or any other QuickTime Export feature available in QuickTime Player Pro (assuming you own the products that install these options). What this procedure gives you, though, is the ability to do relatively clean editing on MPEG source material, without having to transcode to an intermediate format, taking up either large amounts of time, disk space, or degrading video quality.

Timesaving hint #1:

I realize the procedure above is tedious. To simplify it, create a new folder wherever you like, and inside it create another folder called "Done". Inside that, create a third folder called "Masks" and place the pictures (PICT files) for the masks (in 320x240 and 640x480) in there. Also create a couple of very short movies of no more than a half second duration in the same size. In my case I did this with the QuickMovie application, but you could export a slide show of black frames from iMovie and then export again from QuickTime Player Pro in, say, the Cinepack codec. Finally, exporting some sound as WAV from iMovie with the volume edited down to zero gets you the half second of silence you need. Place all of these support files (the masks, the lead-in movies, and the silent wav) in the "Masks" folder. Make sure their names are consistent with the code below (change whichever you prefer). Put the following AppleScript in your /Library -> Scripts -> Folder Action Scripts folder:

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.

Timesaving hint number 2:

Download the files needed to do all this from here. They're in the archive stored there as "Process Mpeg Files.sit."
    •    
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[41,539 views]  

Edit MPEG files using QuickTime Player Pro | 29 comments | Create New Account
Click here to return to the 'Edit MPEG files using QuickTime Player Pro' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Edit MPEG files using QuickTime Player Pro
Authored by: clmensch on Feb 23, '04 11:28:15AM

AWESOME. Thank you thank you thank you. I can't wait to try this. I use DVArchive with my ReplayTV 5080 to download recorded television shows, and I find it absurd that I can't do anything with them other than watch them in Quicktime Pro.


---

"I drank WHAT?" -Socrates



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: MacProducer2 on Jun 18, '04 06:15:06PM

Edit MPEG files with iMovie!

New Product: DropDV. Converts your MPEG files into an iMovie project (DV format). Costs $20 bucks.

http://www.dropdv.com



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: Fofer on Feb 23, '04 11:53:01AM

Great hint. Just in time too, as I've started to put my hacked DirecTiVo through the paces (which produces digitally perfect MPEG-2 files.) I had resorted to using MPEG2VCR (software allows editing of MPEG files without reencoding) on a crappy PC, but I'd much rather enjoy the exercise on my Mac!

The next question was what DVD authoring software to use? iDVD only accepts DV files, DVD Studio Pro wants elemental streams and is a bit higher-end than my basic needs call for, and Sizzle has some compatibility problems with Panther at the moment. I tried Toast but it seems to insist on re-encoding. Ideally I want to burn these MPEG-2 files to DVD-R as a DVD video disk, without reencoding. Is this possible?



[ Reply to This | # ]
TiVo to Mac?
Authored by: SoxFan on Nov 02, '04 11:40:26AM

How do you connect your TiVo to your mac? Can you do it through the TiVo's network port?



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: Fofer on Feb 23, '04 11:56:55AM

"to get rid of the annoying analog noise that sometimes shows up at the top of the frame in TV captures"

By the way, sometime along my travels, I learned that that "noise" is actually what carries the closed-captioning information. After learning that, for some reason, it didn't annoy me quite as much. :)



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: visigothe on Feb 23, '04 12:01:55PM

The funny thing about all of this is that Quicktime Player used to be able to edit MPEG as if it were any other QT codec... back in the Version 3 days. After that, Player could not cut/paste MPEG tracks. I used to keep an old version of Player around *just* for this purpose.

I suppose this was to prevent bloating of the file, as [I would imagine, I haven't analyzed the files] QT would have to transform the cut/pasted portions to pure I-frames, as P and B frames were just delta information.

This thought makes sense, until you realise that *every* modern codec does the same thing [a Keyframe, followed by "n" delta frames]. So I really don't know what the problem is/was.

Can anyone shed some light?



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: pankers on Feb 23, '04 11:41:58PM

I read somewhere that Apple no longer wanted to pay for the MPEG license after version 3.

I still have a copy of QT3 Player and really should see if I can get it to edit my MPEG movies.



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: epicycle on Feb 23, '04 12:47:21PM

I am a bit confused, so does this automation run it through the tools just to get it to the point to where you can edit it in QTP? What if you have say 40 seconds in the beginning that you don't want? So after it is processed can you go in and cut out the pieces of the segment you don't want (i.e. commercials)? Sorry for the questions ... I am using some command line tools now for my Replay 5040 and would love to be able to automate a lot of this or at least use a GUI to remove the segments I don't want.

I appreciate the article, kudos!

Sean



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: Mitchell on Feb 23, '04 04:35:28PM
Basically, in a nutshell, the AppleScript I wrote does all the stuff necessary to get you a .mov file, containing your original data, which you can edit reasonably well in QuickTime Player Pro. All you need to do is run the position marker to the beginning of a commercial, Edit --> Select None, then to the end of a commercial, and run the small AppleScript I put in the hint. I can do a one-hour drama's necessary editing in a little over a minute.

Once you have the movie, as edited, transcode it or do whatever you like to put it in a DVD or VCD compatible format.

[ Reply to This | # ]

Fascinating Method
Authored by: petey on Feb 23, '04 02:08:47PM

This is a fascinating method. But it doesn't seem nearly as easy as editing MPG using mpgtxwrap.



[ Reply to This | # ]
Fascinating Method
Authored by: Mitchell on Feb 23, '04 04:43:27PM

I'd use mpgtxwrap or one of its variants, such as MPEGinsu (gotta love that name) if I could get accurate editing. My experience with an mpgtx based editor is that it is never on the time you ask it to be, and the fragments you create never join together smoothly. Ultimately you wind up with a big mess, especially with ReplayTV files, which are somewhat less than 100% shiny in terms of MPEG2 standard adherence.



[ Reply to This | # ]
hmm
Authored by: martinx on Feb 23, '04 04:38:25PM

This is one thing that bugs me about Apple - they never seem to make much effort to support other standard file formats when they can avoid it. Garage Band? Doesn't support import and export of MIDI files. iMovie - doesn't support importing of multiplexed MPEG streams (and a bunch of other stuff), QuickTime Pro - you need to pay extra to deal with MPEG-2. Bah.

What I've always wanted to do is take short clips of various scenes in my DVD collection to create a new mpeg file, kinda like they do when the make "scenes from the next episode" on your standard TV program. But between the encryption, lossless (non-reencoding) cut n paste, and so forth I never figured out how to get it all done. MPEG2VCR (mentioned above) came close, but last time I checked they had just added support from MPEG-2, but all my streams showed up in a format it wouldn't deal with (everything I wanted to do was greyed out).



[ Reply to This | # ]
Sticking with the PC for now...
Authored by: jriskin on Feb 23, '04 05:20:52PM

I really wish there was an inexpensive easier way to do this on the mac. Right now I use the nanoPeg program that came with my Hauppauge250 that I use on the PC.

It would be really nice if there were more friendly tools on the mac. Maybe someone will see all this and write something...

Although iirc the problem is a licensing one.



[ Reply to This | # ]
Convert MPEG to DV with DropDV...
Authored by: MacProducer2 on Jun 14, '04 08:12:16PM


The easy way has arrived. Convert your MPEG files to DV streams with DropDV.

download at
http://www.dropdv.com/download/DropDV.dmg

Only $20 bucks.



[ Reply to This | # ]
Try this if you have Virtual PC
Authored by: wvasher on Feb 23, '04 07:47:28PM
It's the easiest way I've found and is the closest to being frame accurate. http://www.vasher.com/resources/pages/eyetvediting.php

[ Reply to This | # ]
Try this if you have Virtual PC
Authored by: Fofer on Feb 23, '04 08:58:00PM

That page specifically addresses the editing of MPEG-1 files that EyeTV produces. IIRC, however, EyeTV's software has a pretty nice editing feature built right into it.

I'm hoping the EyeTV 200 (Firewire model, which does MPEG-2) will not only have similar features, but that the editing software will work on MPEG-2 files from other sources. Hmm...



[ Reply to This | # ]
Doesn't work for me.
Authored by: FunkDaddy on Feb 23, '04 09:15:09PM

I d/l'd the files and attached the script to the Folder, but when I drop an .mpg on it nothing happens. - Any Suggestions?



[ Reply to This | # ]
Doesn't work for me.
Authored by: Mitchell on Feb 24, '04 12:31:56AM

If you look at the code, the first place it's likely to crash is at the initial "do shell script" command. It's characteristic of AppleScripts that they just do nothing when they fail. I would check to see if you have ffmpegX installed in your applications folder. I have an explicit path name in the code and if your copy of ffmpegX elsewhere, then you'll have to fix that. I'm calling one of the binaries for which ffmpegX is a wrapper, so that's why it's complicated.



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: IvanX on Feb 23, '04 11:37:11PM

Very cool! Another possibility for ReplayTV owners might be the application I am developing (and should have released in a week or so) which will allow you to edit ReplayTV files in QuickTime (with the MPEG-2 playback extension). It will be somewhat simpler than the above process. For those interested, keep checking http://www.macreplaytv.com.



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: Mitchell on Feb 24, '04 12:37:39AM

Easier than a drag-and-drop folder action? It can detect the commercials itself from the IDX files? Cool. I'll definitely get a copy.



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: Fofer on Feb 25, '04 07:09:22PM

Make it work with TiVo files as well and you'll get another happy user over here.... :)



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: Whosawhatsis on Feb 24, '04 12:27:01AM

mpgtx is definitely easier, just go to places in the movie where you want to cut it and copy the timestamps into it to cut it, then sort out the chunks that have the stuff you don't want and join the others. MUCH easier, and you don't need QT Pro or applescript (although it might be possible to automate a few more steps using the latter).

---
I was offered a penny for my thoughts, so I gave my two cents... I got ripped off.



[ Reply to This | # ]
Converting ReplayTV Files for DVD HOWTO
Authored by: SimonDorfman.com on Feb 25, '04 08:43:25AM
Edit MPEG files using QuickTime Player Pro
Authored by: baturjan on Jun 27, '04 01:35:26AM

Download the files needed to do all this from here. They're in the archive stored there as "Process Mpeg Files.sit."

The link mentioned above does not contain the "Process Mpeg Files.sit". I am very eager to try your hint, as I have been having a pain trying to edit my MPEG2 files from my new camcorder without having to reduce the quality through conversion to DV.

Your hint seems to be the answer to my month long saga of frustration.

thanks



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: bluehz on Jul 23, '04 11:15:25AM

Two more free options just came available - mpgtx (GUI and CLI) and MPEG Streamclip

Find them here:

mpgtx
http://www.biermann.org/philipp/mpegcut/

MPEG Streamclip
http://www.alfanet.it/squared5/mpegstreamclip.html

For mpgtx in CLI, you can use:

mpgtx movie1.mpg movie2.mpg etc.mpg -o output.mpg


[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: maclover888 on Aug 23, '04 07:21:58PM

This seem so complicated. I've been using PixeDV (part of CaptyDVD) to edit mpeg files from my replaytv, anybody else using it?



[ Reply to This | # ]
Edit MPEG files using QuickTime Player Pro
Authored by: wannabe on Sep 15, '04 03:47:30AM

"Timesaving" hints?

Don't waste any time on this. It will not work!

Why would it?

Replace a couple frames of a WAV export of the audio, slap it back into a QT container with the mpeg program, and presto! LOL

Did you know the Script Editor has a record feature!



[ Reply to This | # ]
Another method for lossless MPEG-1/2 edits - MPEG Streamclip
Authored by: victory on Feb 14, '05 11:54:04PM
I realize that Mitchell posted his hint over a year before this reply, but I thought I might share a nice (and free) MPEG video editing app I've just become aware of. I thought I'd mention it here for the benefit of others who arrived at this page in search of a similar solution.

The app is MPEG Streamclip and was at v1.2 at the time of this writing. Reading through the online-help guide, you get the impression that this is a fairly serious app. There's an extensive list of functions it performs, but what caught my attention is that thus far, it's the only OSX-based lossless MPEG editing app that *just seems to work*.

In my case it allows me to open standard multiplexed MPEG-1 files from my PVR, chop out unwanted sections, and re-save the edited content as another MPEG-1 file, all without re-compressing any of the data. (NOTE: Be sure to read the online documentation on the difference between just 'trimming' a clip and actually 'cutting' it). There have been lossless MPEG editors out for quite some time on the PC -- I'm really glad to see a usable (and freely available) one for OSX.

Congratulations and thanks to the developer (of whom I have no connection with)

[ Reply to This | # ]

Edit MPEG files using QuickTime Player Pro
Authored by: Zareste on Jul 28, '06 09:41:56PM

I find it easiest just to edit it and export as a hinted movie. The file size stays the same instead of increasing as in the Save As option, so I'd say that's the best choice without re-compressing.



[ Reply to This | # ]