FFMpeg package file convert problem

Recently I was watching Multiple Drag And Drop File Uploading and Processing with Inertia course. I get in trouble with the EncodeVideo Job File.

My EncodeVideo Job File

<?php

namespace App\Jobs;

use App\Events\EncodeVideoStart;
use App\Models\Video;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;
use ProtoneMedia\LaravelFFMpeg\Support\FFMpeg;

class EncodeVideo implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $timeout = 0;

    /**
     * Create a new job instance.
     */
    public function __construct(public Video $video)
    {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        event(new EncodeVideoStart($this->video));

        FFMpeg::fromDisk('public')
            ->open($this->video->video_path)
            ->export()
            ->toDisk('public')
            ->inFormat(new \FFMpeg\Format\Video\X264())
            ->save('videos/' . Str::uuid() . 'mp4');
    }
}

When the job is run my queue show fails.

Log file

[2024-03-01 13:02:57] local.INFO: Broadcasting [App\Events\EncodeVideoStart] on channels [private-users.1] with payload:
{
    "video_id": 24,
    "socket": null
}  
[2024-03-01 13:02:57] local.INFO: ffprobe running command '/usr/bin/ffprobe' '-help' '-loglevel' 'quiet'  
[2024-03-01 13:02:57] local.INFO: ffprobe executed command successfully  
[2024-03-01 13:02:57] local.INFO: ffprobe running command '/usr/bin/ffprobe' '/home/polash/Sites/polash/storage/app/public/videos/d67d47d8-787c-4fad-944d-22b59ddd3eaa' '-show_streams' '-print_format' 'json'  
[2024-03-01 13:02:57] local.INFO: ffprobe executed command successfully  
[2024-03-01 13:02:57] local.INFO: ffmpeg running command '/usr/bin/ffmpeg' '-y' '-i' '/home/polash/Sites/polash/storage/app/public/videos/d67d47d8-787c-4fad-944d-22b59ddd3eaa' '-threads' '12' '-vcodec' 'libx264' '-acodec' 'aac' '-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-passes65e1d2013cb0a/pass-65e1d2013cbd6' '/home/polash/Sites/polash/storage/app/public/videos/18fde341-b1d4-46e3-9ecd-6592f31dc33cmp4'  
[2024-03-01 13:02:57] local.INFO: ffprobe running command '/usr/bin/ffprobe' '/home/polash/Sites/polash/storage/app/public/videos/d67d47d8-787c-4fad-944d-22b59ddd3eaa' '-show_format' '-print_format' 'json'  
[2024-03-01 13:02:57] local.INFO: ffprobe executed command successfully  
[2024-03-01 13:02:57] local.ERROR: ffmpeg failed to execute command '/usr/bin/ffmpeg' '-y' '-i' '/home/polash/Sites/polash/storage/app/public/videos/d67d47d8-787c-4fad-944d-22b59ddd3eaa' '-threads' '12' '-vcodec' 'libx264' '-acodec' 'aac' '-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-passes65e1d2013cb0a/pass-65e1d2013cbd6' '/home/polash/Sites/polash/storage/app/public/videos/18fde341-b1d4-46e3-9ecd-6592f31dc33cmp4': ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
[wmv3 @ 0x55fdd61aaac0] Extra data: 8 bits left, value: 20
Guessed Channel Layout for Input Stream #0.0 : stereo

so, I make a route in my web.php for testing purposes

Route::get('/try', function() {
   FFMpeg::fromDisk('public')
    ->open('videos/9aa05166-8d9b-4f48-bba5-9f445382625b')
    ->export()
    ->toDisk('public')
    ->inFormat(new \FFMpeg\Format\Video\X264)
    ->save('/videos/abc.mp4');
});

when I hit try route, it works.

I am also check

$ which ffmpeg
/usr/bin/ffmpeg

$ which ffprobe
/usr/bin/ffprobe

My .env file

FFMPEG_BINARIES=/usr/bin/ffmpeg
FFPROBE_BINARIES=/usr/bin/ffprobe

ffmpeg -version command output:

ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

also, I am checking ffmpeg -i input.mp4 output.mp4 this command for testing purposes and it works. so I think when I run the ffmpge package command as a job, it's not working. I tried a lot but couldn't find any solution to this problem.

polash
polash
0
3
143
alex
alex
Moderator
Solution

This may be due to the fact you're not adding the file extension properly here.

->save('videos/' . Str::uuid() . 'mp4');

It should be

->save('videos/' . Str::uuid() . '.mp4'); // added a dot before mp4

Try this and if it doesn't work, we'll debug further!

polash
polash

How did I miss such a simple thing :( Thank you so much. now it's working

alex
alex
Moderator

The small things are the hardest to spot sometimes! Glad that worked.