Extract cover from mp3 file

Locked
mazout
User
Posts:2
Joined:Wed Mar 01, 2006 4:25 pm
Extract cover from mp3 file

Post by mazout » Wed Mar 01, 2006 4:30 pm

Hello,

I made an uploader for mp3 files.
I simply want to know how to extract from the id3 tag (with PHP of course)
- the cover
- the comments

I use the function id3_get_tag in PHP but it doesn't extract the cover nor the comments.

Thanks for your help.

--
mazout
EPITA

James Heinrich
getID3() v1 developer
Posts:1477
Joined:Fri May 04, 2001 4:00 pm
Are you a spambot?:no
Location:Northern Ontario, Canada
Contact:

Post by James Heinrich » Thu Mar 02, 2006 1:02 am

Code: Select all

$getID3 = new getID3;
$fileinfo = $getID3->analyze($filename);
$picture = @$fileinfo['id3v2']['APIC'][0]['data']; // binary image data
$comments = @$fileinfo['id3v2']['comments']; // multi-dimensional array

mazout
User
Posts:2
Joined:Wed Mar 01, 2006 4:25 pm

Post by mazout » Thu Mar 02, 2006 3:56 pm

Thanx I know extracts comments and covers (adding some code of course).

Great ! Thank you.

--
mazout
EPITA

jarc
User
Posts:3
Joined:Sun Jan 21, 2007 11:29 am

Post by jarc » Sun Jan 21, 2007 4:26 pm

James Heinrich wrote:

Code: Select all


$picture = @$fileinfo['id3v2']['APIC'][0]['data']; // binary image data

Hi
With this we can extract the data, but how can we show the data like a jpg image?

Thanks

ameshkin69
User
Posts:2
Joined:Thu Feb 01, 2007 6:46 am

Post by ameshkin69 » Thu Feb 01, 2007 6:48 am

This is simply not working, iu have no idea what I'm doing wrong but I cannot seem to get the data for the picture which is attatched to an mp3 file!

Does anyone have code that works?

TEMAndroid
User
Posts:2
Joined:Sun Oct 28, 2007 7:17 pm
Location:BelNet

Post by TEMAndroid » Sun Oct 28, 2007 7:27 pm

