jdzyzh / mp4v2

Automatically exported from code.google.com/p/mp4v2
Other
0 stars 0 forks source link

I have a count (4) for artwork now so how do I get 2 3 and 4 ? #56

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Using the MP4TagsFetch 
2.
3.

What is the expected output? What do you see instead?

Ok the count of artwork was fixed ( R372 ) but now the problem is 
if you do have more than one piece of artwork how do you 
get the others. The Get function (CoverArtBox::get ) looks like
it would be perfect but it is not an exported function ( in the DLL )
I'm i missing something here ? I sure its easy to Export a function 
but still working on that.   

What version of the product are you using? On what operating system?

mp4v2-trunk-r355 with CoverArtBox R372   Visual C++ Windows XP

Please provide any additional information below.

I'm not an expert on C++ ( yet ) but I fixed a 
problem with the CoverArtBox::get  function 
// --------------    changes start here
--------------------------------------------------
    // the problem here is that some programs have the wrong number 
    // in the "type" or just 00 hence we end up with the wrong types 
    // better bet is to find the type using the routine already in place ! 
    // rather than screw up the rest ( got an Exception error without )
    // just let the lib take care of this 
    metadata->GetValue( &item.buffer, &item.size );
    item.autofree = true;
    item.type = data->typeCode.GetValue();
    item.type = BT_UNDEFINED; // setting this here overrides the value above ! 
                              // i'm sure there is a better way to do this 
                              // I will leave that to the code gods 
    // autodetect type if BT_UNDEFINED  we only need the first twenty bytes 
    // this borrowed from the set cover art ! 
    item.type = (item.type == BT_UNDEFINED) ? computeBasicType(
item.buffer, 20 ): item.type;
//  --------------------------------   end changes
------------------------------------    

Original issue reported on code.google.com by wils...@tampabay.rr.com on 26 Feb 2010 at 9:13

Attachments:

GoogleCodeExporter commented 8 years ago
Does this code in tags.c not work for you?

    if( tags->artworkCount ) {
        const MP4TagArtwork* art = tags->artwork; /* artwork != NULL when
artworkCount > 0 */
        uint32_t i;
        for( i = 0; i < tags->artworkCount; i++, art++ )
            printf( "art[%d]: type=%d size=%u data=%p\n", i, art->type, art->size,
art->data );
    }

...admittedly it seems like tags->artwork would need to be **, but give this 
code a
try and let me know how it goes.

Original comment by kid...@gmail.com on 6 Apr 2010 at 2:58

GoogleCodeExporter commented 8 years ago
Yes this works to inform you of how many artworks are available. The problem is 
that
the Tags structure only
retrieves the Last art work. In the Meta data we had GetMetadataCoverArt Which 
allows
you to get the artwork by index.
As far as I can find there is no similar function in the New "Tags" version. Am 
I
Missing it ? ( I will feel like a fool if I am )
I did a temporary change to the GetMetadataCoverArt  for my use that includes 
the
arttype. It was simple and saves me the time
Seemed silly not to return the arttype when you are retrieving a piece of 
artwork.
Thanx for your help !

Below is the modifications that I made to the 1.91 release to get what I wanted.
Seems like it would not be that hard to
add something similar to the "Tags" version since the routines and structures 
are all
still there. Understand I am a Delphi
(pascal) programmer first and a C++ in my spare time ! This has been tortured 
and has
( so far ) ran flawlessly.
Of course this could not be used because if would break anybody else's use of 
the
library.

in   cmeta.cpp .....................................
bool MP4GetMetadataCoverArt(MP4FileHandle hFile,
                           uint8_t **coverArt, uint32_t* size,uint32_t* type,
                           uint32_t index)
{
   if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
       try {
           return ((MP4File*)hFile)->GetMetadataCoverArt(coverArt, size,type, index);
       }
       catch (MP4Error* e) {
           PRINT_ERROR(e);
           delete e;
       }
   }
   return false;
}

in coverartbox.cpp .................................

