php - 从 ffmpeg shell_exec 命令中检索信息

标签 php audio video ffmpeg shell-exec

我正在做以下事情

$output = shell_exec('/usr/local/bin/ffmpeg -i intro.mp3 2>&1'); 
echo "<pre>$output</pre>";

这输出
ffmpeg version 0.8.5, Copyright (c) 2000-2011 the FFmpeg developers
  built on Aug 20 2012 09:28:43 with clang 3.1 (tags/Apple/clang-318.0.61)
  configuration: --enable-nonfree --enable-gpl --enable-version3 --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libfaac --enable-libxvid --enable-libx264 --enable-libvpx --enable-hardcoded-tables --enable-shared --enable-pthreads --disable-indevs --cc=clang
  libavutil    51.  9. 1 / 51.  9. 1
  libavcodec   53.  7. 0 / 53.  7. 0
  libavformat  53.  4. 0 / 53.  4. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[mp3 @ 0x7f9481807c00] max_analyze_duration 5000000 reached at 5015510
Input #0, mp3, from 'intro.mp3':
  Metadata:
    album           : Frank 
    artist          : Amy Winehouse
    genre           : R&B
    title           : [Intro] Stronger Than Me
    track           : 01
    date            : 2008
  Duration: 00:03:54.71, start: 0.000000, bitrate: 230 kb/s
    Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 160 kb/s
At least one output file must be specified

我想获取信息以插入数据库专辑、艺术家、流派、标题等

但都是分开的

我可以通过执行以下操作来获得它们
$output = shell_exec('/usr/local/bin/ffmpeg -i intro.mp3 2>&1'); 

$edit = explode('  ', $output);
$edit = implode("@", $edit);
$edit = explode(':', $output);
echo "<pre>";
print_r($edit);
echo "</pre>";

然后运行
<?php echo $edit[9]; ?>

ETC

但这似乎是获取值的一种非常糟糕的方式和令人讨厌的方式,有时输出会略有不同,这会与输出混淆。

最好的方法是什么,还是我坚持这样做?

最佳答案

使用 ffmpeg 检索元数据有更好的方法。

1. 新建ffmpeg_movie对象,例如

$movie = new ffmpeg_movie(String path_to_media, boolean persistent);

2. 像这样开始获取元数据:
$movie->getAuthor();
$movie->getGenre();
$movie->getAlbum();

ffmpeg-php API documentation 上的可用内容列表.

3. 庆祝美好时光。

关于php - 从 ffmpeg shell_exec 命令中检索信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12175539/

相关文章:

android - Android 上的原生音频重采样

php - Facebook 广告 API PHP : Video upload using AdVideo class

opengl - 是否可以使用 GLSL 着色器实现视频编解码器?

php - 如果存在数据,如何执行更新查询,否则将数据插入 Mysql?

php - PHP 中的 Telegram Bot 自定义键盘

javascript - 通知系统如何工作

php - 数组键索引附带数字

audio - 为什么使用MFCC和Delta系数时对数似然法很奇怪

audio - 如何在Cocos2d中使用NSArray播放随机声音

javascript - 单击按钮时更改嵌入式 youtube 视频中的时间