ID3v2 cover art insertion with Perl?

S

Seppo Ingalsuo

Hi,

I'm struggling with my flac->mp3 music library maintenance script. based
on some net articles I have used MP3::Tag to attach cover art this way

use constant HEADER => ( chr(0x0) , "image/jpeg" , chr(0x0), "");

$img = new Image::Magick;
if (! $img->Read("$flacdir/cover.jpg")) {
$id3v2->add_frame( "APIC", HEADER, $img->ImageToBlob(magick => 'jpg'));
}

There is also setting

MP3::Tag->config("id3v23_unsync_size_w" => "TRUE");

See e.g. http://perl.thiesen.org/scripts/id3image

But I get corrupted cover art images in Amarok. iTunes and Windows Media
Player seem to work with it. MediaTomb uPnP server + PS3 doesn't find
the pictures. I'd like to get MediaTomb that uses taglib for metadata to
work.

There are Perl bindings for taglib in Audio::TagLib in CPAN. I'm able to
generate basic ID3v1 tags with it but nothing else since the
documentation is missing/minimal and I'm far from fluent in Perl to get
the information from Audio::TagLib source code. Any pointers how to do
proper ID3v2 APIC tags with Perl would be really helpful.

I found this but it seems to generate only ID3v1 tags based on "id3v2
-l" output and there is no example of
Audio::TagLib::ID3v2::AttachedPictureFrame

http://www.mfischer.com/2007/11/21/mp3-metadata-tagging/

BR,
Seppo
 
S

Seppo Ingalsuo

Seppo said:
There are Perl bindings for taglib in Audio::TagLib in CPAN. I'm able to
generate basic ID3v1 tags with it but nothing else since the
documentation is missing/minimal and I'm far from fluent in Perl to get
the information from Audio::TagLib source code. Any pointers how to do
proper ID3v2 APIC tags with Perl would be really helpful.

As response to myself this seems to work ... :^)

my $mp3 = Audio::TagLib::MPEG::File->new($outfile);
my $id3v2 = $mp3->ID3v2Tag(1);
$id3v2->setArtist(Audio::TagLib::String->new($artist));
$id3v2->setAlbum(Audio::TagLib::String->new($album));
$id3v2->setTitle(Audio::TagLib::String->new($title));
$id3v2->setYear($date);
$id3v2->setTrack($track);
$id3v2->setGenre(Audio::TagLib::String->new($genre));
if (open(PICFILE, "$flacdir/cover.jpg")) {
$filesize = (-s PICFILE);
binmode(PICFILE);
read(PICFILE, $imgdata, $filesize);
close(PICFILE);
my $imgbv = Audio::TagLib::ByteVector->new();
$imgbv->setData($imgdata,$filesize);
my $bv = Audio::TagLib::ByteVector->new("APIC");
my $field =
Audio::TagLib::ID3v2::AttachedPictureFrame->new($bv, "UTF8");
$field->setPicture($imgbv);
$field->setTextEncoding("UTF8");
$field->setMimeType(Audio::TagLib::String->new("image/jpeg"));
$field->setType("Other");
$field->setDescription(Audio::TagLib::String->new("Cover
(front)"));
$id3v2->addFrame($field);
}
$mp3->save();

BR,
Seppo
 
D

derstilledon

As response to myself this seems to work ... :^)

my $mp3 = Audio::TagLib::MPEG::File->new($outfile);
my $id3v2 = $mp3->ID3v2Tag(1);
$id3v2->setArtist(Audio::TagLib::String->new($artist));
$id3v2->setAlbum(Audio::TagLib::String->new($album));
$id3v2->setTitle(Audio::TagLib::String->new($title));
$id3v2->setYear($date);
$id3v2->setTrack($track);
$id3v2->setGenre(Audio::TagLib::String->new($genre));
if (open(PICFILE, "$flacdir/cover.jpg")) {
$filesize = (-s PICFILE);
binmode(PICFILE);
read(PICFILE, $imgdata, $filesize);
close(PICFILE);
my $imgbv = Audio::TagLib::ByteVector->new();
$imgbv->setData($imgdata,$filesize);
my $bv = Audio::TagLib::ByteVector->new("APIC");
my $field =
Audio::TagLib::ID3v2::AttachedPictureFrame->new($bv, "UTF8");
$field->setPicture($imgbv);
$field->setTextEncoding("UTF8");
$field->setMimeType(Audio::TagLib::String->new("image/jpeg"));
$field->setType("Other");
$field->setDescription(Audio::TagLib::String->new("Cover
(front)"));
$id3v2->addFrame($field);
}
$mp3->save();

BR,
Seppo

the script works fine. the cover will be displayed on windows
mediaplayer 11.. but ther is NO cover on ps3 (mediatomb).
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to

the script works fine. the cover will be displayed on windows
mediaplayer 11.. but ther is NO cover on ps3 (mediatomb).

Most software handling ID3v2 is horribly buggy. Most creators produce
a broken MP3 file. Most readers reject conforming ID3v2 tags.

grep docs of MP3::Tag for ITunes...

Hope this helps,
Ilya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top