Esempio n. 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);
        }
    }

}
Esempio n. 2
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);
}