I am trying to use the command given in the selected answer here, but it does not work when executed. I know that everything else is working since I can create thumbnails with a different command. What is the proper way to format this? I am assuming that the problem is with " -vsync 0 -vf select='not(mod(n,100))' " but have not been able to get it working.
$cmd = $ffmpeg . " -i " . $src . " -vsync 0 -vf select='not(mod(n,100))' " . $out . ".jpg";
exec($cmd);
You have error on this line:
$cmd = $ffmpeg . " -i " . $src . " -vsync 0 -vf select='not(mod(n,100))' " . $out . ".jpg";
Change it to:
$cmd = "ffmpeg -i " . $src . " -vsync 0 -vf \"select='not(mod(n,100))'\" " . $out . ".jpg";
Or try:
$cmd = "ffmpeg -i " . $src . " -vsync 0 -vf select='not(mod(n,100))' " . $out . ".jpg";
Also when you call exec function call it like this:
exec($cmd,$out);
print_r($out);
Print_r will print you output of what was executed in exec()...
Related
I am working on a PHP code as shown below in which conversion of mp4 into mp3 is happening at Line B.
I have added if block after system command to print Conversion Completed on the webpage once the conversion is complete but it doesn't seem to work.
Php code:
if (isset($_POST['id']))
{
for($i=0; $i <count($mp4_files); $i++) {
if($i == $_POST['id']) {
$f = $mp4_files[$i];
$parts = pathinfo($f);
switch ($parts['extension'])
{
case 'mp4' :
$filePath = $src_dir . DS . $f;
print_r($f); // Line A
system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3', $result); // Line B
if($result)
{
echo "Conversion Completed";
}
}
}
}
}
Problem Statement:
I am wondering what changes I should make in the PHP code above so that once the conversion is complete; on the webpage, it should print Conversion Completed.
You can use shell_exec to get a return value and then put that in an if statement like this
$output = shell_exec('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3');
if ($output) {
echo "Conversion Completed!";
// or redirect here
}
Also, make sure to sanitize your inputs as they are exposed to a CLI interface.
I am working on database migration. I have written a code for executing the command that retrieves the data from database and pushes into a csv file. This Works fine in MySQL but when I try to do the same in SQL Server it does not work. Infact when I copy paste the same command into command prompt it works fine. I double checked everything. I do not understand why its not working. It returns blank output. I have already tried many of the solutions provided before. None works. Any help on this is most appreciated.
Here is the code I am using:
//$sqlsrv is used to determine the database server type
$str_query = voc_get_query_string($query);
$output_uri = 'temporary://' . user_password();
$file_path = drupal_realpath($output_uri . '.csv');
if($sqlsrv){
$exec_path = drupal_realpath('private://Binn\sqlcmd');
}else{
$exec_path = drupal_realpath('private://mysql');
}
$sql_uri = 'temporary://' . user_password();
$sql_path = drupal_realpath($sql_uri);
$fp = fopen($sql_path, 'w');
fputs($fp, $str_query);
fclose($fp);
global $databases;
if ($sqlsrv) {
$cmd = ($exec_path .
' -S ' . $databases['default']['default']['host'] .
' -d ' . $databases['default']['default']['database'] .
' -U ' . $databases['default']['default']['username'] .
' -P ' . $databases['default']['default']['password'] .
' -i ' . $sql_path . '>>'. $file_path .
' -s '. '"," -W -m10 -r1');
}
else {
$cmd = ($exec_path . ' ' . $databases['default']['default']
['database'] .
' -h ' . $databases['default']['default']['host'] .
' -u ' . $databases['default']['default']['username'] .
' -p ' . $databases['default']['default']['password'] . ' < '
. $sql_path .
' > ' . $file_path);
}
exec($cmd);
watchdog('cmd', var_export($cmd, TRUE));
running Laravel 5.2 on Xampp 321 Win7 Mysql5.6 PHP 5.6.3 I cant create BD dump file .sql
$filename = "backup-".Carbon\Carbon::now()->format('Y-m-d_H-i-s').".sql 2>&1";
try{
$command = "mysqldump --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . " > " . storage_path() . "/" . $filename;
$returnVar = NULL;
$output = NULL;
//exec command allows you to run terminal commands from php
exec($command, $output, $returnVar);
//dd($command);
return 1;
}catch(Exception $e){
return $e->errorInfo; //some error
}
When loading script it generates an empty file! But by doing dd ($ command) and copying paste this text, this command works fine in the Xampp shell. Any ideas please?
Solved with this code: setting absolute path of mysqldump adn adding double backslash to url var
$filename = "backup-".date("d-m-Y-H-i-s").".sql";
$mysqlPath = "D:\\xampp/mysql/bin/mysqldump";
try{
$command = "$mysqlPath --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . " > " . storage_path() . "/" . $filename." 2>&1";
$returnVar = NULL;
$output = NULL;
exec($command, $output, $returnVar);
return 1;//ok
}catch(Exception $e){
return "0 ".$e->errorInfo; //some error
}
A video can contain a meta info about the camera orientation. For example iPhone and other phones set this flag if you turn the device. Problem is while some player read this info and rotate the video accordingly, other players do not.
To fix this the video has to be rotated and the meta info needs to be set correctly.
Does ffmpeg provide a fix for this or do I have to go the hard way (Read rotation, rotate, set meta data)
I did go the hard way:
$ffmpeg == "path/to/ffmpeg";
$output_file_full = "file/after/normal/conversion";
// get rotation of the video
ob_start();
passthru($ffmpeg . " -i " . $output_file_full . " 2>&1");
$duration_output = ob_get_contents();
ob_end_clean();
// rotate?
if (preg_match('/rotate *: (.*?)\n/', $duration_output, $matches))
{
$rotation = $matches[1];
if ($rotation == "90")
{
echo shell_exec($ffmpeg . ' -i ' . $output_file_full . ' -metadata:s:v:0 rotate=0 -vf "transpose=1" ' . $output_file_full . ".rot.mp4 2>&1") . "\n";
echo shell_exec("mv $output_file_full.rot.mp4 $output_file_full") . "\n";
}
else if ($rotation == "180")
{
echo shell_exec($ffmpeg . ' -i ' . $output_file_full . ' -metadata:s:v:0 rotate=0 -vf "transpose=1,transpose=1" ' . $output_file_full . ".rot.mp4 2>&1") . "\n";
echo shell_exec("mv $output_file_full.rot.mp4 $output_file_full") . "\n";
}
else if ($rotation == "270")
{
echo shell_exec($ffmpeg . ' -i ' . $output_file_full . ' -metadata:s:v:0 rotate=0 -vf "transpose=2" ' . $output_file_full . ".rot.mp4 2>&1") . "\n";
echo shell_exec("mv $output_file_full.rot.mp4 $output_file_full") . "\n";
}
}
I used some ugly temp files. Sorry about that.
How can I convert FLV to WMV? Is there any script around there or some way I can integrate this?
Thank you!!!
I don't think you can do this directly with PHP.
But, you can use external tools called form PHP (ffmpeg for example).
Here is a code sample:
<?php
$src = "file.flv";
$output = "file.wmv";
ffmpegPath = "/path/to/ffmpeg";
$flvtool2Path = "/path/to/flvtool2";
$ffmpegObj = new ffmpeg_movie($src);
$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
$srcFPS = $ffmpegObj->getFrameRate();
$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
$srcAR = $ffmpegObj->getAudioSampleRate();
exec($ffmpegPath . " -i " . $src . " -ar " . $srcAR . " -ab " . $srcAB . " -vcodec wmv1 -acodec adpcm_ima_wav -s " . $srcWidth . "x" . $srcHeight . " " . $output. " | " . $flvtool2Path . " -U stdin " . $output);
// Make multiples function
function makeMultipleTwo ($value)
{
$sType = gettype($value/2);
if($sType == "integer")
{
return $value;
} else {
return ($value-1);
}
}
?>
Sources:
http://vexxhost.com/blog/2007/05/20/how-to-convertencode-files-to-flv-using-ffmpeg-php/
http://ubuntuforums.org/showpost.php?p=7315615&postcount=10
All solutions you will find are going to use ffmpeg, because that's easy to install on servers and even easier to utilize from PHP scripts. Most always you can just do:
exec("ffmpeg -i video.flv video.wmv");