I'm using ffmpeg to generate snapshot from an existing file, the command line is:
ffmpeg -ss 0:00 -f image2 -r 0.2 -s 640*480 test_%d.jpg -i media.flv
After exec the command line above the process start and will generate snapshot pics every 5 seconds, name start from test_1.jpg(test_1.jpg, test_2.jpg, test_3.jpg, etc).
But now I want the generated names start from test_0.jpg, and the step is 5(that is: test_0.jpg, test_5.jpg, test_10.jpg, etc)
Can anyone help me what should I do? (I'm using PHP). Thanks.
Cache your last number by saving it in the database or you using local file to write the last number reached in your exec and when you retrieving it back increase it by 5
//get your var from your database or from your cache file if it was empty leave it 0
$mycachednum = 0;
exec("ffmpeg -ss 0:00 -f image2 -r 0.2 -s 640*480 test_$mycachednum.jpg -i media.flv");
//save it
$mycachednum = $mycachednum + 5;
Related
I'm using a shared server managed by Aruba.it
It uses
ffmpeg version 4.1
built with gcc 4.8.5
(GCC) 20150623
(Red Hat 4.8.5-36)
I need to use ffmpeg to fix the loudness of any uploaded MP3 to -12 dB LUFS -1 dB TP
I found on internet the following commands, but not any output.mp3 is generated
PHP
exec("/usr/bin/ffmpeg -i Temp.mp3 -af loudnorm=I=-12:LRA=7:tp=-2:measured_I=-30:measured_LRA=1.1:measured_tp=-11 04:measured_thresh=-40.21:offset=-0.47 -y output.mp3");
Where do I wrong please?
EDIT
Not any error is returned.
If you run it manually, unscripted in your terminal you will get an error:
Unable to find a suitable output format for '04:measured_thresh=-40.21:offset=-0.47'
04:measured_thresh=-40.21:offset=-0.47: Invalid argument
There is an errant space in your command, so change measured_tp=-11 04 to measured_tp=-11.04.
Based on the suggestion by #llogan I found the solution.
It should be in 3 steps and not in only one.
The MP3 to MP3 doesn't work, on my case.
So I converted the input MP3 into wave, normalized it, and converted back to MP3
exec("/usr/bin/ffmpeg -i Temp.mp3 Temp.wav");
exec("/usr/bin/ffmpeg -i Temp.wav -af loudnorm=I=-12:LRA=7:tp=-2:measured_I=-30:measured_LRA=1.1:measured_tp=-11.04:measured_thresh=-40.21:offset=-0.47 output.wav");
exec("/usr/bin/ffmpeg -i output.wav -ab 320k output.mp3");
this solution worked perfectly
With shell_exe or exec use:
$output = shell_exec('/usr/bin/ffmpeg -i Temp.mp3 -af loudnorm=I=-12:LRA=7:tp=-2:measured_I=-30:measured_LRA=1.1:measured_tp=-11 04:measured_thresh=-40.21:offset=-0.47 -y output.mp 2>&1');
2 refers to the second file descriptor of the process, i.e. stderr.
> means redirection.
&1 means the target of the redirection should be the same location as the first file descriptor, i.e. stdout.
In $output you will have the response. If the apache user www-data doesn't have enough rights execute the comand as sudo
and am wanting to use ffmpeg as command line direct on windows 7 x64, I tried adding the extension, but unfortunately it did not work for some unknown reason, but the executable worked perfectly, I'm using the exec command, the only problem is that does not work with direct lines, I have to create a file. bat to run the program. this is my doubt.
$a = exec('\b.bat');
if ($a)
{
echo "Success"."\n";
print $a;
}else {
echo "No good"."\n";
print $a;
}
b.bat
ffmpeg -i video.flv -an -ss 00:00:16 -an -r 1 -vframes 1 -y %a.jpg
already tried several alternatives but the only one that worked was with the. bat
$a = exec('\windows/system32/ffmpeg.exe ffmpeg -i video.flv -an -ss 00:00:16 -an -r 1 -vframes 1 -y %a.jpg');
Make sure you include the full path to your .bat file and also make sure to include the full path to ffmpeg.exe in your .bat file.
Well, I am also working on this ffmpeg file to convert my movies and stuff my idea is for people to watch movies for free anyway here is what I use to convert my movies, have a note that when the ffmpeg.exe is not in the same folder than the movies then you will need to give a full path or use of ../ to go up a folder and / to a folder for example:
$input_path= $_FILES["file"]["tmp_name"];
$output_result= "movies/" . basename($_FILES["file"]["name"]).".flv";
exec("FFMPEG.EXE -i '$input_path' -s 900x400 -r 29.97 -b 1024k -ar 22050 -ab 50k -ac 1 '$output_result'");
there I am using scale and rateframe as well as bitrate and sound quality so my input and output I gave them in a variable basically that command you can use as is just give a value to those variables $input and $output. Please note that I am barely working out the idea too so far this is what I have come out with please do not expect excellent results since we are using microsoft windows the results may vary from version to version and you may have to use the command in administrator mode I hope this helps you my email is support#web2021.com if anything let me know man.
I need to manage the recording/capture of a website mindwhile it is running a slide-show to get videos form these slides.
My approach is:
<?php
define('FFMPEG_LIBRARY', '/usr/bin/ffmpeg ');
$ffmpegcmd = "ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/output.mpg";
shell_exec($ffmpegcmd);
?>
But i get this error from php error log:
[x11grab # 0x81e8aa0] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 800 height: 600
No protocol specified
No protocol specified
[x11grab # 0x81e8aa0] Could not open X display.
:0.0: Input/output error
Similar command from console run good.
Please, any help to get display and be able to control ffmpeg from browser php script?
Thanks in advance.
thanks for your time.
I got rid the X display error, but not I still haven't got the capture.
Using xvfb I get an unknown file at /tmp written by www-data user:
-rw-r--r-- 1 www-data www-data 11252 Sep 12 09:49 server-B20D7FC79C7F597315E3E501AEF10E0D866E8E92.xkm
Running startx I got also an unknown file at /tmp
-rw------- 1 www-data www-data 59 Sep 12 09:53 serverauth.oLcFlG7tXC
any of both grow in size so it is not capturing anything. The content is some binary thing.
What are those files about?
What I am trying is to write a script in which I can control the time ffmpeg is capturing the desktop to create a video from a jquery slide displayed on a website.
My try from console is closer, but if I can do it by browser I will be able to know when to stop sending an AJAX request once the slide is finished.
This is my try from console:
#!/bin/bash
# start the slide website: I will need to change it to control by querystring the language and course level
firefox http://www.languagecourse.net/vocabulary-trainer.php &
# start recording: I will need to adjust the frame to capture
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/output2.mpg &
# since I can't control the time a course takes I pause an arbitrary time
sleep 5
# look for the capture PID and close it
for i in $(ps aux | grep ffmpeg | sed "s/ */#/g" | cut -f2 -d#)
do
echo "proceso $i killed"
kill -9 $i
done
I wonder once the website is opened I can continue doing the control from AJAX, but not know if I will be able to get the ffmpeg PID to stop the command.
I will appreciate any kind of comments.
Regards,
·_-
You can use Xvfb to emulate a x-environment
<?php
$ffmpegcmd = "xvfb-run -a ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/output.mpg";
shell_exec($ffmpegcmd);
or something like this
<?php
$ffmpegcmd = "startx -- `which Xvfb` :1 -screen 0 800x600x24 && DISPLAY=:1 && ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/output.mpg");
shell_exec($ffmpegcmd);
That should be good to get rid of the "Could not open X display." error, and will probably solve your problem.
I am using FFMpeg to covert videos and it is working fine from the command line. I am using the following command:
ffmpeg -i input.mpg -vcodec libx264 -b 819200 -s 100x100 -g 15 -bf 3 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -flags +loop -cmp +chroma -me_range 16 -me_method hex -subq 5 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 1 -flags2 +fastpskip -dts_delta_threshold 1 -acodec libfaac -ab 48000 output.m4v
However, when I run the command using PHP exec(), the output video is not encoded correctly and is distorted and cropped. I am using the following in PHP:
$output = exec($cmd . ' 2>&1', $output, $return);
The $output returns a '0' successful code.
Does any one have any suggestions?
Thank you.
This is unusual. It is possible that you have more than one ffmpeg binary installed, and the one that is being called by the PHP/Apache user is not the same as the one you call as your user from the command line.
Try specifying the full path to your ffmpeg binary (/usr/bin/ffmpeg or whatever) inside your exec().
It sounds like some command line options are getting lost/altered. I would try to split this into a 2 part process:
write a shell script on-the-fly (from PHP) that has all the proper command arguments (make it executable)
execute the shell script (from PHP)
I would probably try:
1) change ' 2>&1' to ' 2>&1 &'
Also, transcoding can take a while. Are you certain you are waiting long enough for the transcode to complete?
hi i want to include the vedio download option in my webpage. I am using ffmpeg, but it seems to work very slow. Is there is any other way to do this or how to spead up the ffmpeg.
i am using this code to get the frames from the vedio.
to convert the vedio
$call="ffmpeg -i ".$_SESSION['video_to_convert']." -vcodec libvpx -r 30 -b ".$quality." -acodec libvorbis -ab 128000 -ar ".$audio." -ac 2 -s ".$size." ".$converted_vids.$name.".".$type." -y 2> log/".$name.".txt";
$convert = (popen("start /b ".$call, "r"));
pclose($convert);
to get the frame from the vedio
exec("ffmpeg -vframes 1 -ss ".$time_in_seconds." -i $converted_vids video_images.jpg -y 2>);
but this code does not generate any error its loading continously.
Cache or pre-generate the output format.
Use the ffmpeg-php library. Should boost up some processes rather then manually calling the ffmpeg command line tool using exec.
I'd first of all take PHP out of the equasion and time how long it takes to do what you're after via the command line.
Once you're happy that works the way you'd like it to, make sure you've tweaked your script's execution time (see http://php.net/manual/en/function.set-time-limit.php) to accomodate what's likely to take a while.
Consider an async approach if it's getting in the way of UX.
Ta