Retrieve ID3 info from m4a file in PHP
Asked Answered
P

2

8

I've written some PHP code to pull out ID3 tags from mp3 files. The next step is to do the same with .m4a files. From the research I've done it looks like most m4a files do not use ID3 but instead a format using 'atoms'.

Are there any PHP libraries out there that can parse out these 'atoms'? I've seen some C#/C++ ones but haven't been able to find any PHP ones. Any other guides or documentation would be great as well.

Prunella answered 30/1, 2012 at 20:7 Comment(5)
You can try getID3() - I have had great success with this library in the past for various types of media tags.Spiller
One thing I forgot to mention is that I dont have the full file. I only have the first X bytes. Does getID3 support partial files?Prunella
I think it only reads the tags in the header, and I think this is usually in the first X bytes of the file - but the answer really is "Try it and see"Spiller
This does not work well with getID3. I have forked the library and integrated it to use partial data files. I have it working, but for an 8MB song, it requires and atom of at least 325kb of data. Is there a better way to parse this data from m4a without downloading so much data? I want to make this more efficient. Are there any other libraries that handle this better, in any language without downloading so much data?Kyrakyriako
Few years ago I was looking for a reliable mp3 library but never found one. There were many but nothing 100% stable. The situation could change but if not do what I did. Download the source of mp3info (ibiblio.org/mp3info) and rewrite a part which interest you into PHP. If you don't want to do it you can just install the mp3info and call it from your script to get all info.Alanealanine
R
3

This project handles many audio files formats including AAC (M4A is AAC) : http://getid3.sourceforge.net/

hope this can help

Rampant answered 16/12, 2014 at 22:27 Comment(3)
Thx for sharing link.Japeth
Not too bad. It seems to have issues with VBR files, though (i.e. it comes up with the wrong duration).Monmouthshire
@Alexis Wilke, in rare cases duration is wrong. That's why for this purpose I prefer this sox shell command which is the strongest solution I found : sox "file.mp3" -n stat 2>&1 | sed -n 's#^Length (seconds):[^0-9]*([0-9.]*)$#\1#p'Rampant
S
-1

I came across a similar issue not too long ago and had a look around. The simplest and most effective method (in my opinion) is to use the exec command in order to extra media information.

I based my code on a forum post over at longtailvideo http://www.longtailvideo.com/support/forums/jw-player/setup-issues-and-embedding/9448/how-to-get-video-duration-with-ffmpeg-and-php

<?php
$videofile="/var/video/user_videos/partofvideo.avi";
ob_start();
passthru("/usr/bin/ffmpeg -i \"{$videofile}\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();

$search='/Duration: (.*?),/';
$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);

echo $matches[1][0]; <-- Duration
?>

This script can handle anything ffmpeg is prepared to handle (which is a lot!) I know the above example illustrates a video file but, it will work fine with audio also

Sunnysunproof answered 13/8, 2013 at 1:8 Comment(1)
I think using ffprobe would be better in this case since it will only do probing (faster).Monmouthshire

© 2022 - 2024 — McMap. All rights reserved.