I am using the code bellow to grab an image from a video file and it is working great.
But when i am running the php file that contains the code bellow all system procceses appears, and i mean some infos about the convertion, export etc.
How can i make it run silent?
$stderr = system("ffmpeg -i $videoPath -vframes 1 -an -s 306x173 -ss 03 $finalfilename 2>&1 >/dev/null", $exit_status);
if ($exit_status === 0) {
print 'Done! :)';
} else {
print 'Error... :/';
// $stderr will help you figure out what happened...
}
You should change the order of redirections. Like this:
>/dev/null 2>&1
Or direct everything directly to /dev/null:
>/dev/null 2>/dev/null
You can also use -loglevel quiet as a global option but this will not be helpful if you experience errors.
First of all: sorry! On the other question I made a mistake suggesting you to use system() function, but you clearly need the exec() one.
Furthermore, you might want to suppress any ffmpeg verbose output with -v error to get only error messages on $stderr. You also need to pass -y to avoid getting stuck when $finalfilename already exists. Fixing all together:
exec("ffmpeg -v error -y -i $videoPath -vframes 1 -an -s 306x173 -ss 03 $finalfilename 2>&1 >/dev/null", $stderr, $exit_status);
if ($exit_status === 0) {
print 'Done! :)';
} else {
print 'Error... :/';
// implode("\n", $stderr) will help you figure out what happened...
}
Related
I'm using this code to run ffmpeg and return when it succeeded or failed using 2> & 1 and $var. The problem is that I would also like to generate a log.txt with the current ffmpeg process. I know it does using 2> log.txt but how do I use both options at the same time?
<?php
$ffmpeg = '"D:\FFMPEG\bin\ffmpeg.exe"' . " -loglevel verbose -n -i https://URLVIDEO -map p:0 -acodec copy -bsf:a aac_adtstoasc -vcodec copy video.mp4 2>&1";
exec($ffmpeg, $output, $var);
if($var){
echo 'error';
}else{
echo 'success';
}
?>
Use 1> log.txt 2>&1.
stdout is redirected to the log file and stderr is appended to stdout.
If I understood correctly, you want both streams to be logged. If so, another option is to use &> e.g. cmd &> log.txt.
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;
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