bool
CoverArtBox::get( MP4FileHandle hFile, Item& item, uint32_t index )
{
   item.reset();
   MP4File& file = *((MP4File*)hFile);

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

   if( !(index < covr->GetNumberOfChildAtoms()) )
       return true;

   MP4DataAtom* data = static_cast<MP4DataAtom*>( covr->GetChildAtom( index ));
   if( !data )
       return true;

   MP4BytesProperty* metadata = NULL;
   if ( !data->FindProperty( "data.metadata", (MP4Property**)&metadata ))
       return true;
// --------------    changes start here
--------------------------------------------------
   // the problem here is that some programs have the wrong number
   // in the "type" or just 00 hence we end up with the wrong types
   // better bet is to find the type using the routine already in place !
   // rather than screw up the rest ( got an Exception error without )
   // just let the lib take care of this
   metadata->GetValue( &item.buffer, &item.size );
   item.autofree = true;
   item.type = data->typeCode.GetValue();
   item.type = BT_UNDEFINED; // setting this overrides the value above !
                             // i'm sure there is a better way to do this
                             // I will leave that to the code gods
   // this borrowed from the set cover art !
   item.type = (item.type == BT_UNDEFINED) ? computeBasicType( item.buffer, item.size
): item.type;
//    --------------------------------   end changes
------------------------------------    
   return false;
}

in type.cpp .................................
   // POD static init does not need singletons
   static ImageHeader IMAGE_HEADERS[] = {
       { BT_BMP,  "\x42\x4d" }, // there was an error here   these bytes were
reversed see issue # 59
       { BT_GIF,  "GIF87a" },
       { BT_GIF,  "GIF89a" },
       { BT_JPEG, "\xff\xd8\xff\xe0" },
       { BT_PNG,  "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" },
       { BT_UNDEFINED } // must be last
   };
}

in mp4file.h .................................................
 bool GetMetadataCoverArt(uint8_t **coverArt, uint32_t* size, uint32_t* type,
                            uint32_t index = 0);

in meta.h    .....
/**
 * @deprecated Deprecated, scheduled for removal. Please use the tags convenience API.
 */
MP4V2_DEPRECATED
MP4V2_EXPORT
bool MP4GetMetadataCoverArt(
   MP4FileHandle hFile,
   uint8_t**     coverArt,
   uint32_t*     size,
   uint32_t*      type,    // added by DW 3/1/10
   uint32_t      index DEFAULT(0) );

in MP4Meta.cpp ................................

bool MP4File::GetMetadataCoverArt(uint8_t **coverArt, uint32_t *size,uint32_t 
*type,
                                 uint32_t index)
{
   char buffer[256];
   if (size == NULL || coverArt == NULL) return false;

   if (index > 0 && index > GetMetadataCoverArtCount()) return false;

   snprintf(buffer, 256, "moov.udta.meta.ilst.covr.data[%d].metadata", index);

   *coverArt = NULL;
   *size = 0;
   *type =0;

   GetBytesProperty(buffer, coverArt, size);
     itmf::BasicType arttype;
         arttype = impl::itmf::computeBasicType(*coverArt,*size);
     *type = arttype;

   if (size == 0)
       return false;

   return true;
} 

Original comment by wils...@tampabay.rr.com on 6 Apr 2010 at 12:57

GoogleCodeExporter commented 8 years ago
could you attach a file with multiple pieces of artwork for me to play with?

Original comment by kid...@gmail.com on 6 Apr 2010 at 8:09

GoogleCodeExporter commented 8 years ago
Ok this has Six pictures attached first 4 are simple arrows down left right and 
up 
then there is a .jpg image and then another .bmp ! I had built this file when I 
Could not understand why the .bmp file type was not recognized. ( This was the 
Error
in the type.cpp file. If I can help in anyway please let me know. I just about 
got
the library figured out but still a lot I do not understand ! 

Thanx
Don Wilson 

Original comment by wils...@tampabay.rr.com on 6 Apr 2010 at 10:06

Attachments:

GoogleCodeExporter commented 8 years ago
okay, kona did some research on this.  Basically, you either need to use trunk 
or
wait for 2.0.0.  The code I posted above works just fine to retrieve artwork,
including multiple pieces of art.

I did submit your change to the BM string, so that's already in there.

Closing

Original comment by kid...@gmail.com on 23 Apr 2010 at 10:23