php - 如何获得视频的最高比特率和尺寸?
问题描述
我正在使用一个名为pascalbaljetmedia/laravel-ffmpeg
并希望为视频流创建 HLS 播放列表。但首先我想检查视频比特率或宽度/高度,看看它是 4k、1080、720 等。
那么我如何计算视频比特率及其尺寸?..
这是我在获取视频信息后想要做的事情:
$video = FFMpeg::fromDisk('videos')
->open('original_video.mp4')
->exportForHLS();
$resolutions = [];
//check if we can make 4k version
if ( ( $bitrate >= 14000 ) || ( $width >= 3840 && $height >= 2160 ) )
{
// Then it's a 4k video
// We make a 4k version of HLS
$resolutions[] = ['q' => 14000, 'size' => [ 'w' => 3840, 'h' => 2160]];
}
//check if we can make HD version
if( ( $bitrate >= 5800 ) || ( $width >= 1920 && $height >= 1080 ) )
{
// Then it's a HD video
// We make a HD version of HLS
$resolutions[] = ['q' => 5800, 'size' => [ 'w' => 1920, 'h' => 1080]];
}
//Lastly we loop through and add formarts
foreach($resolutions as $resolution){
$video->addFormat($resolution['q'], function($media) {
$media->addFilter('scale='. $resolution['size']['w].':'. $resolution['size']['h]);
});
}
$video->save('video_name.m3u8');
有什么帮助吗?
解决方案
我不使用 Laravel,但它看起来像是pascalbaljetmedia/laravel-ffmpeg
的包装器php-ffmpeg/php-ffmpeg
,因此您应该能够使用FFProbe来提取此信息。
$ffprobe = FFMpeg\FFProbe::create();
$video = $ffprobe->streams('original_video.mp4')->videos()->first();
$width = $video->get('width');
$height = $video->get('height');
$bitrate = $video->get('bit_rate');
顺便说一句,您的代码行中有几个拼写错误应该是$media->addFilter('scale=' . $resolution['size']['w'] . ':' . $resolution['size']['h']);
.
推荐阅读
- excel - Excel VBA 在 DIN A4 上以昂贵的价格拟合列
- python - IndexError:列表索引超出范围错误,如何修复代码?
- python - 使用 spaCy 更好的命名实体识别和相似性
- html - 以百分比表示的 Flex box flex-basis 值未产生预期结果
- tomcat - Tomcat 与 AEM 集成的问题
- c# - 如何在 DataGridView 中解决这个问题?
- java - 如何在每次登录 log4j2 后立即调用方法
- php - PHP 在每个月底自动提交表单
- java - 谷歌播放。为什么我有 OpenGL ES 2.0+ 而不是 1.0
- windows - NetFileEnum 不一致,偶尔不返回数据