1

I am trying to transcode a video file of 1.2mb file uploaded to my website server via php/html upload, but I keep getting the error:

PHP Fatal error:

Uncaught exception 'Alchemy\BinaryDriver\Exception\ExecutionFailureException' with message 'ffmpeg failed to execute command '/usr/local/bin/ffmpeg' '-y' '-i' '/home/user/public_html/contents/videos/1490719990_MP4_360p_Short_video_clip_nature_mp4.mp4' '-async' '1' '-metadata:s:v:0' 'start_time=0' '-r' '16' '-b_strategy' '1' '-bf' '3' '-g' '9' '-vcodec' 'libx264' '-acodec' 'libmp3lame' '-b:v' '128k' '-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' '8k' '-ac' '1' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes58dab05a323b6eknk4/pass-58dab05a32465' '/home/user/public_html/contents/videos/1490719990_MP4_360p_Short_video_clip_nature_mp4_22995.mp4'' in /home/user/public_html/app/ffmpeg/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php:100

Stack trace:

0 /home/user/public_html/app/ffmpeg/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(72):

Alch in /home/user/public_html/app/ffmpeg/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php on line 168

Funny thing is that the same server is extracting frames and getting duration of the same file using ffprobe and ffmpeg.

Here is the code I am using to transcode:

$ffmpeg = $ffmpeg = FFMpeg\FFMpeg::create(['timeout'=>3600, 'ffmpeg.thread'=>12, 'ffmpeg.binaries'  => '/usr/local/bin/ffmpeg',
    'ffprobe.binaries' => '/usr/local/bin/ffprobe']);

            $ffprobe_prep = FFMpeg\FFProbe::create(['ffmpeg.binaries'  => '/usr/local/bin/ffmpeg',
    'ffprobe.binaries' => '/usr/local/bin/ffprobe']);
            $ffprobe = $ffprobe_prep->format($video_file);

            $video = $ffmpeg->open($video_file);

            // Get video duration to ensure our videos are never longer than our video limit.
            $duration = $ffprobe->get('duration');

            // Use mp4 format and set the audio bitrate to 56Kbit and Mono channel.
            // TODO: Try stereo later...
            $format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');
            $format
                -> setKiloBitrate(128)
                -> setAudioChannels(1)
                -> setAudioKiloBitrate(8);

            $first = $ffprobe_prep
                        ->streams($video_file)
                        ->videos()
                        ->first();

            $width = $first->get('width');

            if($width > VIDEO_WIDTH){
                // Resize to 558 x 314 and resize to fit width.
                $video
                    ->filters()
                    ->resize(new FFMpeg\Coordinate\Dimension(VIDEO_WIDTH, ceil(VIDEO_WIDTH / 16 * 9)));
            }

            // Trim to videos longer than three minutes to 3 minutes.
            if($duration > MAX_VIDEO_PLAYTIME){

                $video
                    ->filters()
                    ->clip(FFMpeg\Coordinate\TimeCode::fromSeconds(0), FFMpeg\Coordinate\TimeCode::fromSeconds(MAX_VIDEO_PLAYTIME));
            }

            // Change the framerate to 16fps and GOP as 9.
            $video
                ->filters()
                ->framerate(new FFMpeg\Coordinate\FrameRate(16), 9);

            // Synchronize audio and video
            $video->filters()->synchronize();

            $video->save($format, $video_file_new_2);

I have contacted my host to no vital assistance. The only useful information they can provide me is that ffmpeg was compiled on the server with libmp3lame support.

This code works perfect on localhost

Any help as to why I may be getting the error and how to correct it is appreciated.

Community
  • 1
  • 1
  • 1
    have you tried to launch this command on the console: '/usr/local/bin/ffmpeg' '-y' '-i' 'myvideo' '-async' '1' '-metadata:s:v:0' 'start_time=0' '-r' '16' '-b_strategy' '1' '-bf' '3' '-g' '9' '-vcodec' 'libx264' '-acodec' 'libmp3lame' '-b:v' '128k' '-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' '8k' '-ac' '1' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes58dab05a323b6eknk4/pass-58dab05a32465' 'myvideo' That's the best way of getting feedback about what is going on. – Iván Rodríguez Torres Mar 28 '17 at 21:58
  • I am on a shared host. I do not have access to the terminals. –  Mar 28 '17 at 21:59
  • Okey. In your local go to `ffmpeg/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php` find the line 167 and print the args passed to ` $this->driver->command();` then do the same in y our host. Check if there are some differences – Iván Rodríguez Torres Mar 28 '17 at 22:05
  • They are different. The local one has four items in an array, but the one on the server has just too. –  Mar 28 '17 at 22:53
  • spotting that kind of bugs without having the project it's very difficult. But now, you know were to begin to search. Find out why params are different, since, it shouldn't. Once you find it, you will get the problem solved – Iván Rodríguez Torres Mar 28 '17 at 23:22
  • Your `ffmpeg` command looks like it's from 2007. Use the x264 encoding presets instead of attempting to use a legion of random options. Replace `-b_strategy 1 -bf 3 -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` with `-preset slow`. However, this won't solve whatever issue you're experiencing, but it will make a more sane command. – llogan Mar 29 '17 at 18:27
  • 1
    @IvánRodríguezTorres "have you tried to launch this command on the console" saved me. My environment is Ubuntu 18 Bionic Beaver. Seems `libfaac` library is not included with ffmpeg for licensing reasons. The terminal thrown error: Unknown encoder 'libfaac' and then I resolved with `$format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');` – Sarvap Praharanayuthan Aug 16 '18 at 18:06
  • @ViswalingaSuryaS, You should have added that as an answer. That was what I finally did. That's the solution. –  Mar 09 '19 at 22:02

0 Answers0