wisherzhang / mp4v2

Automatically exported from code.google.com/p/mp4v2
Other
0 stars 0 forks source link

No way to leave a file untouched if settings tags for writing fails #96

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Consider what mp4tags.cpp does to write a file.  It's basically:

MP4FileHandle h = MP4Modify( mp4 );
const MP4Tags* mdata = MP4TagsAlloc();
MP4TagsFetch( mdata, h );

< make a bunch of changes >

MP4TagsStore( mdata, h );
MP4TagsFree( mdata );
MP4Close( h );

The trouble is, MP4TagsStore (or really any operation after calling MP4Modify) 
can fail.  By itself, that's not so bad, but let's assume we want to give up in 
the middle and not write the file after all.  The way MP4Modify and MP4Close 
(really MP4File::Modify and MP4File::Close) work makes it hard to leave the 
file alone.  It'd be nice if this code in MP4File::Close were optional:

    if( IsWriteMode() ) {
        SetIntegerProperty( "moov.mvhd.modificationTime", MP4GetAbsTimestamp() );
        FinishWrite();
    }

I'll come up with patch if people agree this is good idea.

Original issue reported on code.google.com by dbyr...@gmail.com on 19 Apr 2011 at 9:48

GoogleCodeExporter commented 8 years ago
Not sure if you can use it, but I added an optional flag argument to 
MP4Close(), so maybe you could pass in a flag to skip the FinishWrite() call?

Original comment by kid...@gmail.com on 26 Jun 2011 at 6:55