I am running the basic script provided in the documentation. This is on a linux server. I am using a .mov file for testing. The frame is generated but the encoding fails with the following error.
exception 'Alchemy\BinaryDriver\Exception\ExecutionFailureException' with message 'ffmpeg failed to execute command '/usr/bin/ffmpeg' '-y' '-i' 'Algonquin elevators 4.mov' '-f' 'webm' '-vcodec' 'libvpx' '-acodec' 'libvorbis' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '128k' 'export-webm.webm'' in /var/www/aims/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php:100 Stack trace: #0 /var/www/aims/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(72): Alchemy\BinaryDriver\ProcessRunner->doExecutionFailure(''/usr/bin/ffmpe...') #1 /var/www/aims/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(209): Alchemy\BinaryDriver\ProcessRunner->run(Object(Symfony\Component\Process\Process), Object(SplObjectStorage), false) #2 /var/www/aims/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(137): Alchemy\BinaryDriver\AbstractBinary->run(Object(Symfony\Component\Process\Process), false, Array) #3 /var/www/aims/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php(155): Alchemy\BinaryDriver\AbstractBinary->command(Array, false, Array) #4 /var/www/aims/ffmpeg-test/index.php(37): FFMpeg\Media\Video->save(Object(FFMpeg\Format\Video\WebM), 'export-webm.web...') #5 {main} Next exception 'FFMpeg\Exception\RuntimeException' with message 'Encoding failed' in /var/www/aims/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php:165 Stack trace: #0 /var/www/aims/ffmpeg-test/index.php(37): FFMpeg\Media\Video->save(Object(FFMpeg\Format\Video\WebM), 'export-webm.web...') #1 {main}
The ffmpeg is working good through cmd line, also it works if I run shell_exec
shell_exec("ffmpeg -i Algonquin elevators 4.mov output.webm &");
I have a similar issue concerning the encoding. PHP-FFMPEG always throws an error Encoding failed after about 49% of the encoding. When I execute the exact command (except for the passlog-parameter) it wont abort unexpectly.
Edit: I tried different videos and codecs. It always stops at 49%..
Is there a posibility to debug the output?
it's probably due to a timeout, have you tried to run it with a timeout equals to 0 ? (see timeout option in https://github.com/PHP-FFMpeg/PHP-FFMpeg#ffmpeg)
timeout is set to zero. Also tried a video of size ~3MB which takes about 5 seconds to 49% and a video with about 100MB which takes ~30sek to 49%
humm, it seems to be about the pass files (49% is when it moves from a file to another)
When the exception is thrown, the command line is run is available, have you tried to run it manually ?
Thats a useful information! Without any passfile-stuff (run from CLI) no error is thrown.
sys_temp_dir = /tmp. PHP also creates the first passlogfile. I've checked this.
What do you mean with "command line is available"?
then exception that is thrown might be an Alchemy\BinaryDriver\Exception\ExecutionFailureException, if you print $exception->getMessage(), you will get the commandline that failed
Yes. The error thrown is:
ffmpeg failed to execute command '/usr/bin/ffmpeg' '-y' '-i' '/var/video/e9c97892aea34b21e2390a47498a9e29.mp4' '-async' '1' '-metadata:s:v:0' 'start_time=0' '-s' '960x720' '-threads' '12' '-vcodec' 'libx264' '-acodec' 'libvo_aacenc' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '128k' '-pass' '2' '-passlogfile' '/tmp/ffmpeg-passes5354eb172ab23ztc1r/pass-5354eb172abf3' '/var/video/output/e9c97892aea34b21e2390a47498a9e29.mp4'
'-pass' '2 seems to prove the php-ffmpeg is unable to create the second passfile? But why? It's an chmod 0777 tmp-folder
run it manually, it's probably about reading the passfile
I cannot. The passfile seems to be deleted after the exception? When i strip the passfile paramters I can run it manually.

