Working with media files in Laravel? Need to extract metadata like duration, bitrate, or codec information from audio and video files? The plutuss/getid3-laravel package offers a seamless integration of the powerful getID3 library into your Laravel projects.
📦 What is plutuss/getid3-laravel?
plutuss/getid3-laravel is a Laravel wrapper around the james-heinrich/getid3 library. It simplifies the process of extracting metadata from various media files by providing a Laravel-friendly interface.
Key Features:
Metadata Extraction: Retrieve information such as format, codec, duration, bitrate, sample rate, and more.
Support for Various Formats: Works with MP3, WAV, FLAC, OGG, AAC, WMA, AVI, MPEG, QuickTime, and many others.
Tag Processing: Analyze and extract information from metadata tags like ID3.
Character Encoding Detection: Automatically detects text encoding used in metadata.
Stream Information Retrieval: Provides details about audio and video streams within media files.
Flexible Integration: Supports local files, uploaded files, and remote URLs.
🚀 Installation
composer require plutuss/getid3-laravel
For Laravel versions below 5.5, you may need to register the service provider manually.
🛠️ Usage
The package provides a MediaAnalyzer facade to interact with media files
Analyze a Local File
use Plutuss\Facades\MediaAnalyzer;
$media = MediaAnalyzer::fromLocalFile('path/to/file.mp4');
$info = $media->getAllInfo();
Analyze an Uploaded File
use Plutuss\Facades\MediaAnalyzer;
use Illuminate\Http\Request;
public function analyze(Request $request)
{
$media = MediaAnalyzer::uploadFile($request->file('media'));
$info = $media->getAllInfo();
// Access specific metadata
$duration = $media->getNestedValue('playtime_seconds');
}
Analyze a Remote File
use Plutuss\Facades\MediaAnalyzer;
$url = 'https://example.com/media.mp3';
$media = MediaAnalyzer::fromUrl($url);
$info = $media->getAllInfo();
Save Remote File Locally Before Analysis
use Plutuss\Facades\MediaAnalyzer;
$url = 'https://example.com/media.mp3';
$media = MediaAnalyzer::saveFileFromUrl(true)
->setDisk('public')
->setFilePath('media/')
->setFileName('sample')
->fromUrl($url);
$info = $media->getAllInfo();
📚 Available Methods
fromLocalFile($path, $disk = null)
uploadFile($uploadedFile)
fromUrl($url)
getAllInfo()
getNestedValue($key)
saveFileFromUrl($bool)
setDisk($disk)
setFilePath($path)
setFileName($name)
🧠 Conclusion
Integrating media metadata extraction into your Laravel application is straightforward with plutuss/getid3-laravel. Whether you're building a media library, podcast platform, or any application that handles audio/video files, this package can streamline your workflow.
For more details, visit the Packagist page or check out the GitHub repository.