Exemplo n.º 1
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 {
Exemplo n.º 2
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;
}