PHP-FFMpeg Installation and Basic Usage on windows issue

好久不见. 提交于 2021-02-08 10:12:45

问题



following the README I installed PHP FFmpeg through Composer and I downloaded binaries from https://ffmpeg.zeranoe.com/builds/
now I'm trying to run the "Basic Usage" example:

<?php
require("vendor/autoload.php");
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('video.mpg');
$video
    ->filters()
    ->resize(new FFMpeg\Coordinate\Dimension(320, 240))
    ->synchronize();
$video
    ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
    ->save('frame.jpg');
$video
    ->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')
    ->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv')
    ->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');
?>

but i receive "Executable not found" errors because I didn't understand where to put them

I also tried specifying binaries ffmpeg.exe and ffprobe.exe with:

$ffmpeg = FFMpeg\FFMpeg::create(array(
    'ffmpeg.binaries'  => '/pathtobin/ffmpeg',
    'ffprobe.binaries' => '/pathtobin/ffprobe',
    'timeout'          => 3600, // The timeout for the underlying process
    'ffmpeg.threads'   => 12   // The number of threads that FFMpeg should use
), $logger);

but still same error... am I making a mountain out of a molehill? any help is appreciated... Thanks

EDIT 1

I added ffmpeg\bin folder to system path and I can run executables from cmd from anywhere, but now I'm getting this error: "Executable not found, proposed : avprobe, ffprobe"...
instead, if I give binary paths explicitly, I get 'ffprobe failed to execute command "C:/FFmpeg/bin/ffprobe.exe" "-help" "-loglevel" "quiet"'

what am I doing wrong?

EDIT 2

web server config

  • Windows 10 Pro
  • IIS 10
  • PHP 7.0.9

site root ---> C:\inetpub\wwwroot\site\
content:
- index.php
- input.mp4
- vendor/ (PHP-FFMpeg library folder)

FFmpeg binaries ---> C:\inetpub\wwwroot\FFmpeg\
content:
- ffmpeg.exe
- ffplay.exe
- ffprobe.exe

index.php

<?php
ini_set('display_errors', 'On'); error_reporting(E_ALL);
require("vendor/autoload.php");
$ffmpeg = FFMpeg\FFMpeg::create(array(
    'ffmpeg.binaries'  => 'C:/inetpub/wwwroot/FFmpeg/ffmpeg.exe',
    'ffprobe.binaries' => 'C:/inetpub/wwwroot/FFmpeg/ffprobe.exe',
    'timeout'          => 3600, // The timeout for the underlying process
    'ffmpeg.threads'   => 12,   // The number of threads that FFMpeg should use
));
$video = $ffmpeg->open('input.mp4');
?>

result

Fatal error: Uncaught Alchemy\BinaryDriver\Exception\ExecutionFailureException: ffprobe failed to execute command "C:/inetpub/wwwroot/FFmpeg/ffprobe.exe" "-help" "-loglevel" "quiet" in C:\inetpub\wwwroot\site\vendor\alchemy\binary-driver\src\Alchemy\BinaryDriver\ProcessRunner.php:100 Stack trace: #0 C:\inetpub\wwwroot\site\vendor\alchemy\binary-driver\src\Alchemy\BinaryDriver\ProcessRunner.php(72): Alchemy\BinaryDriver\ProcessRunner->doExecutionFailure('"C:/inetpub/www...') #1 C:\inetpub\wwwroot\site\vendor\alchemy\binary-driver\src\Alchemy\BinaryDriver\AbstractBinary.php(209): Alchemy\BinaryDriver\ProcessRunner->run(Object(Symfony\Component\Process\Process), Object(SplObjectStorage), false) #2 C:\inetpub\wwwroot\site\vendor\alchemy\binary-driver\src\Alchemy\BinaryDriver\AbstractBinary.php(137): Alchemy\BinaryDriver\AbstractBinary->run(Object(Symfony\Component\Process\Process), false, NULL) #3 C:\inetpub\wwwroot\site\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\FFProbe\OptionsTester.php(61): Alchemy\Binary in C:\inetpub\wwwroot\site\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\FFProbe\OptionsTester.php on line 63

回答1:


The docs say:

This library requires a working FFMpeg install. You will need both FFMpeg and FFProbe binaries to use it. Be sure that these binaries can be located with system PATH to get the benefit of the binary detection, otherwise you should have to explicitly give the binaries path on load.

You will need to store these somewhere permanent and then add this path to your System or User PATH variable:

You would add ";c:\my\path\to\ffmpeg" to the end of the PATH value.




回答2:


I had this problem too. Spent two days using procmon to determine why PHP wasn't starting ffprobe.exe on a new Windows 2016 install.

Turns out if your IIS AppPool identity doesn't have at least modify writes on the C:\Windows\temp folder, you will get this misleading error.

You can get the App Pool identity/context of your site using (not to be confused with the user context provided from get_current_user(). ):

echo "Get ENV: ".getenv("APP_POOL_ID");
Or
echo "Get SERVER: ".$_SERVER["APP_POOL_ID"];

From my analysis, this is because PHP-CGI.exe, CMD.exe & the ffmpeg exe's (ffmpeg.exe, ffprobe.exe, ffplay.exe) use flat files in the temp folder to exchange and parse information. When PHP-CGI.exe creates a temp file in this location all other processes can only read from the temp file, leaving it empty 0 bytes. Every page load, I had these empty temp files being written to C:\Windows\Temp and ffprobe.exe would never execute.

Hope this helps someone.



来源:https://stackoverflow.com/questions/42521137/php-ffmpeg-installation-and-basic-usage-on-windows-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!