uberchel/mediainfo4php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

uberchel/mediainfo4php

最新稳定版本:v1.0.8

Composer 安装命令:

composer require uberchel/mediainfo4php

包简介

MediaInfo is an easy-to-use static PHP class, for extracting data from audio and video files, the FFMpeg program must be installed on the sevrera or computer for the class to work.

README 文档

README

MediaInfo is an easy-to-use static PHP class, for extracting data from audio and video files, the FFMpeg program must be installed on the server or computer for the class to work. Version: 1.0.8

Requirements

  • PHP >= 7.2
  • PHP extensions: mbstring
  • ffmpeg

Installation

No complicated installation, just transfer or copy the class file to your projector and install it using composer.

composer require uberchel/mediainfo4php

Using

The main methods Load and Get have 2 parameters, the first is the path to the file, the second is to give as an Object (default = true) For the rest, it is also possible to assign the path to the file to the first parameters if you need to find out only something specific separately or compare 2 files..


Using composer.

<?php

use uberchel\MediaInfo;
//use composer
require __DIR__ . '/vendor/autoload.php';
//not use composer
require './mediainfo.php';

$data = MediaInfo::Get('1.mkv', true);
print_r($data);


We get all the metadata from the file and put it in the $data variable.

<?php

 $data = MediaInfo::Get('1.mkv', true);
 print_r($data);


Getting all the metadata from the file

<?php

 MediaInfo::Load('1.mkv', true);


Output the necessary data

<?php

// By default, the MediaInfo4PHP class returns an Object anyway, this method supports a Boolean attribute,
// by default it is set to true, and this method can also return all metadata in the selected type.
// Setting the Array type for subsequent calls
 MediaInfo::asObject(false);
 
// Setting the Object type for subsequent calls
 MediaInfo::asObject();

// The following calls will return True / False
 MediaInfo::isObject();

// Checking for the existence of a method value return True / False
// $value - method, example: size or streams audios.size | video.size
// $index - array index in streams, optional parameter
 MediaInfo::Has($value, $index);

// Print the name, return string
 echo MediaInfo::GetTitle();

// Output the Size file, return string
 echo MediaInfo::GetSize();

// Output the Duration, return string
 echo MediaInfo::GetDuration();

// Output the start position, return string
 echo MediaInfo::GetStart();

// Output the Video Codec, return string
 echo MediaInfo::GetVideoCodec();

// Output the Audio Codec, return string
 echo MediaInfo::GetAudioCodec();

// Output the video bitrate, return string
 echo MediaInfo::GetBitrate();

// Output the encoder, return string
 echo MediaInfo::GetEncoder();

// Print the creation date, return string
 echo MediaInfo::GetCreated();

// Output a stream of Video, return Object or Array
 print_r(MediaInfo::GetVideo());

// Output an Audio stream, return Object or Array
 print_r(MediaInfo::GetAudios());

// Output a Subtitle stream, return Object or Array
 print_r(MediaInfo::GetSubtitles());

// Output a stream of Images, return Object or Array
 print_r(MediaInfo::GetPictures());

// Output Stream All streams, return Object or Array
 print_r(MediaInfo::GetStreams());

// Output All information to the stream, return Object or Array
 print_r(MediaInfo::Get());

Examples


Get data from video file size

<?php
use uberchel\MediaInfo;
require './mediainfo.php';

MediaInfo::load('./1.mkv');
if (MediaInfo::Has('size')) {
    echo MediaInfo::GetSize();
}

Get data from video track size

<?php
use uberchel\MediaInfo;
require './mediainfo.php';

MediaInfo::load('./1.mkv');
if (MediaInfo::Has('video.size')) {
    echo MediaInfo::GetVideo()->size;
}

Get data from audio tracks

<?php
use uberchel\MediaInfo;
require './mediainfo.php';

MediaInfo::load('./1.mkv');

foreach (MediaInfo::GetAudios() AS $audio) {
    echo "ID: {$audio['id']}, Title: {$audio['title']}, Codec: {$audio['codec']}";
}

Comparing codecs of different files

<?php
use uberchel\MediaInfo;
require './mediainfo.php';

MediaInfo::load('./1.mkv');
print_r(MediaInfo::getVideoCodec() == MediaInfo::getVideoCodec('./2.mkv'));

//The same thing without loading the Load function
print_r(MediaInfo::getVideoCodec('./1.mkv') == MediaInfo::getVideoCodec('./2.mkv'));

clone the repository and install the requirements

git clone https://github.com/uberchel/MediaInfo4PHP

LICENSE

The MIT License

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-24