0
votes

I have to get the thumbnail image of video i am using the ffmpeg. On my server i run the ffmpeg command from ssh then it is working but from the php exec function it is not working it gives the error /usr/bin/ffmpeg : no such file or dirctory but the ffmpeg is installed on this location usr/bin/ffmpeg. my source code is:

$ffmpeg = '/usr/bin/ffmpeg';

$videoname = 'myvideo.mp4';

$video = $_SERVER['DOCUMENT_ROOT'].'/uploads/videos/'.$videoname;

$image = $_SERVER['DOCUMENT_ROOT'].'/uploads/thumbs/thumb.jpg';

$second = 1;

$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";

exec($cmd);

Please provide any solution.

2
Instead of just running exec() and assuming that you've not made a mistake, why not print the command that's being run and verify that it's correct?Sammitch
My root path is correct as i print the command: /usr/bin/ffmpeg -i path_to_video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg Path_to_thumb 2>&1Naman Tamrakar

2 Answers

0
votes

Update you code with this one you will be good to go.

`$ffmpeg = '/usr/bin/ffmpeg';

$videoname = 'myvideo.mp4';

$video = $_SERVER['DOCUMENT_ROOT'].'/uploads/videos/'.$videoname;

$image = $_SERVER['DOCUMENT_ROOT'].'/uploads/thumbs/thumb.jpg';

$second = 1;

$cmd = "$ffmpeg -i '".$video."' -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg '".$image."' 2>&1"; echo $cmd; exec($cmd);`

Sometimes exec() function miss behaves due to missing quotes around variables.

0
votes

Use shell_exec instead of exec

$ffmpeg = '/usr/bin/ffmpeg';

$videoname = 'myvideo.mp4';

$video = $_SERVER['DOCUMENT_ROOT'].'/uploads/videos/'.$videoname;

$image = $_SERVER['DOCUMENT_ROOT'].'/uploads/thumbs/thumb.jpg';

$second = 1;

$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";

shell_exec($cmd);