doujiao2443
doujiao2443
2012-11-10 02:25

ffmpeg:如何获取PHP的可用编解码器列表?

已采纳

Problem is, I am trying to convert (through php), a .3gp (or any video format) file to ogg.

When I do not specify -vcodec and -acodec, the video is converted, but does not have any audio.

I had read here and other places that I need to specify -acodec libvorbis, however, when I specify the codec as libvorbis, the conversion fails: video converts to 0byte file.

Basically, I am trying to determine if the codec specified is actually part of the ffmpeg build I am using as a process of narrowing down my issue.

Code that produces full length video without sound:

$srcFile = 'anyvideo.3gp';
$destFile = 'anyvideo.ogg';
$ffmpegPath = 'path/to/ffmpeg.exe';
$ffmpegObj = new ffmpeg_movie($srcFile);
$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth()); 
$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
$srcFPS = $ffmpegObj->getFrameRate(); 
$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
$srcAR = $ffmpegObj->getAudioSampleRate();
$srcLen = $ffmpegObj->getDuration();

exec($ffmpegPath." -i ".$srcFile." -ar ".$srcAR." -s ".$srcWidth."x".$srcHeight." ". $destFile);

And the code that produces 0byte file:

exec($ffmpegPath." -i ".$srcFile." -acodec libvorbis -ar ".$srcAR." -s ".$srcWidth."x".$srcHeight." ".$destFile);

So, my question is, how do I determine the codec's available to ffmpeg using PHP? Can it even be done?

UPDATED - ANSWER BELOW

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dongna2498 dongna2498 9年前

    ANSWER:

    exec($ffmpegPath." -codecs", $codecArr);
    for($ii=0,$ii<count($codecArr);$ii++){
        echo $codecArr[$ii];
    }
    
    点赞 评论 复制链接分享
  • dpdx51205 dpdx51205 8年前

    Since ffmpeg version 0.8 it is

    $ ffmpeg -codecs
    

    If you have an older version use

    $ ffmpeg -formats
    

    There are other ffmpeg option syntax changes, too. E.g. -vcodes is -c:v since ffmpeg 0.9.

    You might have have also a look to the php library html5-video-php to convert your videos to MP4, WEBM, or OGG formats. The library wraps ffmpeg and considers the different ffmpeg versions. To list all available codecs and retrive basic video infos use:

    $html5video = new Html5Video\Html5Vide();
    $codecsList = $html5video->getEncoders();
    $videoInfo = $html5video->getInfo($src);
    
    点赞 评论 复制链接分享
  • dougao2830 dougao2830 9年前

    You should be able to see what formats are installed by using the -formats flag on the commandline

    ffmpeg -formats
    

    This will output a long list of codecs available to you.

    点赞 评论 复制链接分享