Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

sh: ffmpeg: command not found when run command through php

I have installed successfully installed FFMpeg on root of my Centos 6 machine (https://trac.ffmpeg.org/wiki/CompilationGuide/Centos).

My workplace of apache/php is /var/www/html

Now I'm running below command successfully on /var/www/html directory to capture frame from the video file. It's capturing a frame.

[root@localhost html]# ffmpeg -i video.mpg -an -ss 30  -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg -s 160x100 frame8  2>&1

I want to run this command through php and using shell_exec() or exec() php functions. My php code for running the command is:

$cmd = "/root/bin/ffmpeg -i /project/app/webroot/videos/video.mpg -ss 00:00:14.435 -f image2 -vframes 1 /project/app/webroot/videothumbnails/example-thumb.jpg";
$locale = 'en_IN.UTF-8';
setlocale(LC_ALL, $locale);
putenv('LC_ALL='.$locale);
echo shell_exec($cmd);

When I'm trying to run command through above php code, I'm getting below error:

sh: ffmpeg: command not found

Please help me to solve out this problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For Video Thumbnail creation we use ffmpeg.

In Linux Systems(centos 6.x) Ffmpeg installation process and Php example:-

This process is done in my centos 6 and created thumbnails using php.

Step1:- Please check If any existing ffmpeg available or not in your linux server .If available please remove that files.

Step2:- For New ffmpeg installation follow this link
http://root.uabid.com/compile-ffmpeg-on-centos-6-x/ .

Step3:- After installation complete check whereis your ffmpeg installed.

Command: whereis ffmpeg

type this command in linux command line and check.If for example your ffmpeg path in (/usr/local/bin/ffmpeg). Use this path in your code.

Php Example:-

<?php

    if($extension === 'mp4' OR $extension == 'MP4' )
    {
    $video = $timestamp.$imagename;
    $videoname=substr($imagename,0, -4).$timestamp;
    $image = "sites/default/files/content_images/{$videoname}-thumb.jpg";

    var_dump($video);

    $cmd = "/usr/local/bin/ffmpeg -i    /opt/lampp/htdocs/myproject/sites/default/files/content_videos/".$video." -ss   00:00:01.435 -f image2 -vframes 1       /opt/lampp/htdocs/myproject/sites/default/files/content_images/".$videoname."-  thumb.jpg";

    $cmdstr = $cmd;
    $locale = 'en_IN.UTF-8';
    setlocale(LC_ALL, $locale);
    putenv('LC_ALL='.$locale);
    echo exec($cmd);
?>

Process 2:- This is for static file paths:

<?php    
    $cmd = "/root/bin/ffmpeg -i /var/www/html/project/app/webroot/videos/example.mp4 -ss   00:00:01.435 -f image2 -vframes 1 /var/www/html/project/app/webroot/videothumbnails/example-thumb.jpg";
    $cmdstr = $cmd;
    $locale = 'en_IN.UTF-8';
    setlocale(LC_ALL, $locale);
    putenv('LC_ALL='.$locale);
    echo exec($cmd);
?>

Hope this helps to you & others..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...