X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=libhb%2Fdecmetadata.c;h=e377f8c25c95410ea0c46859f56e9d27aaa8b9dc;hb=033e32de9c380f54c7d1362a3979da205ebc3a29;hp=7ac9bcffa8a7ec73f5e5a4a7b90e84744727adb4;hpb=0f25cfb3cfac4feff657bb79bcc0b689baa99860;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/libhb/decmetadata.c b/libhb/decmetadata.c index 7ac9bcff..e377f8c2 100644 --- a/libhb/decmetadata.c +++ b/libhb/decmetadata.c @@ -8,117 +8,60 @@ #include "common.h" -void identify_art_type( hb_metadata_t *metadata ) -{ - typedef struct header_s { - enum arttype type; - char* name; // short string describing name of type - char* data; // header-bytes to match - } header; - - // types which may be detected by first-bytes only - static header headers[] = { - { BMP, "bmp", "\x4d\x42" }, - { GIF87A, "GIF (87a)", "GIF87a" }, - { GIF89A, "GIF (89a)", "GIF89a" }, - { JPG, "JPEG", "\xff\xd8\xff\xe0" }, - { PNG, "PNG", "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" }, - { TIFFL, "TIFF (little-endian)", "II42" }, - { TIFFB, "TIFF (big-endian)", "MM42" }, - { UNKNOWN } // must be last - }; - header* p; - header* found = NULL; - for( p = headers; p->type != UNKNOWN; p++ ) { - header *h = p; - - if( metadata->coverart_size < strlen(h->data) ) - continue; - - if( memcmp(h->data, metadata->coverart, strlen(h->data)) == 0 ) { - metadata->coverart_type = h->type; - break; - } - } -} - static void decmp4metadata( hb_title_t *title ) { MP4FileHandle input_file; - hb_deep_log( 2, "Got an MP4 input, read the metadata"); input_file = MP4Read( title->dvd, 0 ); if( input_file != MP4_INVALID_FILE_HANDLE ) { - char *value = NULL; - uint8_t *cover_art = NULL; - uint32_t size; - uint32_t count; - /* * Store iTunes MetaData */ - if( MP4GetMetadataName( input_file, &value) && value ) - { - hb_deep_log( 2, "Metadata Name in input file is '%s'", value); - strncpy( title->metadata->name, value, 255); - MP4Free(value); - value = NULL; - } + const MP4Tags* tags; - if( MP4GetMetadataArtist( input_file, &value) && value ) - { - strncpy( title->metadata->artist, value, 255); - MP4Free(value); - value = NULL; - } - - if( MP4GetMetadataComposer( input_file, &value) && value ) - { - strncpy( title->metadata->composer, value, 255); - MP4Free(value); - value = NULL; - } + /* alloc,fetch tags */ + tags = MP4TagsAlloc(); + MP4TagsFetch( tags, input_file ); - if( MP4GetMetadataComment( input_file, &value) && value ) - { - strncpy( title->metadata->comment, value, 1024); - value = NULL; - } - - if( MP4GetMetadataReleaseDate( input_file, &value) && value ) - { - strncpy( title->metadata->release_date, value, 255); - MP4Free(value); - value = NULL; + if( tags->name ) { + hb_deep_log( 2, "Metadata Name in input file is '%s'", tags->name ); + strncpy( title->metadata->name, tags->name, sizeof(title->metadata->name) ); } - - if( MP4GetMetadataAlbum( input_file, &value) && value ) - { - strncpy( title->metadata->album, value, 255); - MP4Free(value); - value = NULL; - } - - if( MP4GetMetadataGenre( input_file, &value) && value ) - { - strncpy( title->metadata->genre, value, 255); - MP4Free(value); - value = NULL; - } - - if( MP4GetMetadataCoverArt( input_file, &cover_art, &size, 0) && - cover_art ) - { - title->metadata->coverart = cover_art; - title->metadata->coverart_size = size; - identify_art_type( title->metadata ); + + if( tags->artist ) + strncpy( title->metadata->artist, tags->artist, sizeof(title->metadata->artist) ); + + if( tags->composer ) + strncpy( title->metadata->composer, tags->composer, sizeof(title->metadata->composer) ); + + if( tags->comments ) + strncpy( title->metadata->comment, tags->comments, sizeof(title->metadata->comment) ); + + if( tags->releaseDate ) + strncpy( title->metadata->release_date, tags->releaseDate, sizeof(title->metadata->release_date) ); + + if( tags->album ) + strncpy( title->metadata->album, tags->album, sizeof(title->metadata->album) ); + + if( tags->genre ) + strncpy( title->metadata->genre, tags->genre, sizeof(title->metadata->genre) ); + + if( tags->artworkCount > 0 ) { + const MP4TagArtwork* art = tags->artwork + 0; // first element + title->metadata->coverart = (uint8_t*)malloc( art->size ); + title->metadata->coverart_size = art->size; + memcpy( title->metadata->coverart, art->data, art->size ); hb_deep_log( 2, "Got some cover art of type %d, size %d", - title->metadata->coverart_type, - title->metadata->coverart_size); + art->type, + title->metadata->coverart_size ); } + + /* store,free tags */ + MP4TagsStore( tags, input_file ); + MP4TagsFree( tags ); /* * Handle the chapters. @@ -129,8 +72,8 @@ static void decmp4metadata( hb_title_t *title ) MP4GetChapters( input_file, &chapter_list, &chapter_count, MP4ChapterTypeQt ); - if( chapter_list ) { - uint i = 1; + if( chapter_list && ( hb_list_count( title->list_chapter ) == 0 ) ) { + uint32_t i = 1; while( i <= chapter_count ) { hb_chapter_t * chapter; @@ -141,7 +84,7 @@ static void decmp4metadata( hb_title_t *title ) chapter->minutes = ( ( chapter->duration / 90000 ) % 3600 ) / 60; chapter->seconds = ( chapter->duration / 90000 ) % 60; strcpy( chapter->title, chapter_list[i-1].title ); - hb_deep_log( 2, "Added chapter %i, name='%s', dur=%lld, (%02i:%02i:%02i)", chapter->index, chapter->title, + hb_deep_log( 2, "Added chapter %i, name='%s', dur=%"PRId64", (%02i:%02i:%02i)", chapter->index, chapter->title, chapter->duration, chapter->hours, chapter->minutes, chapter->seconds); hb_list_add( title->list_chapter, chapter );