File-size is zero?
Running under root just for test purposes..
I tried switching from ffmpeg to avconv. Now it seems to work. Strange! Maybe it was an incompatibility with that ffmpeg version..
cool you managed to do the job.
I'll work on a proper debugger soon (see #94), but you can have an insight about what's wrong with such code:
$ffmpeg = \FFMpeg\FFMpeg::create();
$ffmpeg->getFFMpegDriver()->listen(new \Alchemy\BinaryDriver\Listeners\DebugListener());
$ffmpeg->getFFMpegDriver()->on('debug', function ($message) {
echo $message."\n";
});
$video = $ffmpeg->open($source);
$video->save(new \FFMpeg\Format\Video\X264(), $target);
Thanks for your help and that snippet - And also thanks for that great library.
I am converting flv file into mp4 file on laravel. But I get encoding failed error.. I tried to save a frame and it worked fine. So it may not a permission problem.
exception 'Alchemy\BinaryDriver\Exception\ExecutionFailureException' with message 'ffmpeg failed to execute command '/usr/bin/ffmpeg' '-y' '-i' '/var/www/html/public/temp/pTSKGIGRGGrPL2l6IWAP.flv' '-s' '320x240' '-vcodec' 'libx264' '-acodec' 'libfaac' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '128k' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes54060c1f4a7ce5y500/pass-54060c1f4a945' '/var/www/html/public/videos/2014/09/g73mcjbKxxWFfiR7uG1x.mp4'' in /var/www/html/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php:100
Stack trace:
#0 /var/www/html/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(72): Alchemy\BinaryDriver\ProcessRunner->doExecutionFailure(''/usr/bin/ffmpe...')
#1 /var/www/html/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(209): Alchemy\BinaryDriver\ProcessRunner->run(Object(Symfony\Component\Process\Process), Object(SplObjectStorage), false)
#2 /var/www/html/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(137): Alchemy\BinaryDriver\AbstractBinary->run(Object(Symfony\Component\Process\Process), false, Array)
#3 /var/www/html/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php(158): Alchemy\BinaryDriver\AbstractBinary->command(Array, false, Array)
#4 /var/www/html/app/controllers/VideoController.php(134): FFMpeg\Media\Video->save(Object(FFMpeg\Format\Video\X264), '/var/www/html/p...')
#5 [internal function]: VideoController->videoupload_ajax()
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('videoupload_aja...', Array)
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(VideoController), Object(Illuminate\Routing\Route), 'videoupload_aja...')
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(962): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'VideoController', 'videoupload_aja...')
#10 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(109): call_user_func_array(Object(Closure), Array)
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1028): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(996): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(776): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(746): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#19 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(642): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#21 /var/www/html/public/index.php(49): Illuminate\Foundation\Application->run()
#22 {main}
Next exception 'FFMpeg\Exception\RuntimeException' with message 'Encoding failed' in /var/www/html/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php:168
Stack trace:
#0 /var/www/html/app/controllers/VideoController.php(134): FFMpeg\Media\Video->save(Object(FFMpeg\Format\Video\X264), '/var/www/html/p...')
#1 [internal function]: VideoController->videoupload_ajax()
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('videoupload_aja...', Array)
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(VideoController), Object(Illuminate\Routing\Route), 'videoupload_aja...')
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(962): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'VideoController', 'videoupload_aja...')
#6 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(109): call_user_func_array(Object(Closure), Array)
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1028): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(996): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(776): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(746): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#15 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(642): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#17 /var/www/html/public/index.php(49): Illuminate\Foundation\Application->run()
It might be a lack of support of codecs. Try to run the commandline by yourself and read ffmpeg output
Thank you! I cloned from latest ffmpeg repo and it worked! The problem was libfaac.
@sean-madhavan, how did u solve that problem i got same error too. and i downloaded the latest version what the next step? thank you in advance
If on a mac - Install FFMpeg like this
brew reinstall ffmpeg --with-faac --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools
Remove the older version first.
thanks @ghotgalkar for the comment. How about on linux platform?
Hi guys, why i can't transcode video using php-ffmpeg in CENTOS server I tried in terminal and it works perfectly using root then the command but if not root 'encoding failed' occured. any idea what happening?
thanks @ghotgalkar!!
Thanks @romainneutron for your commnt! Printing out errors revealed me that $ffmpeg->save(); could not save to target directory (even it was chmodded to 0777). I have changed it to /tmp/anyname and now it works.
Thanks @ghotgalkar . Your suggestion worked perfectly on my Mac running El Capitan.
@Grald sorry for the super late reply. Not tried on linux. The main issue is that you need the compile flags to make sure you have all the requirements for audio and video encoding.
I found a lot of info on https://trac.ffmpeg.org/wiki/CompilationGuide
and also there is something specific for CentOS on https://trac.ffmpeg.org/wiki/CompilationGuide/Centos
Hopefully this helps.
@ghotgalkar it's okay now thanks :)
Watermark short videos upload from pc working.
But download video 720p from vimeo and watermark not working
use FFMpeg\FFMpeg;
use FFMpeg\Format\Video\X264;
......
set_time_limit(0);
.......
$ffmpeg = FFMpeg::create([
'ffmpeg.binaries' => '/usr/bin/ffmpeg',
'ffprobe.binaries' => '/usr/bin/ffprobe',
'timeout' => 0, // The timeout for the underlying process
//'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
]);
$video = $ffmpeg->open( '/var/www/webroot/ccbank/frontend/web/uploads/vimeo.mp4');
$watermark = '/var/www/webroot/ccbank/frontend/web/uploads/logo-h100.png';
$video->filters()->watermark($watermark, [
'position' => 'relative',
'right' => 50,
'top' => 50,
]);
$format = new X264();
$output = '/var/www/webroot/ccbank/frontend/web/uploads/watermark1.mp4';
$video->save($format, $output);
Browser error:

error command line:
'/usr/bin/ffmpeg' '-y' '-i' '/var/www/webroot/ccbank/frontend/web/uploads/vimeo.mp4' '-vf' 'movie=/var/www/webroot/ccbank/frontend/web/uploads/logo-h100.png [watermark]; [in][watermark] overlay=main_w - 50 - overlay_w:50 [out]' '-vcodec' 'libx264' '-acodec' 'libfaac' '-b:v' '1000k' '-refs' '6' '-coder' '1' '-sc_threshold' '40' '-flags' '+loop' '-me_range' '16' '-subq' '7' '-i_qfactor' '0.71' '-qcomp' '0.6' '-qdiff' '4' '-trellis' '1' '-b:a' '128k' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes57ee9ba784e323laim/pass-57ee9ba784f92' '/var/www/webroot/ccbank/frontend/web/uploads/watermark1.mp4'
Terminal:

lib libfaac-dev ready installed
How to fix that?
@zinzinday Have you managed to solve your issue?
If no, what is your environment? OS, FFMPEG version, etc...
shell_exec("ffmpeg -y -i input.avi output.avi </dev/null >/dev/null 2>/var/log/ffmpeg.log &");
@Tinywan What is this? Could you add some description to your command?
If you have an issue, please create a new one.
@Romain OK!
I have the same issue, when adding watermark to images. some of images will throw Encoding error. and the result file size become zero.
Hi @shtse8,
This issue is pretty old, and doesn't relate specifically to watermarking.
Could you create a new one pasting the error throwed, your piece of code, and the result of the execution of the command line if you have it, so that we can help you debug your code?
Thanks
run it manually, it's probably about reading the passfile
Thanks, that's a smart way~
Most helpful comment
If on a mac - Install FFMpeg like this
Remove the older version first.