Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ID3v2 cover art insertion with Perl?

0 views
Skip to first unread message

Seppo Ingalsuo

unread,
Apr 2, 2008, 2:21:46 AM4/2/08
to
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

Seppo Ingalsuo

unread,
Apr 2, 2008, 7:02:12 AM4/2/08
to
Seppo Ingalsuo wrote:

> 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

dersti...@googlemail.com

unread,
May 8, 2008, 4:21:12 AM5/8/08
to

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

Ilya Zakharevich

unread,
May 8, 2008, 4:44:54 AM5/8/08
to
[A complimentary Cc of this posting was sent to

<dersti...@googlemail.com>], who wrote in article <5e3e377e-a54a-4332...@e39g2000hsf.googlegroups.com>:
> 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

0 new messages