Example #1
0
void MP4File::Make3GPCompliant(const char* fileName,  char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount, bool deleteIodsAtom)
{
    char brand[5] = "3gp5";
    char* _3gpSupportedBrands[1] = { (char*)&brand };

    if (majorBrand) {
        if (!supportedBrands || !supportedBrandsCount) {
            throw new MP4Error("Invalid parameters", "MP4File::Make3GPCompliant");
        }
    }

    MakeFtypAtom(
        majorBrand ? majorBrand : (char*)brand,
        majorBrand ? minorVersion  : _3GP_MINOR_VERSION,
        majorBrand ? supportedBrands : (char**)_3gpSupportedBrands,
        majorBrand ? supportedBrandsCount : 1);

    if (deleteIodsAtom) {
        // Delete the iods atom, if it exists....
        MP4Atom* iodsAtom = m_pRootAtom->FindAtom("moov.iods");
        if (iodsAtom) {
            MP4Atom* moovAtom = m_pRootAtom->FindAtom("moov");
            ASSERT(moovAtom);

            moovAtom->DeleteChildAtom(iodsAtom);
        }
    }

}
Example #2
0
bool
genericSetItem( MP4File& file, const MP4ItmfItem* item )
{
    if( !item || !item->__handle )
        return false;

    MP4Atom* ilst = file.FindAtom( "moov.udta.meta.ilst" );
    if( !ilst )
        return false;

    MP4ItemAtom* const old = static_cast<MP4ItemAtom*>(item->__handle);
    const uint32_t childCount = ilst->GetNumberOfChildAtoms();
    uint32_t fidx = numeric_limits<uint32_t>::max();
    for( uint32_t i = 0; i < childCount; i++ ) {
        MP4Atom* atom = ilst->GetChildAtom( i );
        if( atom == old ) {
            fidx = i;
            break;
        }
    }

    if( fidx == numeric_limits<uint32_t>::max() )
        return false;

    ilst->DeleteChildAtom( old );
    delete old;

    MP4ItemAtom& itemAtom = *(MP4ItemAtom*)MP4Atom::CreateAtom( file, ilst, item->code );
    ilst->InsertChildAtom( &itemAtom, fidx );

    return __itemModelToAtom( *item, itemAtom );
}
bool
PictureAspectRatioBox::remove( MP4FileHandle file, uint16_t trackIndex )
{
    MP4Atom* coding;
    if( findCoding( file, trackIndex, coding ))
        throw new MP4Exception( "supported coding not found" );

    MP4Atom* pasp;
    if( findPictureAspectRatioBox( file, *coding, pasp ))
        throw new MP4Exception( "pasp-box not found" );

    coding->DeleteChildAtom( pasp );
    delete pasp;

    return false;
}
Example #4
0
bool
genericRemoveItem( MP4File& file, const MP4ItmfItem* item )
{
    if( !item || !item->__handle )
        return false;

    MP4Atom* ilst = file.FindAtom( "moov.udta.meta.ilst" );
    if( !ilst )
        return false;

    MP4ItemAtom* const old = static_cast<MP4ItemAtom*>(item->__handle);
    ilst->DeleteChildAtom( old );
    delete old;

    return true;
}
Example #5
0
void MP4File::Make3GPCompliant(const char* fileName,  char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount, bool deleteIodsAtom)
{
    char brand[5] = "3gp5";
    char* _3gpSupportedBrands[1] = { (char*)&brand };

    if (majorBrand) {
        if (!supportedBrands || !supportedBrandsCount) {
            throw new MP4Error("Invalid parameters", "MP4File::Make3GPCompliant");
        }
    }

    m_fileName = MP4Stralloc(fileName);
    m_mode = 'r';
    // first load meta-info into memory
    Open("rb");
    ReadFromFile();

    CacheProperties();	// of moov atom

    // now switch over to writing the new file
    MP4Free(m_fileName);
    // create a temporary file
    m_fileName = MP4Stralloc(TempFileName());

    MakeFtypAtom(
        majorBrand ? majorBrand : (char*)brand,
        majorBrand ? minorVersion  : _3GP_MINOR_VERSION,
        majorBrand ? supportedBrands : (char**)_3gpSupportedBrands,
        majorBrand ? supportedBrandsCount : 1);

    if (deleteIodsAtom) {
        // Delete the iods atom, if it exists....
        MP4Atom* iodsAtom = m_pRootAtom->FindAtom("moov.iods");
        if (iodsAtom) {
            MP4Atom* moovAtom = m_pRootAtom->FindAtom("moov");
            ASSERT(moovAtom);

            moovAtom->DeleteChildAtom(iodsAtom);
        }
    }


    FILE* pReadFile = m_pFile;
    m_pFile = NULL;
    m_mode = 'w';

    Open("wb");

    SetIntegerProperty("moov.mvhd.modificationTime",
                       MP4GetAbsTimestamp());

    // writing meta info in the optimal order
    ((MP4RootAtom*)m_pRootAtom)->BeginOptimalWrite();

    // write data in optimal order
    RewriteMdat(pReadFile, m_pFile);

    // finish writing
    ((MP4RootAtom*)m_pRootAtom)->FinishOptimalWrite();

    // cleanup
    fclose(m_pFile);
    m_pFile = NULL;
    fclose(pReadFile);

    // move temporary file into place
    Rename(m_fileName, fileName);
}