I have a file located at html://www.example.com/wp-content/music.mp3
I've tested and confirmed ffmpeg is installed and have run
exec("ffmpeg -help",$output);
I successfully get an output. Now i want to start converting but i cannot locate the file above. I've tried
exec("ffmpeg -i html://www.example.com/wp-content/music.mp3",$output);
exec("ffmpeg -i home/mywebsite/public_html/wp-content/music.mp3",$output);
I get no output for either. ffmpeg is located in /usr/bin/ffmpeg.
How do i solve?
Redirect the error output (stderr) to response (stdout):
<?php
$command = "ffmpeg -i https://www.example/a.mp3 2>&1";
$output = shell_exec($command);
echo $output;
Related
I have a PHP script with two FFmpeg commands. The first command combines a list of .ts files into a single .ts file and logs the output information into a textfile. The second command converts the combined .ts file into an mp4 file and logs the output information into a textfile.
Here's the PHP:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$ffmpeg = "/usr/local/bin/ffmpeg";
$vidClips = 'my_vids/vidClipslist.txt';
$combinedFileTs = 'my_vids/combinedFileTs.ts';
$logFileCombine = 'my_vids/logFileCombine.txt';
$logFileConvert = 'my_vids/logFileConvert.txt';
$combinedFileMp4 = 'my_vids/combinedFileMp4.mp4';
shell_exec("$ffmpeg -f concat -safe 0 -i $vidClips -c copy $combinedFileTs 1> $logFileCombine 2>&1");
shell_exec("$ffmpeg -i $combinedFileTs -f mpegts -codec:v mpeg1video -bf 0 -codec:a mp2 -q 12 $combinedFileMp4 1> $logFileConvert 2>&1");
echo "Video finished.";
?>
When I run this, my 500.shtml file message is shown on the page. However, I get no other error message echoed to the page nor are there any errors in my Cpanel error log. I also have a php error log set up, but it doesn't show any errors.
Oddly, both of the FFmpeg commands do what they're supposed to, i.e., the "combinedFileTs.ts", "logFileCombine.txt", "combinedFileMp4.mp4", and "logFileConvert.txt" are all created. It's just that I'm getting the 500 error and the PHP script following the two FFmpeg commands is not being run, i.e., echo "video finished."
When I remove the output directive on the first FFmpeg command, i.e., "1> $logFileCombine 2>&1", everything works. All the files are created, the proceeding PHP script is run, and I don't get the 500 error.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$ffmpeg = "/usr/local/bin/ffmpeg";
$vidClips = 'my_vids/vidClipslist.txt';
$combinedFileTs = 'my_vids/combinedFileTs.ts';
$logFileCombine = 'my_vids/logFileCombine.txt';
$logFileConvert = 'my_vids/logFileConvert.txt';
$combinedFileMp4 = 'my_vids/combinedFileMp4.mp4';
shell_exec("$ffmpeg -f concat -safe 0 -i $vidClips -c copy $combinedFileTs");
shell_exec("$ffmpeg -i $combinedFileTs -f mpegts -codec:v mpeg1video -bf 0 -codec:a mp2 -q 12 $combinedFileMp4 1> $logFileConvert 2>&1");
echo "Video finished.";
?>
Also, the first FFmpeg command takes about 2 min to run. Thinking that the problem was due to the PHP script being killed, I increased the max_execution_time to 600 and the memory_limit to 512M in my php.ini file but that did not fix the problem.
I need both FFmpeg commands to produce an output log textfile and I need the proceeding PHP code to run.
I am good in php but very new to ffmpeg and exec stuffs.Now I have successfully installed ffmpeg via ssh.I referred some stackoverflow here and found below code to make video using several images.
<?php
echo exec('ffmpeg -f image2 -i image%d.jpg video.mpg');
?>
I have image1.jpg and image2.jpg in same folder.I run this php code but nothing happened...where does video.mpg gets saved ? and how to check if exec function ran successfully or how to debug it ?Any help is appreciated.
If it successfully worked, video.mpg got saved in your current working directory. If needed you can change filenames to absolute paths.
To check if exec() function ran successfully you can pass the third argument to get the exit status:
exec('ffmpeg -f image2 -i image%d.jpg video.mpg', $output, $exit_status);
If successful, $exit_status will got 0 value, so:
if ($exit_status === 0) {
// ran fine
} else {
// failed...
}
If it's failling you might want to get errors on $output. You can move STDERR to STDOUT ignoring original STDOUT this way:
exec('ffmpeg -f image2 -i image%d.jpg video.mpg 2>&1 >/dev/null', $output, $exit_status);
Then you could dump $output to see what you got on STDERR:
if ($exit_status !== 0) {
print implode("\n", $output);
}
If the video.mpg file already exists the command will get stuck, you might want to pass -y flag to ffmpeg to overwrite any existing file:
exec('ffmpeg -y -f image2 -i image%d.jpg video.mpg 2>&1 >/dev/null', $output, $exit_status);
Have been trying to execute FFMPEG using a script I have uploaded to my domain
<?php
$output = array();
$result = -1;
exec('../../../../../../usr/bin/ffmpeg -ab 320k -i source.wav dest320.mp3', $output, $result);
var_dump($output, $result);
?>
The example code says the program should not be returning -1 unless there is an error but I have pointed to the exact path that FFMPEG is stored in.....
When I call 'ffmpeg -ab 320k -i source.wav dest320.mp3' from CentOS it works...
Am lost and have spent hte last few hours trying to work it out.
Thanks
CP
Any time you have an exec that doesn't work in php, you should switch to passthru for debugging.
passthru('../../../../../../usr/bin/ffmpeg -ab 320k -i source.wav dest320.mp3 1 2>&1');
Appending 1 2>&1 to the end, pipes your stderr to stout, and returns any errors you have while running your exec.
It is probably safer to use passthru('/usr/bin/env ffmpeg -ab 320k -i source.wav dest320.mp3 1 2>&1'); which will get the correct path for ffmpeg without the need to specify and absolute/relative path.
Also worth noting that if you are using Ubuntu since 12.04, the ffmpeg command has been renamed to avconv.
i'm trying to extract a single frame from a video file using the following php code:
$cmd = 'ffmpeg -i "d:\webs\beta\test\sample2.mp4" -vframes 1 -s 146x82 -f image2 "d:\webs\beta\test.jpg"';
exec($cmd, $rc);
the problem is that i'm getting an 500 internal server error the first time i'm trying to execute the script, but when reloading it works.
so it means when reloading: works / doesn't work / works ..
any ideas what could be wrong?
Try this script.
<?php
$ffmpeg = "/full/path/to/ffmpeg";
$videoFile = "/full/path/to/video.mp4";
$imgOut = "/full/path/to/frame.jpg";
$second = 0;
$cmd = $ffmpeg." -i \"".$videoFile."\" -an -ss ".$second.".001 -y -f mjpeg \"".$imgOut."\" 2>&1";
$feedback = `$cmd`;
?>
i had the same problem exactly.
using proc_open instead of exec and its variants fixed it.
Roey
I am confused with instruction to install ffmpeg-php for video converting... There are some guide us to download and put files in particular folder and then convert files, but some instruct through another way, where you must download ffmpeg.exe and place it local and then call it from php to convert file.....
So which one is the best and how to install it....?????
Now i download ffmpeg and execute this script but not working, and give rights also...
$ffmpeg = "ffmpeg/ffmpeg.exe";
$desvfile = $_POST['file'];
$curr_dir = dirname(__FILE__);
$flvfile = $curr_dir."/converted/new1.flv";
if(file_exists($ffmpeg)){
$cmd = "ffmpeg/ffmpeg.exe -i ".$desvfile." -ar 22050 -ab 32 -f flv -s 320×240 ".$flvfile;
exec($cmd, $output);
echo "executed command: [".$cmd."] with result: ".print_r($output, true)."<br>\n";
echo "Successfully video Converted, to video.flv";
}
else{
echo "There is some problem during converting!";
}
There is any way, to test => exec(ffmpeg) functionality....?????
UPDATED!
if(file_exists($desvfile)){
echo "Destination file Exist. <br />";
$cmd = "$ffmpeg -i '$desvfile' -ar 22050 -ab 32 -f flv -s 320×240 '$flvfile'";
exec(escapeshellcmd($cmd), $output);
echo "executed command: => [".$cmd."] <br />with result: => ".print_r($output, true)."<br>\n";
echo "Successfully video Converted, to video_converted.flv";
}
else{
echo "There is some problem during converting!";exit;
}
Which give me the output,,, but not execute the video to convert....
Output:
// Destination file Exist.
// executed command: => [/var/www/html/test_site/converter/ffmpeg/ffmpeg.exe -i '/var/www/html/test_site/converter/uploads/Gazzump.com - YouTube - Anders And.avi' -ar 22050 -ab 32 -f flv -s 320×240 '/var/www/html/test_site/converter/converted/new1.flv']
// with result: => Array ( )
// Successfully video Converted, to video_converted.flv
I've always found it easier to call FFMPEG with exec(). It is much easier to find exe builds of FFMPEG than the PHP extension. There is no install procedure for this method... just put the EXE somewhere on the server that is accessible by whatever account PHP is executing as.
There is no "best way" really. Both methods of accessing FFMPEG will produce the same output.