GOPchop - MPEG2 GOP-accurate editor
Released under GNU General Public License
Kees Cook (kees@outflux.net)


This tool is used for people wanting to take sections out of MPEG2-PS 
files without re-encoding the resulting frames.  The idea is to write 
specific "Group of Pictures" (GOP) sections to a new MPEG2-PS file.  These 
GOPs will decode correctly (in theory), and the gaps won't be noticed.  I 
wrote this tool to edit commercials out of MPEG2 files produced by my 
capture card.  Using this tool for anything else is really beyond the 
scope of its design.


Requirements
------------
For GOPchop to work, you need two things: GTK-1.2, and the CVS version
of mpeg2dec.  (0.2.0 will work with some work...)  For mpeg2dec, it's
expected that all the libraries and includes have been installed on your
system.  In my CVS copy, one particular library (libcpuaccel) doesn't
appear to install during "make install".  This library can be found in
mpeg2dec-0.2.0/src/.libs  Copy it to where ever the other mpeg2dec 
libraries went, and "configure" should notice it.


Compiling
---------
"./configure" should do the trick.  If you have RedHat or some pre-3.0 
gcc, you may have Issues(tm) compiling (and running).  I'd recommend using
3.0+ of gcc and g++.  If you have both packages installed (RedHat 7.2), you
can run "CC=gcc3 CXX=g++3 ./configure" to force configure to use the right
compiler.

I'm still inexperienced when it comes to making and using "./configure" 
files, so for computers that are not mine, you might have to fix things to 
get everything to compile.  If you find stuff that needs correcting, 
please email me and I'll update it.  :)


Using GOPchop
-------------
The basic way to use GOPchop is like so:

 1) Run GOPchop.
 2) Select an MPEG2 with "File / Open".
 3) Drag the slider to the first GOP you want to have in a clip.
		(You can disable "Options / Auto-Refresh" to seek
		 faster, and then click "Refresh" to see where you
		 are in the file.)
 4) Click "Start Mark".
 5) Drag the slider to the last GOP you want in the clip.
 6) Click "End Mark".  (If you drag the slider somewhere before the
		first mark, "End Mark" will not do anything.)
 7) Repeat steps 3 through 6 to select all the clips you want saved.
 8) Drag clips up and down to reorder them in the Clip List window.
 9) To delete unwanted clips, select it, and hit Del or Backspace.
10) Save the clips to a new MPEG2 with "File / Save Clips".

If you want to save different clips, select "File / Clear Clips" and start 
over at step 3.  If you want to use a differnet source MPEG2, select "File 
/ Close" and start over at step 1.

At present, I don't support saving clips from multiple different MPEG2 
source files.  In the future, perhaps.


VOB Files
---------
Since DVD VOB files are MPEG2, you can use GOPchop to pull scenes.  
HOWEVER, GOPchop is not a DVD-authentication tool.  I might go look at 
libdvdread, but I require an mmap-able file interface (like, say, a direct 
filesystem "open" call).  If you have unencrypted DVDs, or can get the 
unencrypted VOB somewhere to use "open" on it, GOPchop should have no 
problems with it.


What to expect during MPEG2 loading
-----------------------------------
Usually, when GOPchop loads an MPEG2, there will be some "errors" near the 
end of the file.  These errors can generally be ignored.  They have to do 
with how your MPEG2 was created, and expected packet information or 
end-of-file codes might be missing.  That's perfectly okay.  (Even MPEG2s 
_made_ by GOPchop issue this warning.  :P)

I didn't implement parsing for every MPEG2 System packet header out there.  
It's in my TODO list to do it, but you might not be able to load some 
MPEG2s.  The error will say something about "Need to write a parsing 
routine".  Email me if you run into this, and I can get it finished up for 
you.


How it works
------------
I scan the MPEG2 for a full list of System packets, then examine the
Program Element Stream packets they contain.  In the video PES, I look for
GOP headers (and Picture headers).  Each GOP is then mapped back to the
System packets that contain it (a full GOP can span multiple VES packets,
and multiple System packets).  When a GOP is saved to a new file, the
entire System packet list for that GOP is written as a byte-for-byte copy
from the source MPEG2. In theory, this will take any audio streams along
for the ride.  So far, so good.  :)



KNOWN ISSUES
------------
mpeg2dec (and libvo) sometimes just up and segfault when they bring up a
window.  I think this is from a bad compiler (using gcc 3+ seems to have
made the problem go away for me.  I hope you don't see this bug, but it
doesn't appear to be my code's fault.  ;)

Some audio streams don't take kindly to be chopped like this.  However, 
they usually have CRC to detect problems.  For example, I snipped together 
some scenes from a DVD, and when playing back with "MPlayer", the AC3 
audio stream reported CRC errors and gracefully dropped the garbled 
packet.  As for the playback, I didn't notice it at all.

GOPchop assumes that all GOPs will appear in the first video PES packet of 
a System packet.  Technically, this might not be true, but in practice, 
this seems to happen.  As a result, GOPchop could fail to load some 
"unusual" MPEG2 files.  If you have some examples, please email me, and 
maybe I can fix my code.  :)

If you make changes to the widgets with Glade, on a build, it will spit
out "main.c".  You'll have to delete this file to get GOPchop to compile
again correctly.  :)



Acknowledgements
----------------
Kirsten for not kicking me out of the house while I hacked this together
for a week straight.  :)

Paul for having lots and lots of commercials to edit out of MPEG2s.

Various people from the KFir MPEG2 list (mpeg2@linuxtv.org) for guiding me
towards this program's basic design, especially:
	Warren Young (warren@etr-usa.com)
	Marcus Metzler (mocm@convergence.de)


-- 
Kees Cook (kees@outflux.net)
http://outflux.net/
