Extract cover from mp3 file

Extract cover from mp3 file

Postby mazout » Wed Mar 01, 2006 11:30 am

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
mazout
User
 
Posts: 2
Joined: Wed Mar 01, 2006 11:25 am

Postby James Heinrich » Wed Mar 01, 2006 8:02 pm

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
James Heinrich
getID3() v1 developer
 
Posts: 1204
Joined: Fri May 04, 2001 11:00 am
Location: London, ON, Canada

Postby mazout » Thu Mar 02, 2006 10:56 am

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

Great ! Thank you.

--
mazout
EPITA
mazout
User
 
Posts: 2
Joined: Wed Mar 01, 2006 11:25 am

Postby jarc » Sun Jan 21, 2007 11:26 am

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
jarc
User
 
Posts: 3
Joined: Sun Jan 21, 2007 6:29 am

Postby ameshkin69 » Thu Feb 01, 2007 1: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?
ameshkin69
User
 
Posts: 2
Joined: Thu Feb 01, 2007 1:46 am

Postby TEMAndroid » Sun Oct 28, 2007 2:27 pm

Anybody can help? I have same problem :(((
TEMAndroid
User
 
Posts: 2
Joined: Sun Oct 28, 2007 2:17 pm
Location: BelNet

Postby TEMAndroid » Mon Oct 29, 2007 2: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
TEMAndroid
User
 
Posts: 2
Joined: Sun Oct 28, 2007 2:17 pm
Location: BelNet

HELP PLEASE

Postby saulo » Tue Mar 11, 2008 3: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 3:16 pm
Location: mexico

solved!

Postby saulo » Tue Mar 11, 2008 3: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 3:16 pm
Location: mexico

solved!

Postby saulo » Tue Mar 11, 2008 3: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 3:16 pm
Location: mexico

solved!

Postby saulo » Tue Mar 11, 2008 3: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!
saulo
User
 
Posts: 4
Joined: Tue Mar 11, 2008 3:16 pm
Location: mexico

Re: Extract cover from mp3 file

Postby sala » Tue Mar 31, 2009 6:39 am

Thanks! saulo .....

That one i want.............
sala
User
 
Posts: 1
Joined: Tue Mar 31, 2009 2:53 am

Re: Extract cover from mp3 file

Postby ssubham » Sun Jan 23, 2011 11:04 am

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

Thank you for the cooperation in advance.

Regards,
subham
ssubham
User
 
Posts: 2
Joined: Sun Jan 23, 2011 11:01 am

Re: Extract cover from mp3 file

Postby James Heinrich » Sun Jan 23, 2011 11:41 am

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.
James Heinrich
getID3() v1 developer
 
Posts: 1204
Joined: Fri May 04, 2001 11:00 am
Location: London, ON, Canada

Re: Extract cover from mp3 file

Postby ssubham » Mon Jan 24, 2011 7:04 am

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?
ssubham
User
 
Posts: 2
Joined: Sun Jan 23, 2011 11:01 am

Re: Extract cover from mp3 file

Postby James Heinrich » Mon Jan 24, 2011 7:22 am

No. Anything that gives you a spectral display of the audio will be doing exactly that.
James Heinrich
getID3() v1 developer
 
Posts: 1204
Joined: Fri May 04, 2001 11:00 am
Location: London, ON, Canada


Return to Support 1.x (resolved)

Who is online

Users browsing this forum: No registered users and 0 guests

cron