[Flac-dev] Difficulties in add cover art to FLAC file
Anthony Liu
quadamage at gmail.com
Mon Mar 8 08:30:05 PST 2010
Hi all, recently I tried to add cover art to flac files and have dfficulties
in doing so.
FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new();
if(0 == chain)
return;
if(!FLAC__metadata_chain_read(chain, filename))
return;
FLAC__StreamMetadata *picture =
FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE);
FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
if(0 == iterator)
return;
FLAC__metadata_iterator_init(iterator, chain);
while(FLAC__metadata_iterator_next(iterator))
;
const char *violation;
if( !FLAC__metadata_object_picture_is_legal(picture, &violation))
printf( "Illegal Picture: %s", violation );
if(!FLAC__metadata_iterator_insert_block_after(iterator, picture))
{
printf(L" ERROR: adding new PICTURE block to metadata");
FLAC__metadata_object_delete(picture);
}
FLAC__metadata_iterator_delete(iterator);
FLAC__metadata_chain_sort_padding(chain);
if(!FLAC__metadata_chain_write(chain, true, false ))
{
const FLAC__Metadata_ChainStatus status =
FLAC__metadata_chain_status(chain);
printf( "Fail to write: %d", status );
}
FLAC__metadata_chain_delete(chain);
The above code will add a NULL cover art into the flac file, it works.
However, after I add the following code between the call
of FLAC__metadata_iterator_next and
FLAC__metadata_object_picture_is_legal,
I got a "fail to write: status 0" message.
picture->data.picture.type = (FLAC__StreamMetadata_Picture_Type)3;
FLAC__metadata_object_picture_set_mime_type( picture, "image/jpeg", true );
FLAC__metadata_object_picture_set_description( picture,
(FLAC__byte*)"", true );
CFile picfile;
picfile.Open( L"I:\\1.jpg", CFile::modeRead | CFile::shareDenyWrite);
ULONGLONG dwLength = picfile.GetLength();
LPSTR pData = new char[static_cast<unsigned int>(dwLength+1)];
picfile.Read(pData, static_cast<UINT>(dwLength));
FLAC__metadata_object_picture_set_data( picture, (FLAC__byte*)pData,
dwLength, true );
delete [] pData;
I did some tests and it seemed that the error was caused by
the FLAC__metadata_object_picture_set_data function,
the members of picture object like width, height, depth, colors were not
initialized, are they mandatory or optional?
What's wrong with the code?
Please help!
--
Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/flac-dev/attachments/20100309/8cb73a66/attachment.htm
More information about the Flac-dev
mailing list