douben7260 2013-11-10 11:34
浏览 1098
已采纳

找到ffmpeg的绝对路径

I installed ffmpeg and ffmpeg-php to my dedicated server and with a small script i am trying to extract an image from specific second.

<?php

$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;

$timeOffset = "00:00:30";
$videoPath = "sample.mp4";
$extensi = ".jpg";
$folder = "images/";
$finalfilename = $folder . $randomfilename . $extensi;

echo $extension_fullname; //I AM GETING THIS /usr/lib64/php/modules/ffmpeg.so

if (exec("ffmpeg -ss $timeOffset -i $videoPath  -frames:v 1 $finalfilename")){
echo "Done";
}else{
echo "Error";   
}
?>

as you can see in my execution command ther is ffmpeg, but how can i find the absolute path to ffmpeg? Take a look in my screenshot maybe this helps you to tell me..

My last question is what is ffmpeg-php? Do i need it? i already install it.

Thank you

enter image description here

  • 写回答

1条回答 默认 最新

  • dongtan7351 2013-11-10 12:11
    关注

    If you're using ffmpeg executable you won't need ffmpeg-php. You might want to use ffmpeg executable only, since together with ffprobe executable you could do anything.

    I didn't get the point of your $extension*'s variables. To know the absolute path where your ffmpeg is installed you could use the which program: which ffmpeg.

    Your exec() call checking is wrong, I'd suggest you to use it this way:

    exec("ffmpeg -v error -y -ss $timeOffset -i $videoPath -vframes 1 $finalfilename 2>&1 >/dev/null", $stderr, $exit_status);
    
    if ($exit_status === 0) {
        print 'Done! :)';
    } else {
        print 'Error... :/';
        // implode("
    ", $stderr) will help you figure out what happened...
    }
    

    I've added -v error to let ffmpeg output only error messages and -y to avoid $finalfilename file-existing issue. I've also suppressed all STDOUT and moved only STDERR output to $stderr variable. If your exec() call fail for some reason ($exit_status will be non 0), you'll get what happened on that $stderr array.

    If I'm missing something, please, let me know!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型