Support and General Use > Audio Playback, Database and Playlists

Converting ID3 image tags from PNG to JPG

(1/3) > >>

I have an issue which is similar to,54788.0.html.

I have a podcatcher I wrote myself in perl, which checks listed RSS feeds, looks for new items, downloads them and prepares an .m3u8 playlist for me. I have album art set for each feed in the appropriate directory, but quite often each episode has its own artwork embedded in PNG format, and I'd like to be able to convert it to JPG so that it shows up on RockBox.

Because this conversion happens when each file gets downloaded, batch processing isn't really a valid solution. I've got something that almost works, shown below. The JPG file it produces can be displayed by RockBox's Image Viewer plugin, and an ID3 inspector shows me that the finished MP3 file has a JPG embedded image. So every individual step seems to be working, but when I play the file, the album art isn't displayed.

Can anyone help me figure out what I might be missing? Thanks.

My image conversion code:

--- Code: ---#!/usr/bin/perl

use strict;
use Imager;
use MP3::Tag;
use Data::Dumper;

my $input = "~/Documents/test.mp3";
my $mp3 = MP3::Tag->new($input);
my @tags = $mp3->get_id3v2_frame_ids();
print Dumper(@tags);
if ($mp3->have_id3v2_frame_by_descr("APIC")) {
    print "Picture exists\n";

    # Read the image into a variable
    my $png_img = $mp3->select_id3v2_frame_by_descr("APIC");

    # Import the image into Imager for conversion
    if (open(my $fh_png, "<:raw", \$png_img)){
        print "Is PNG\n";
        my $converter = Imager->new();

        $converter = $converter->scale(xpixels=>1000, ypixels=>1000, type=>'min');

        my $jpg_img;

        # Write to a stream that can be written into the ID# tag
        open(my $fh_jpg, ">:raw", \$jpg_img) or die "Cannot open JPG stream";
        $converter->write(fh=>$fh_jpg, type=>"jpeg", jpeg_progressive=>0) or die "Cannot write: ", $converter->errstr;

        # Write to a file
        open(my $fh, ">:raw", "~/Documents/test.jpg") or die "Cannot open JPG file";
        $converter->write(fh=>$fh, type=>"jpeg", jpeg_progressive=>0) or die "Cannot write: ", $converter->errstr;

        # Update the ID3 tag
        $mp3->select_id3v2_frame_by_descr("APIC", $jpg_img) or die "Cannot update MP3";
        $mp3->config(write_v24 => 1) or die "Cannot set config";
        $mp3->update_tags() or die "Cannot update tags";


--- End code ---

I'm not experienced with Perl, but does your code generate a 1000x1000 pixel jpeg? If so this is very big. I'd try making a much smaller file which will take less memory to display. I'd suggest a maximum of 300x300, or use the exact size that your favourite theme uses.

That's certainly worth trying. That 1000×1000 limit was added because the sample file I'm using had an embedded image that was 3600×3600, which seemed excessive. Quite a few of the music files I have have cover art in the 1000×1000 range, so it didn't occur to me it might be a problem.

And after a quick test, changing the image size to 190×190, it's still not working.

Have you tried saving the jpeg as a separate file instead of being embedded?

Yeah, as I say, RockBox can read the file generated. I've considered just dropping the JPG into the directory with the same filename as the podcast (that should work, right?), but whit it copies podcasts over to my iPod, it reports a pretty naïve count of files copied, and I'd need to rework that to something more complicated to make it work properly.

Not entirely out of the question, but getting the art properly embedded is definitely the more elegant solution.


[0] Message Index

[#] Next page

Go to full version