src/main/java/org/jcodec/movtool/InplaceMP4Editor.java
public boolean copy(File src, File dst, MP4Edit edit) throws IOException {
        SeekableByteChannel fi = null;
        SeekableByteChannel fo = null;
        try {
            fi = NIOUtils.readableChannel(src);
            fo = NIOUtils.writableChannel(dst);

            List<Tuple._2<Atom, ByteBuffer>> fragments = doTheFix(fi, edit);
            if (fragments == null)
                return false;

            List<_2<Long, ByteBuffer>> fragOffsets = Tuple._2map0(fragments, new Tuple.Mapper<Atom, Long>() {
                public Long map(Atom t) {
                    return t.getOffset();
                }
            });

            // If everything is clean, only then actually start writing file
            Map<Long, ByteBuffer> rewrite = Tuple.asMap(fragOffsets);
            for (Atom atom : MP4Util.getRootAtoms(fi)) {
                ByteBuffer byteBuffer = rewrite.get(atom.getOffset());
                if (byteBuffer != null)
                    fo.write(byteBuffer);
                else
                    atom.copy(fi, fo);
            }

            return true;
        } finally {
            NIOUtils.closeQuietly(fi);
            NIOUtils.closeQuietly(fo);
        }
    }
public boolean copy(File src, File dst, MP4Edit edit) throws IOException {
        SeekableByteChannel fi = null;
        SeekableByteChannel fo = null;
        try {
            fi = NIOUtils.readableChannel(src);
            fo = NIOUtils.writableChannel(dst);

            List<Tuple._2<Atom, ByteBuffer>> fragments = doTheFix(fi, edit);
            if (fragments == null)
                return false;

            List<_2<Long, ByteBuffer>> fragOffsets = Tuple._2map0(fragments, new Tuple.Mapper<Atom, Long>() {
                public Long map(Atom t) {
                    return t.getOffset();
                }
            });

            // If everything is clean, only then actually start writing file
            Map<Long, ByteBuffer> rewrite = Tuple.asMap(fragOffsets);
            for (Atom atom : MP4Util.getRootAtoms(fi)) {
                ByteBuffer byteBuffer = rewrite.get(atom.getOffset());
                if (byteBuffer != null)
                    fo.write(byteBuffer);
                else
                    atom.copy(fi, fo);
            }

            return true;
        } finally {
            NIOUtils.closeQuietly(fi);
            NIOUtils.closeQuietly(fo);
        }
    }
public boolean copy ( File src , File dst , MP4Edit edit ) throws IOException { SeekableByteChannel fi = null ; SeekableByteChannel fo = null ; try { fi = NIOUtils . readableChannel ( src ) ; fo = NIOUtils . writableChannel ( dst ) ; List < Tuple . _2 < Atom , ByteBuffer > > fragments = doTheFix ( fi , edit ) ; if ( fragments == null ) return false ; List < _2 < Long , ByteBuffer > > fragOffsets = Tuple . _2map0 ( fragments , new Tuple . Mapper < Atom , Long > ( ) { public Long map ( Atom t ) { return t . getOffset ( ) ; } } ) ; // If everything is clean, only then actually start writing file Map < Long , ByteBuffer > rewrite = Tuple . asMap ( fragOffsets ) ; for ( Atom atom : MP4Util . getRootAtoms ( fi ) ) { ByteBuffer byteBuffer = rewrite . get ( atom . getOffset ( ) ) ; if ( byteBuffer != null ) fo . write ( byteBuffer ) ; else atom . copy ( fi , fo ) ; } return true ; } finally { NIOUtils . closeQuietly ( fi ) ; NIOUtils . closeQuietly ( fo ) ; } }
Tries to modify movie header in place according to what's implemented in
the edit. Copies modified contents to a new file.

Note: The header is still edited in-place, so the new file will have
all-the-same sample offsets.

Note: Still subject to the same limitations as 'modify', i.e. the new
header must 'fit' into an old place.

This method is useful when you can't write to the original file, for ex.
you don't have permission.

@param src
An original file
@param dst
A file to store the modified copy
@param edit
An edit logic to apply
@return
@throws IOException
Tries to modify movie header in place according to what s implemented in the edit . Copies modified contents to a new file .