FFMPEG returns error

Friends, I’m trying to create a thumb of the video “clock.avi”, but is returning the following error message: ‘ffmpeg’ is not recognized as an internal or external command, operable program or batch file.

My script:


<?php

extension_loaded('ffmpeg') or die('Error in loading ffmpeg');

function ExtractThumb($in, $out)
{
$thumb_stdout;
$errors;
$retval = 0;

// Delete the file if it already exists
if (file_exists($out)) { unlink($out); }

// Use ffmpeg to generate a thumbnail from the movie
$cmd = "ffmpeg -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1";
exec($cmd, $thumb_stdout, $retval);

// Queue up the error for processing
if ($retval != 0) { $errors[] = "FFMPEG thumbnail generation failed"; }

if (!empty($thumb_stdout))
{
foreach ($thumb_stdout as $line)
{
echo $line . "
\
";
}
}

if (!empty($errors))
{
foreach ($errors as $error)
{
echo $error . "
\
";
}
}
}

ExtractThumb('clock.avi', 'clock.jpg');

?>

The FFMPEG is installed correctly, otherwise return “Error in loading ffmpeg”.

Can you help?

You probably need to define the full system path to the ffmpeg binary

How to do it?

Change $cmd = "ffmpeg to $cmd = "/usr/bin/ffmpeg

Replacing “/usr/bin” with the correct path to the executable

The support of my host gave me this, but it does not work: C:\Program Files (x86)\PHP\v5.2\ffmpeg

You would need to use either: “C:\\Program Files (x86)\\PHP\\v5.2\\ffmpeg -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1”
or ‘C:\Program Files (x86)\PHP\v5.2\ffmpeg -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1’

‘C:\Program’ is not recognized as an internal or external command, operable program or batch file.

Try: $cmd = ‘“C:\Program Files (x86)\PHP\v5.2\ffmpeg” -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1’;

Gave the same error. I think there can be no spaces.

Quoting the file path is how you use spaces. And since you need double quotes to surround the path, your string has to be single quotes (in order to avoid having to escape the double quote characters).

Add the .exe file extension to the file path. The windows binary typically has it. The linux servers with a linux binary do not. However, if this isn’t actually a Windows binary, note that you can’t use a linux binary on windows.

So, assuming that the path to ffmpeg is correct and that the correct binary for the operating system is being used, the command string should be something like this:

$cmd = '"C:\\Program Files (x86)\\PHP\\v5.2\\ffmpeg.exe" -itsoffset -4 -i '.$in.' -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 '.$out.' 2>&1'; 

‘C:\Program’ is not recognized as an internal or external command, operable program or batch file.

Install ffmpeg in c:\ffmpeg then you won’t need to worry about windows paths or spaces

How about this?

$cmd = "\\"C:/Program Files (x86)/PHP/v5.2/ffmpeg.exe\\" -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1";

He returned this:

‘C:/Program’ is not recognized as an internal or external command, operable program or batch file.

I did so

$cmd = "\\'C:/Program Files (x86)/PHP/v5.2/ffmpeg.exe\\' -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1";

and returned it

The filename, directory name, or volume label syntax is incorrect.

Well that is a start. Can you echo the $cmd variable and paste the output here so I can see how the $in and $out variables are being inserted?

Example:

$cmd = "\\'C:/Program Files (x86)/PHP/v5.2/ffmpeg.exe\\' -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1";  
echo $cmd;

\‘C:/Program Files (x86)/PHP/v5.2/ffmpeg.exe\’ -itsoffset -4 -i clock.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 clock.jpg 2>&1

Okay, I researched the error you received, and it seems that is from Windows and it hates the apostrophes.

So back to square one.
Try this:

$cmd = "\\\\\\"C:/Program Files (x86)/PHP/v5.2/ffmpeg.exe\\\\\\" -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1";  

‘\“C:/Program Files (x86)/PHP/v5.2/ffmpeg.exe\”’ is not recognized as an internal or external command, operable program or batch file. =/

This sounds weird by try removing the .exe extension

$cmd = "\\\\\\"C:/Program Files (x86)/PHP/v5.2/ffmpeg\\\\\\" -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1";  

‘\“C:/Program Files (x86)/PHP/v5.2/ffmpeg\”’ is not recognized as an internal or external command, operable program or batch file. FFMPEG thumbnail generation failed