dpvr49226 2012-08-22 13:28
浏览 92
已采纳

ffmpeg:在php中使用返回的数据

I have started using ffmpeg and I am very new to it, so please bear with me.

I have installed ffmpeg on my server and it works great; I can run certain commands and get output data when logged in via ssh

For example I can run

ffmpeg -i Sleep\ Away.mp3 

Which returns the following:

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 @ 0x7f9694011a00] Header missing
    Last message repeated 13 times
[mp3 @ 0x7f9694007c00] max_analyze_duration 5000000 reached at 5007020
[mp3 @ 0x7f9694007c00] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'Sleep Away.mp3':
  Metadata:
    track           : 3
    album           : Bob Acri
    artist          : Bob Acri
    title           : Sleep Away
    genre           : Jazz
    album_artist    : Bob Acri
    composer        : Robert R. Acri
    date            : 2004
  Duration: 00:03:21.77, start: 0.000000, bitrate: 192 kb/s
    Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 192 kb/s
At least one output file must be specified

The question I am asking is, how can I use the output data above? I am developiong a music website; say I want to loop through all the MP3 files and save the info about them into a database, so that the above would result in:

Sleep Away.mp3    mp3    3:21    Jazz    2004     Bob Acri ...

obviously in a table

I have tried to use the php backtick operator with no success so far. I just thought I would put a question up here to get some advice from people that have done something similar.

Thanks

Update: I have tried the following

<?php $output = `ffmpeg -i Sleep\ Away.mp3`; echo "<pre>$output</pre>"; ?>
<?php $output = shell_exec('ffmpeg -i Sleep\ Away.mp3'); echo "<pre>$output</pre>"; ?>

both don't appear to return anything.

  • 写回答

3条回答 默认 最新

  • drrrdo0802 2012-08-22 13:51
    关注

    ffmpeg sends that information on standard error, and not to standard output which is what shell_exec() captures.

    You need to add: 2>&1 at the end of your command:

    $out = shell_exec('/path/to/ffmpeg -i Sleep\ Away.mp3 2>&1');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题