Anybody can help? I have same problem :(((

TEMAndroid
User
Posts:2
Joined:Sun Oct 28, 2007 7:17 pm
Location:BelNet

Post by TEMAndroid » Mon Oct 29, 2007 7:59 pm

I solved the problem, may be not correctly but it works! :)
in file module.tag.id3v2.php add string (1261):

Code: Select all

$parsedFrame['data']             = substr($parsedFrame['data'], 2);
Please check this bug correctly :)

Sorry for my english

saulo
User
Posts:4
Joined:Tue Mar 11, 2008 8:16 pm
Location:mexico

HELP PLEASE

Post by saulo » Tue Mar 11, 2008 8:21 pm

hi, i've been traying show a cover from any mp3 and i can't get the solution.

please somebody help me, my code is:


$getID3 = new getID3;

$ThisFileInfo = $getID3->analyze("musica/01-maroon_5-if_i_never_see_your_face_again.mp3");

getid3_lib::CopyTagsToComments($ThisFileInfo);


$picture = @$ThisFileInfo['id3v2']['APIC'][0]['data']; // binary image data

echo $picture;

echo @$ThisFileInfo['comments_html']['artist'][0]."<br>"; // artist from any/all available tag formats
echo @$ThisFileInfo['tags']['id3v2']['title'][0]."<br>"; // title from ID3v2
echo @$ThisFileInfo['audio']['bitrate']."<br>"; // audio bitrate
echo @$ThisFileInfo['playtime_string']."<br>"; // playtime in minutes:seconds, formatted string



thanks for the help.

saulo
User
Posts:4
Joined:Tue Mar 11, 2008 8:16 pm
Location:mexico

solved!

Post by saulo » Tue Mar 11, 2008 8:47 pm

hi guys, i have the answer, if you need, there it is:

test1.php (here show the info of mp3)

<?php
require_once('getid3/getid3/getid3.php');
//$filename="musica/yoursong.mp3";


// include getID3() library (can be in a different directory if full path is specified)

// Initialize getID3 engine
$getID3 = new getID3;
// Analyze file and store returned data in $ThisFileInfo
$ThisFileInfo = $getID3->analyze("musica/01-maroon_5-if_i_never_see_your_face_again.mp3");

// Optional: copies data from all subarrays of [tags] into [comments] so
// metadata is all available in one location for all tag formats
// metainformation is always available under [tags] even if this is not called
getid3_lib::CopyTagsToComments($ThisFileInfo);


$picture = @$ThisFileInfo['id3v2']['APIC'][0]['data']; // binary image data

echo $picture;


// Output desired information in whatever format you want
// Note: all entries in [comments] or [tags] are arrays of strings
// See structure.txt for information on what information is available where
// or check out the output of /demos/demo.browse.php for a particular file
// to see the full detail of what information is returned where in the array
echo @$ThisFileInfo['comments_html']['artist'][0]."<br>"; // artist from any/all available tag formats
echo @$ThisFileInfo['tags']['id3v2']['title'][0]."<br>"; // title from ID3v2
echo @$ThisFileInfo['audio']['bitrate']."<br>"; // audio bitrate
echo @$ThisFileInfo['playtime_string']."<br>"; // playtime in minutes:seconds, formatted string

echo "<img src='cover.php' width='200'>";

?>



and cover.php (here show the binary data)

<?
require_once('getid3/getid3/getid3.php');

$getID3 = new getID3;
#$getID3->option_tag_id3v2 = true; # Don't know what this does yet
$getID3->analyze("musica/01-maroon_5-if_i_never_see_your_face_again.mp3");
if (isset($getID3->info['id3v2']['APIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['APIC'][0]['data'];
} elseif (isset($getID3->info['id3v2']['PIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['PIC'][0]['data'];
} else {
$cover = null;
}
if (isset($getID3->info['id3v2']['APIC'][0]['image_mime'])) {
$mimetype = $getID3->info['id3v2']['APIC'][0]['image_mime'];
} else {
$mimetype = 'image/jpeg'; // or null; depends on your needs
}

if (!is_null($cover)) {
// Send file
header("Content-Type: " . $mimetype);

if (isset($getID3->info['id3v2']['APIC'][0]['image_bytes'])) {
header("Content-Length: " . $getID3->info['id3v2']['APIC'][0]['image_bytes']);
}

echo($cover);
}
?>


nice day!

saulo
User
Posts:4
Joined:Tue Mar 11, 2008 8:16 pm
Location:mexico

solved!

Post by saulo » Tue Mar 11, 2008 8:53 pm

hi guys, i have the answer, if you need, there it is:

test1.php (here show the info of mp3)

<?php
require_once('getid3/getid3/getid3.php');
//$filename="musica/yoursong.mp3";


// include getID3() library (can be in a different directory if full path is specified)

// Initialize getID3 engine
$getID3 = new getID3;
// Analyze file and store returned data in $ThisFileInfo
$ThisFileInfo = $getID3->analyze("musica/01-maroon_5-if_i_never_see_your_face_again.mp3");

// Optional: copies data from all subarrays of [tags] into [comments] so
// metadata is all available in one location for all tag formats
// metainformation is always available under [tags] even if this is not called
getid3_lib::CopyTagsToComments($ThisFileInfo);


$picture = @$ThisFileInfo['id3v2']['APIC'][0]['data']; // binary image data

echo $picture;


// Output desired information in whatever format you want
// Note: all entries in [comments] or [tags] are arrays of strings
// See structure.txt for information on what information is available where
// or check out the output of /demos/demo.browse.php for a particular file
// to see the full detail of what information is returned where in the array
echo @$ThisFileInfo['comments_html']['artist'][0]."<br>"; // artist from any/all available tag formats
echo @$ThisFileInfo['tags']['id3v2']['title'][0]."<br>"; // title from ID3v2
echo @$ThisFileInfo['audio']['bitrate']."<br>"; // audio bitrate
echo @$ThisFileInfo['playtime_string']."<br>"; // playtime in minutes:seconds, formatted string

echo "<img src='cover.php' width='200'>";

?>



and cover.php (here show the binary data)

<?
require_once('getid3/getid3/getid3.php');

$getID3 = new getID3;
#$getID3->option_tag_id3v2 = true; # Don't know what this does yet
$getID3->analyze("musica/01-maroon_5-if_i_never_see_your_face_again.mp3");
if (isset($getID3->info['id3v2']['APIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['APIC'][0]['data'];
} elseif (isset($getID3->info['id3v2']['PIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['PIC'][0]['data'];
} else {
$cover = null;
}
if (isset($getID3->info['id3v2']['APIC'][0]['image_mime'])) {
$mimetype = $getID3->info['id3v2']['APIC'][0]['image_mime'];
} else {
$mimetype = 'image/jpeg'; // or null; depends on your needs
}

if (!is_null($cover)) {
// Send file
header("Content-Type: " . $mimetype);

if (isset($getID3->info['id3v2']['APIC'][0]['image_bytes'])) {
header("Content-Length: " . $getID3->info['id3v2']['APIC'][0]['image_bytes']);
}

echo($cover);
}
?>


nice day!

saulo
User
Posts:4
Joined:Tue Mar 11, 2008 8:16 pm
Location:mexico

solved!

Post by saulo » Tue Mar 11, 2008 8:54 pm

hi guys, i have the answer, if you need, there it is:

test1.php (here show the info of mp3)

<?php
require_once('getid3/getid3/getid3.php');
//$filename="musica/yoursong.mp3";


// include getID3() library (can be in a different directory if full path is specified)

// Initialize getID3 engine
$getID3 = new getID3;
// Analyze file and store returned data in $ThisFileInfo
$ThisFileInfo = $getID3->analyze("musica/01-maroon_5-if_i_never_see_your_face_again.mp3");

// Optional: copies data from all subarrays of [tags] into [comments] so
// metadata is all available in one location for all tag formats
// metainformation is always available under [tags] even if this is not called
getid3_lib::CopyTagsToComments($ThisFileInfo);


$picture = @$ThisFileInfo['id3v2']['APIC'][0]['data']; // binary image data

echo $picture;


// Output desired information in whatever format you want
// Note: all entries in [comments] or [tags] are arrays of strings
// See structure.txt for information on what information is available where
// or check out the output of /demos/demo.browse.php for a particular file
// to see the full detail of what information is returned where in the array
echo @$ThisFileInfo['comments_html']['artist'][0]."<br>"; // artist from any/all available tag formats
echo @$ThisFileInfo['tags']['id3v2']['title'][0]."<br>"; // title from ID3v2
echo @$ThisFileInfo['audio']['bitrate']."<br>"; // audio bitrate
echo @$ThisFileInfo['playtime_string']."<br>"; // playtime in minutes:seconds, formatted string

echo "<img src='cover.php' width='200'>";

?>



and cover.php (here show the binary data)

<?
require_once('getid3/getid3/getid3.php');

$getID3 = new getID3;
#$getID3->option_tag_id3v2 = true; # Don't know what this does yet
$getID3->analyze("musica/yoursong.mp3");
if (isset($getID3->info['id3v2']['APIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['APIC'][0]['data'];
} elseif (isset($getID3->info['id3v2']['PIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['PIC'][0]['data'];
} else {
$cover = null;
}
if (isset($getID3->info['id3v2']['APIC'][0]['image_mime'])) {
$mimetype = $getID3->info['id3v2']['APIC'][0]['image_mime'];
} else {
$mimetype = 'image/jpeg'; // or null; depends on your needs
}

if (!is_null($cover)) {
// Send file
header("Content-Type: " . $mimetype);

if (isset($getID3->info['id3v2']['APIC'][0]['image_bytes'])) {
header("Content-Length: " . $getID3->info['id3v2']['APIC'][0]['image_bytes']);
}

echo($cover);
}
?>


nice day!

sala
User
Posts:1
Joined:Tue Mar 31, 2009 7:53 am
Are you a spambot?:no

Re: Extract cover from mp3 file

Post by sala » Tue Mar 31, 2009 11:39 am

Thanks! saulo .....

That one i want.............

ssubham
User
Posts:2
Joined:Sun Jan 23, 2011 4:01 pm
Are you a spambot?:no

Re: Extract cover from mp3 file

Post by ssubham » Sun Jan 23, 2011 4:04 pm

Hi,
Is there any way to get the spectrum(amplitude) from the mp3 files?

Thank you for the cooperation in advance.

Regards,
subham

James Heinrich
getID3() v1 developer
Posts:1477
Joined:Fri May 04, 2001 4:00 pm
Are you a spambot?:no
Location:Northern Ontario, Canada
Contact:

Re: Extract cover from mp3 file

Post by James Heinrich » Sun Jan 23, 2011 4:41 pm

ssubham wrote:Is there any way to get the spectrum(amplitude) from the mp3 files?
Sure, just decode the MPEG audio, run it through a Fourier transform and there you go. That is far far far outside the scope of getID3, however.

ssubham
User
Posts:2
Joined:Sun Jan 23, 2011 4:01 pm
Are you a spambot?:no

Re: Extract cover from mp3 file

Post by ssubham » Mon Jan 24, 2011 12:04 pm

James Heinrich wrote:
ssubham wrote:Is there any way to get the spectrum(amplitude) from the mp3 files?
Sure, just decode the MPEG audio, run it through a Fourier transform and there you go. That is far far far outside the scope of getID3, however.
thank you for the reply. Is there anyother way to get it?

James Heinrich
getID3() v1 developer
Posts:1477
Joined:Fri May 04, 2001 4:00 pm
Are you a spambot?:no
Location:Northern Ontario, Canada
Contact:

Re: Extract cover from mp3 file

Post by James Heinrich » Mon Jan 24, 2011 12:22 pm

No. Anything that gives you a spectral display of the audio will be doing exactly that.

Locked