Esempio n. 1
0
int CMP4Tag::ReadMp4Tag(char *Filename)						 
{
MP4FileHandle MP4File;

	if(!(MP4File=MP4Read(Filename, 0)))
	{
	char buf[25+MAX_PATH+1];
		sprintf(buf,"ReadMp4Tag: can't open \"%s\"",Filename);
		MessageBox(NULL,buf,NULL,MB_OK);
		return 1;
	}

	FREE_ARRAY(copyright);
	MP4GetMetadataTool(MP4File, &copyright);

	FREE_ARRAY(artist);
	MP4GetMetadataArtist(MP4File, &artist);
	FREE_ARRAY(writer);
	MP4GetMetadataWriter(MP4File, &writer);
	FREE_ARRAY(title);
	MP4GetMetadataName(MP4File, &title);
	FREE_ARRAY(album);
	MP4GetMetadataAlbum(MP4File, &album);
	MP4GetMetadataTrack(MP4File, (unsigned __int16 *)&trackno, (unsigned __int16 *)&ntracks);
	MP4GetMetadataDisk(MP4File, (unsigned __int16 *)&discno, (unsigned __int16 *)&ndiscs);
	MP4GetMetadataCompilation(MP4File, (unsigned __int8 *)&compilation);
	FREE_ARRAY(year);
	MP4GetMetadataYear(MP4File, &year);
	FREE_ARRAY(genre);
	MP4GetMetadataGenre(MP4File, &genre);
	FREE_ARRAY(comment);
	MP4GetMetadataComment(MP4File, &comment);
	FREE_ARRAY(art.data);
	MP4GetMetadataCoverArt(MP4File, (unsigned __int8 **)&art.data, (u_int32_t *)&art.size);

	MP4Close(MP4File);
/*
	FILE *f=fopen("D:\\prova.jpg","wb");
		fwrite(artFile,1,artSize,f);
		fclose(f);*/
	return 0;
}
Esempio n. 2
0
bool mediaM4A(Artwork *art, const char *filePath)
{
    MP4FileHandle mp4file = MP4Read(filePath);
    if (mp4file == MP4_INVALID_FILE_HANDLE) {
        return false;
    }

    uint16_t numvalue, numvalue2;
    char *value;
    u_int8_t numbool;

    art->filetype = FILETYPE_M4A;

    if (MP4GetMetadataArtist(mp4file, &value) && value != NULL)
    {
        art->artist = (QString::fromUtf8(value)).trimmed();
        free(value);
    }
    if (MP4GetMetadataYear(mp4file, &value) && value != NULL)
    {
        art->year = QString(value).toInt();
        free(value);
    }

    if (MP4GetMetadataAlbum(mp4file, &value) && value != NULL)
    {
        art->album = (QString::fromUtf8(value)).trimmed();
        free(value);
    }

    if (MP4GetMetadataName(mp4file, &value) && value != NULL)
    {
        art->track = (QString::fromUtf8(value)).trimmed();
        free(value);
    }

    if (MP4GetMetadataWriter(mp4file, &value) && value != NULL)
    {
        // composer
        free(value);
    }

    if (MP4GetMetadataTrack(mp4file, &numvalue, &numvalue2))
    {
        art->trackNo = numvalue;
        art->trackCount = numvalue2;
    }

    if (MP4GetMetadataDisk(mp4file, &numvalue, &numvalue2))
    {
        art->discNo = numvalue;
        art->discCount = numvalue2;
    }

    if (MP4GetMetadataGenre(mp4file, &value) && value != NULL)
    {
        art->genre = (QString::fromUtf8(value)).trimmed();
        free(value);
    }

    if (MP4GetMetadataCompilation(mp4file, &numbool))
    {
        art->type = numbool ? ARTWORK_COMPILATION : ARTWORK_NORMAL;
    }

    /*
    art->bitrate = 0;
    art->sampleRate = 0;
    art->channels = 0;
    */

    MP4Duration duration = MP4GetDuration(mp4file);
    if (duration != MP4_INVALID_DURATION) {
        u_int64_t timescale = MP4GetTimeScale(mp4file);
        u_int64_t msectime = (duration * (u_int64_t) 1000) / timescale;
        u_int64_t sectime, mintime, hrtime;

        if (msectime == 0) {
            hrtime = mintime = sectime = (u_int64_t) 0;
        }
        else {
            hrtime = msectime / (u_int64_t) (3600 * 1000);
            msectime -= hrtime * (u_int64_t) (3600 * 1000);
            mintime = msectime / (u_int64_t) (60 * 1000);
            msectime -= (mintime * (u_int64_t) (60 * 1000));
            sectime = msectime / (u_int64_t) (1000);
            msectime -= sectime * (u_int64_t)(1000);
        }

        art->duration = hrtime * 3600 + mintime * 60 + sectime;
    }

    art->makeSearchable();
    if (!art->hasCover()) {
        uint8_t *cover = NULL;
        uint32_t cover_size;

        if (MP4GetMetadataCoverArt(mp4file, &cover, &cover_size)) {
            if (saveImage(art, (const char*) cover, cover_size)) {
                qDebug() << "MP4: invalid image in " << filePath;
            }
        }

        if (cover) {
            free(cover);
        }
    }

    MP4Close(mp4file);

    return true;
}
Esempio n. 3
0
bool LoadFileAAC(FILE_INFO *pFile)
{
    MP4FileHandle h = MP4Read(GetFullPath(pFile), 0);
    if (h == MP4_INVALID_FILE_HANDLE) {
		return false;
	}
	char* value;
	char* buff;
	u_int16_t no, total;
	if (MP4GetMetadataName(h, &value) == true) {
		if (UTF8toSJIS(value, &buff) == true) {
			SetTrackNameSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataArtist(h, &value) == true) {
		if (UTF8toSJIS(value, &buff) == true) {
			SetArtistNameSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataWriter(h, &value) == true) {
		if (UTF8toSJIS(value, &buff) == true) {
			SetComposerSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataComment(h, &value) == true) {
		if (UTF8toSJIS(value, &buff) == true) {
			SetCommentSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataTool(h, &value) == true) {
		if (UTF8toSJIS(value, &buff) == true) {
			SetSoftwareSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataYear(h, &value) == true) {
		if (UTF8toSJIS(value, &buff) == true) {
			SetYearSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataAlbum(h, &value) == true) {
		if (UTF8toSJIS(value, &buff) == true) {
			SetAlbumNameSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataAlbumArtist(h, &value) == true) { /* 取得できるようにmp4v2.dllを変更 */
		if (UTF8toSJIS(value, &buff) == true) {
			SetAlbumArtistSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataTrack(h, &no, &total) == true) {
		char trackNo[10];
		if (total > 0) {
			sprintf(trackNo, "%d/%d", no, total);
		} else {
			sprintf(trackNo, "%d", no);
		}
		SetTrackNumberSI(pFile, trackNo);
	}
	if (MP4GetMetadataDisk(h, &no, &total) == true) {
		char diskNo[10];
		if (total > 0) {
			sprintf(diskNo, "%d/%d", no, total);
		} else {
			sprintf(diskNo, "%d", no);
		}
		SetDiskNumberSI(pFile, diskNo);
	}
	if (MP4GetMetadataGenre(h, &value) == true) { /* 取得できるようにmp4v2.dllを変更 */
		if (UTF8toSJIS(value, &buff) == true) {
			SetGenreSI(pFile, buff);
			free(buff);
		}
	}
	if (MP4GetMetadataGrouping(h, &value) == true) { /* 取得できるようにmp4v2.dllに追加 */
		if (UTF8toSJIS(value, &buff) == true) {
			SetKeywordSI(pFile, buff);
			free(buff);
		}
	}
	CString strOther = "";
	{
		u_int16_t tempo;
		if (MP4GetMetadataTempo(h, &tempo) == true) {
			if (tempo > 0) {
				char buff[10];
				sprintf(buff, " %dBPM", tempo);
				strOther += buff;
			}
		}
	}
	{
		u_int8_t cpl;
		if (MP4GetMetadataCompilation(h, &cpl) == true) {
			if (cpl == 1) {
				strOther += " コンピレーションの一部";
			}
		}
	}

	//MP4TrackId trackId = MP4FindTrackId(pFile, 0, MP4_AUDIO_TRACK_TYPE);
	//SetAudioFormat(pFile, MP4Info(h));
	// mp4info.cpp PrintAudioInfo()
	MP4TrackId trackId = MP4FindTrackId(h, 0);
	static const char* mpeg4AudioNames[] = {
		"MPEG-4 AAC main",
		"MPEG-4 AAC LC", 
		"MPEG-4 AAC SSR",
		"MPEG-4 AAC LTP",
		NULL,
		"MPEG-4 AAC Scalable",
		"MPEG-4 TwinVQ",
		"MPEG-4 CELP",
		"MPEG-4 HVXC",
		NULL, NULL,
		"MPEG-4 TTSI",
		"MPEG-4 Main Synthetic",
		"MPEG-4 Wavetable Syn",
		"MPEG-4 General MIDI",
		"MPEG-4 Algo Syn and Audio FX",
		"MPEG-4 ER AAC LC",
		NULL,
		"MPEG-4 ER AAC LTP",
		"MPEG-4 ER AAC Scalable",
		"MPEG-4 ER TwinVQ",
		"MPEG-4 ER BSAC",
		"MPEG-4 ER ACC LD",
		"MPEG-4 ER CELP",
		"MPEG-4 ER HVXC",
		"MPEG-4 ER HILN",
		"MPEG-4 ER Parametric",
	};
	static u_int8_t mpegAudioTypes[] = {
		MP4_MPEG2_AAC_MAIN_AUDIO_TYPE,	// 0x66
		MP4_MPEG2_AAC_LC_AUDIO_TYPE,	// 0x67
		MP4_MPEG2_AAC_SSR_AUDIO_TYPE,	// 0x68
		MP4_MPEG2_AUDIO_TYPE,			// 0x69
		MP4_MPEG1_AUDIO_TYPE,			// 0x6B
		MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE,
		MP4_VORBIS_AUDIO_TYPE,
		MP4_ALAW_AUDIO_TYPE,
		MP4_ULAW_AUDIO_TYPE,
		MP4_G723_AUDIO_TYPE,
		MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE,
	};
	static const char* mpegAudioNames[] = {
		"MPEG-2 AAC Main",
		"MPEG-2 AAC LC",
		"MPEG-2 AAC SSR",
		"MPEG-2 Audio (13818-3)",
		"MPEG-1 Audio (11172-3)",
		"PCM16 (little endian)",
		"Vorbis",
		"G.711 aLaw",
		"G.711 uLaw",
		"G.723.1",
		"PCM16 (big endian)",
	};
	static u_int8_t numMpegAudioTypes = 
		sizeof(mpegAudioTypes) / sizeof(u_int8_t);

	u_int8_t type =
		MP4GetTrackEsdsObjectTypeId(h, trackId);
	const char* typeName = "Unknown";

	if (type == MP4_MPEG4_AUDIO_TYPE) {
	  u_int8_t* pAacConfig = NULL;
	  u_int32_t aacConfigLength;

	  MP4GetTrackESConfiguration(h, 
				     trackId,
				     &pAacConfig,
				     &aacConfigLength);

	  if (pAacConfig != NULL && aacConfigLength >= 2) {
	    type = (pAacConfig[0] >> 3) & 0x1f;
	    if (type == 0 || type == 5 || type == 10 || type == 11 ||
		type == 18 || type >= 28) {
	      typeName = "MPEG-4";
	    } else {
	        typeName = mpeg4AudioNames[type - 1];
	    }
	    MP4Free(pAacConfig);
	  } else {
Esempio n. 4
0
int ReadMP4Tag(MP4FileHandle file, medialib_tags *tags)
{
    unsigned __int32 valueSize;
    unsigned __int8 *pValue;
    char *pName;
    unsigned int i = 0;

    do {
        pName = 0;
        pValue = 0;
        valueSize = 0;

        MP4GetMetadataByIndex(file, i, (const char **)&pName, &pValue, &valueSize);

        if (valueSize > 0)
        {
            char *val = (char *)malloc(valueSize+1);
            if (!val) return 0;
            memcpy(val, pValue, valueSize);
            val[valueSize] = '\0';

            if (pName[0] == '\xa9')
            {
                if (memcmp(pName, "©nam", 4) == 0)
                {
                    tag_add_field(tags, "title", val);
                } else if (memcmp(pName, "©ART", 4) == 0) {
                    tag_add_field(tags, "artist", val);
                } else if (memcmp(pName, "©wrt", 4) == 0) {
                    tag_add_field(tags, "writer", val);
                } else if (memcmp(pName, "©alb", 4) == 0) {
                    tag_add_field(tags, "album", val);
                } else if (memcmp(pName, "©day", 4) == 0) {
                    tag_add_field(tags, "date", val);
                } else if (memcmp(pName, "©too", 4) == 0) {
                    tag_add_field(tags, "tool", val);
                } else if (memcmp(pName, "©cmt", 4) == 0) {
                    tag_add_field(tags, "comment", val);
                } else if (memcmp(pName, "©gen", 4) == 0) {
                    tag_add_field(tags, "genre", val);
                } else {
                    tag_add_field(tags, pName, val);
                }
            } else if (memcmp(pName, "gnre", 4) == 0) {
                char *t=0;
                if (MP4GetMetadataGenre(file, &t))
                {
                    tag_add_field(tags, "genre", t);
                }
            } else if (memcmp(pName, "trkn", 4) == 0) {
                unsigned __int16 trkn = 0, tot = 0;
                char t[200];
                if (MP4GetMetadataTrack(file, &trkn, &tot))
                {
                    if (tot > 0)
                        wsprintf(t, "%d/%d", trkn, tot);
                    else
                        wsprintf(t, "%d", trkn);
                    tag_add_field(tags, "tracknumber", t);
                }
            } else if (memcmp(pName, "disk", 4) == 0) {
                unsigned __int16 disk = 0, tot = 0;
                char t[200];
                if (MP4GetMetadataDisk(file, &disk, &tot))
                {
                    if (tot > 0)
                        wsprintf(t, "%d/%d", disk, tot);
                    else
                        wsprintf(t, "%d", disk);
                    tag_add_field(tags, "disc", t);
                }
            } else if (memcmp(pName, "cpil", 4) == 0) {
                unsigned __int8 cpil = 0;
                char t[200];
                if (MP4GetMetadataCompilation(file, &cpil))
                {
                    wsprintf(t, "%d", cpil);
                    tag_add_field(tags, "compilation", t);
                }
            } else if (memcmp(pName, "tmpo", 4) == 0) {
                unsigned __int16 tempo = 0;
                char t[200];
                if (MP4GetMetadataTempo(file, &tempo))
                {
                    wsprintf(t, "%d BPM", tempo);
                    tag_add_field(tags, "tempo", t);
                }
            } else if (memcmp(pName, "NDFL", 4) == 0) {
                /* Removed */
            } else {
                tag_add_field(tags, pName, val);
            }

            free(val);
        }

        i++;
    } while (valueSize > 0);

    return 1;
}
Esempio n. 5
0
DWORD CTag_Mp4::Load(LPCTSTR szFileName)
{
    DWORD dwWin32errorCode = ERROR_SUCCESS;
    Release();

    char *pFileName = TstrToDataAlloc(szFileName, -1, NULL, DTC_CODE_UTF8);
    if (pFileName == NULL) {
        return -1;
    }
    char *info = MP4FileInfo(pFileName);
    if(!info)
    {
        free(pFileName);
        Release();
        return -1;
    }
    m_strTrackInfo = info;
    free(info);
    m_strTrackInfo.Replace(_T("\n"),_T("\r\n"));

    // Audio/Video
    _StripAudioInfo(m_strTrackInfo,m_strAudioInfo,m_strVideoInfo);

    MP4FileHandle mp4file = MP4Read(pFileName);
    free(pFileName);
    if(mp4file == MP4_INVALID_FILE_HANDLE)
    {
        Release();
        return -1;
    }

    m_bEnable = TRUE;
    char *value;
    uint16_t numvalue, numvalue2;
    uint8_t int8value;

#ifdef USE_OLD_TAG_API
    if(MP4GetMetadataName(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Name = _CnvMetadata(value);
    }

    if(MP4GetMetadataArtist(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Artist = _CnvMetadata(value);
    }

    if(MP4GetMetadataAlbum(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Album = _CnvMetadata(value);
    }

    if(MP4GetMetadataGrouping(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Group = _CnvMetadata(value);
    }

    if(MP4GetMetadataWriter(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Composer = _CnvMetadata(value);
    }

    if(MP4GetMetadataGenre(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Genre = _CnvMetadata(value);
    }

    if(MP4GetMetadataTrack(mp4file,&numvalue,&numvalue2))
    {
        m_iMetadata_Track1 = numvalue;
        m_iMetadata_Track2 = numvalue2;
    }

    if(MP4GetMetadataDisk(mp4file,&numvalue,&numvalue2))
    {
        m_iMetadata_Disc1 = numvalue;
        m_iMetadata_Disc2 = numvalue2;
    }

    if(MP4GetMetadataTempo(mp4file,&numvalue))
    {
        m_iMetadata_Tempo = numvalue;
    }

    if(MP4GetMetadataYear(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Year = _CnvMetadata(value);
    }

    if(MP4GetMetadataCompilation(mp4file,&int8value))
    {
        m_iMetadata_Compilation = int8value;
    }

    if(MP4GetMetadataComment(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Comment = _CnvMetadata(value);
    }

    if(MP4GetMetadataTool(mp4file,&value) && (value != NULL))
    {
        m_strMetadata_Tool = _CnvMetadata(value);
    }
#else
    const MP4Tags* tags = MP4TagsAlloc();

    if(tags)
    {
        MP4TagsFetch(tags, mp4file);

        if(tags->name)
        {
            m_strMetadata_Name = _CnvMetadata(tags->name);
        }

        if(tags->artist)
        {
            m_strMetadata_Artist = _CnvMetadata(tags->artist);
        }

        if(tags->album)
        {
            m_strMetadata_Album = _CnvMetadata(tags->album);
        }

        if(tags->grouping)
        {
            m_strMetadata_Group = _CnvMetadata(tags->grouping);
        }

        if(tags->composer)
        {
            m_strMetadata_Composer = _CnvMetadata(tags->composer);
        }

        if(tags->genre)
        {
            m_strMetadata_Genre = _CnvMetadata(tags->genre);
        }

        if(tags->track)
        {
            m_iMetadata_Track1 = tags->track->index;
            m_iMetadata_Track2 = tags->track->total;
        }

        if(tags->disk)
        {
            m_iMetadata_Disc1 = tags->disk->index;
            m_iMetadata_Disc2 = tags->disk->total;
        }

        if(tags->tempo)
        {
            m_iMetadata_Tempo = *tags->tempo;
        }

        if(tags->releaseDate)
        {
            m_strMetadata_Year = _CnvMetadata(tags->releaseDate);
        }

        if(tags->compilation)
        {
            m_iMetadata_Compilation = *tags->compilation;
        }

        if(tags->comments)
        {
            m_strMetadata_Comment = _CnvMetadata(tags->comments);
        }

        if(tags->encodingTool)
        {
            m_strMetadata_Tool = _CnvMetadata(tags->encodingTool);
        }

        MP4TagsFree(tags);
    }
#endif

    MP4Close(mp4file);

    return dwWin32errorCode;
}
Esempio n. 6
0
bool MP4::File::save()
{
    MP4Close(mp4file);

    MP4FileHandle handle = MP4Modify(name());
    if(handle == MP4_INVALID_FILE_HANDLE)
    {
        mp4file = MP4Read(name());
        return false;
    }

#ifdef MP4V2_HAS_WRITE_BUG
    /* according to gtkpod we have to delete all meta data before modifying it,
       save the stuff we would not touch */

    // need to fetch/rewrite this only if we aren't going to anyway
    uint8_t compilation = 0;
    bool has_compilation = mp4tag->compilation() == MP4::Tag::Undefined ? MP4GetMetadataCompilation(handle, &compilation) : false;

    char *tool = NULL;
    MP4GetMetadataTool(handle, &tool);

    MP4MetadataDelete(handle);
#endif



#define setmeta(val, tag) \
    if(mp4tag->val().isNull()) { \
        /*MP4DeleteMetadata##tag(handle);*/ \
        MP4SetMetadata##tag(handle, ""); \
    } else { \
        MP4SetMetadata##tag(handle, mp4tag->val().toCString(true)); \
    }

    setmeta(title, Name);
    setmeta(artist, Artist);
    setmeta(album, Album);
    setmeta(comment, Comment);
    setmeta(genre, Genre);

    char buf[100] = "";
    if(mp4tag->year())
        snprintf(buf, sizeof(buf), "%u", mp4tag->year());
    MP4SetMetadataYear(handle, buf);
    u_int16_t t1, t2;
    MP4GetMetadataTrack(handle, &t1, &t2);
    MP4SetMetadataTrack(handle, mp4tag->track(), t2);
    if(mp4tag->bpm() != 0)
        MP4SetMetadataTempo(handle, mp4tag->bpm());
    if(mp4tag->compilation() != MP4::Tag::Undefined) {
        MP4SetMetadataCompilation(handle, mp4tag->compilation());
    }

    MP4SetMetadataCoverArt(handle, mp4tag->cover().size() ? const_cast<u_int8_t *>( reinterpret_cast<const u_int8_t *>( mp4tag->cover().data() ) ) : 0, mp4tag->cover().size());

#ifdef MP4V2_HAS_WRITE_BUG
    // set the saved data again

    if(has_compilation)
        MP4SetMetadataCompilation(handle, compilation);
    if(tool)
    {
        MP4SetMetadataTool(handle, tool);
        free(tool);
    }
#endif

    MP4Close(handle);

    mp4file = MP4Read(name());
    if(mp4file == MP4_INVALID_FILE_HANDLE)
    {
        fprintf(stderr, "reopen failed\n");
        return false;
    }

    return true;
}