【问题标题】:FFMPEG with PHP does not execute?FFMPEG 与 PHP 不执行?
【发布时间】:2012-09-08 06:02:37
【问题描述】:

在阅读了有关 FFMPEG 和 PHP 的 SO 上的大量问题后,我收集了一个小的 sn-p 或其他类似的东西,但它似乎没有做任何事情 - 甚至没有抛出错误。

我的PHP如下:

function get_video_thumbnail($file) {
    define('ALL_PLACE_WIDTH', 250);
    define('ALL_PLACE_HEIGHT', 200);

    $ffmpeg = "ffmpeg"; // where ffmpeg is
    $image_source_path = $file; // where the video is
    $image_cmd = " -r 1 -ss 00:00:10 -t 00:00:01 -s ".ALL_PLACE_WIDTH."x".ALL_PLACE_HEIGHT."   -f image2 "; // command
    $dest_image_path = "cdn/thumbnails"; // destination of thumbnail

    $str_command = $ffmpeg  ." -i " . $image_source_path . $image_cmd .$dest_image_path;     
    shell_exec($str_command);
}

在根文件夹中有一个文件夹“ffmpeg”,里面有“ffmpeg.exe”、“ffplay.exe”和“pthreadGC2.dll”。所以我想知道,我有什么遗漏吗?我正在尝试从视频/mp4 文件生成缩略图。

【问题讨论】:

  • 如果您从命令行运行相同的参数,您会生成缩略图吗?如果您运行exec(escapeshellcmd($cmd), $out, $val),您会在输出 $out 和 $val 中看到什么?分解它 - 首先尝试先执行一个简化版本,以了解通过 PHP shell 调用时 ffmpeg 是否正常工作。例如'ffmpeg -h'
  • 我就是这样做的: $exec_string = "ffmpeg -y -ss ".($position)." -i $filebase.mpg -vf scale='iw:ow/dar', setsar=1:1 -deinterlace -t 1 $output_base";你在-ss之前设置-t很奇怪,应该是-t 11
  • 还有其他方法可以执行外部命令,从而更好地控制其环境和输出:execproc_open。将2>&1 附加到命令中,通过exec 调用它,捕获并打印输出,检查它是否有任何错误消息...

标签: php ffmpeg thumbnails


【解决方案1】:

cdn/thumbnails 是一个文件夹吗?如果是这样,您必须提供文件名。你只给了一个文件夹。因此它不起作用。由于您希望每秒一个 10 秒,因此您必须提供诸如 cdn/thumbnails/images%03d.jpg 之类的内容作为输出。

所以你的命令看起来像这样:

ffmpeg -i inputfile -s widthxheight -f image2 文件夹/文件名%04d.jpg

转到命令行并首先输入命令。确保它在那里工作。然后它将在 php 中工作。

文件将被命名为 filename0000.jpg filename0001.jpg 等等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-04
    • 2013-01-14
    • 1970-01-01
    • 2015-07-13
    • 2011-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多