Currently i am making 2 videos with this command:
ffmpeg -loop 1 -r 25 -t 5 -i /home/psafari/public_html/youtube_images/movie_" . $id . ".jpg -q:v 1 -an /home/psafari/public_html/youtube_videos/".$movie1."
ffmpeg -loop 1 -r 25 -t ".$t." -i /home/psafari/public_html/yy.jpg -q:v 1 -an /home/psafari/public_html/youtube_videos/".$movie2."
And it also works, but when i will make 2 videos into 1, it only shows 5 seconds of the first video (like the other doesn't comvert also).
mencoder -ovc copy -o /home/psafari/public_html/final_".time().".avi /home/psafari/public_html/youtube_videos/".$movie1." /home/psafari/public_html/youtube_videos/".$movie2
Am i doing something wrong?
Related
FFmpeg version 0.6.5 is installed on my web server.
In my website mp4 videos allowed to upload, that part is done.
Now i am working on create a thumbnail of the video and then resize it.
The following links are I referred.
https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg
This is the command i used to create a thumbnail from video, this command is working.
$cmd = "ffmpeg -i test.mp4 -ss 0 -vframes 1 out.png";
After creating the thumbnail, I tried the following the command to resize it, but this is not working.
$cmd = 'ffmpeg -i out.png -vf scale=210:-1 output_320x240.png';
And Some other commands i have tried
$cmd = "ffmpeg -ss 10 -i test.mp4 -vframes 1 -filter scale=-1:150,crop=200:150 output.jpg";
$cmd = "ffmpeg -itsoffset -1 -i test.mp4 -vframes 1 -filter:v scale=280:-1 output.jpg";
In my localhost I used the following command to create thumbnail and resize in a single command, but this is also not working in the server.
$ffmpeg = 'C:\\ffmpeg\\bin\\ffmpeg';
$video = 'test.mp4';
$cmd = "$ffmpeg -itsoffset -1 -i $video -vframes 1 -filter:v scale=\"210:-1\" thumbnail.png";
Thanks to all
This is my ffmpeg process:
exec("/usr/local/bin/ffmpeg -y -i source.avi dest.mp4 >/dev/null 2>/dev/null &
Now, I wish to execute a PHP file after the conversion is complete. Logically, this is what I have:
exec("/usr/local/bin/ffmpeg -y -i source.avi dest.mp4 >/dev/null 2>/dev/null ; php proceed.php &
This doesn't work though, since then PHP will hold up the process to wait till the ffmpeg conversion is complete. What I want is basically to call proceed.php after the conversion completes, both of which are done in the background.
If anyone can provide the Windows server solution, that will be awesome too.
Write an external (bash/php) script that executes both the ffmpeg and php process, and tack & after that.
For windows, please open a new question on SO.
To add on to what Evert had posted, here is an example of what I use for my FFMPEG bash script... it's far from done (it doesn't alert if the program crashes, for instance) but it's somewhere to start:
#!/bin/sh
## Set our paths
FFMPEG_PATH=/usr/local/bin
SITE_PATH=path_to_file
VIDEO_PATH=$SITE_PATH/public_html/videos
## Make sure we have permissions to do this stuff
chown -R wwwrun:www $VIDEO_PATH/$2
chmod -R 765 $VIDEO_PATH/$2
## Set the options for mp4 compression
options="-vcodec libx264 -b 512k -ar 22050 -flags +loop+mv4 -cmp 256 \
-partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
-me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \
-flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \
-g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10\
-qmax 51 -qdiff 4"
## Start the conversion.
$FFMPEG_PATH/ffmpeg -y -i $VIDEO_PATH/$2/original/$1 -an -pass 1 -threads 2 $options $VIDEO_PATH/$2/$2.mp4 2> $VIDEO_PATH/$2/pass_one.log
$FFMPEG_PATH/ffmpeg -y -i $VIDEO_PATH/$2/original/$1 -acodec libfaac -ab 96k -pass 2 -threads 2 $options $VIDEO_PATH/$2/$2.mp4 2> $VIDEO_PATH/$2/pass_two.log
## Create the thumbnail for the video
. $SITE_PATH/bin/create_thumbnail $2 00:00:15 2> $VIDEO_PATH/$2/generate_thumbnails.log
## Clean up the log files that were created
## find /log_path/ -name *log* -exec rm {} \;
## Update datbase and send email that we're done here.
php $SITE_PATH/public_html/admin/includes/video_status.php converting_finished $2
And this all gets called from a PHP file that does (along with some other code):
proc_close(proc_open(server_path.'/bin/convert_video_mp4 '.mysql_result($next_video, 0, "uid").'.'.mysql_result($next_video, 0, "original_ext").' '.mysql_result($next_video, 0, "uid").' &', array(), $foo));
PS - I know mysql extension are on their way out, I haven't been using or updating this code in a while, so please update to your specifications
So this command works for generating a thumbnail 5 seconds into the video, with a size of 300x300:
$cmd = '/usr/local/bin/ffmpeg -i '.$this->getUploadRootDir().'/'.$fname.' -ss 00:00:05 -f image2 -vframes 1 -s 300x300 '.$this->getUploadRootDir().'/thumb_'.$output;
However, I want to keep the aspect ratio so I changed my code to this:
$cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -ss 00:00:5 -f image2 scale='min(300\, iw):-1' ".$this->getUploadRootDir()."/thumb_".$output;
The above code correctly sizes the image, however it's of the first frame in the video.. I need the thumbnail to be 5 seconds in. Any help would be much appreciated.
You can do that with a command line similar to:
ffmpeg -i inputVideo -vf scale='min(300,iw)':-1 -ss 00:00:05 -f image2 -vframes 1 thumbnail.jpg
So in your script, add -vf (video filter) before scale and reorder input and output parameters like below:
$cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -vf scale='min(300\, iw):-1' -ss 00:00:5 -f image2 -vframes 1 ".$this->getUploadRootDir()."/thumb_".$output;
#alexbuisson has the correct answer, but just to confirm as I'm playing with ffmpeg today:
This works for me:
ffmpeg -i "my_video.mp4" -ss 00:00:05 -f image2 -vf scale="min(300\, iw):-1" -vframes 1 "capture.jpg"
I get one Jpeg 300 px wide with the correct image ratio.
So adapted to your code this becomes:
$cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -ss 00:00:05 -f image2 -vf scale='min(300\, iw):-1' ".$this->getUploadRootDir()."/thumb_".$output;
I am trying to create videos from images sequence. I tried all the below code given in $ff_command variable.
$path = dirname(__FILE__);
$ff_command = "ffmpeg -f image2 -i {$path}/img%03d.jpg video.mpg";
$ff_command = "ffmpeg -r 10 -b 1800 -i {$path}/img%03d.jpg test1800.mpg";
$ff_command = "ffmpeg -i {$path}/img%03d.jpg -s 1280x720 -aspect 16:9 -r 24 -vb 20M teste.mp4";
$ff_command = "ffmpeg -f image2 -i {$path}/img%03d.jpg -vcodec mpeg4 -b 800k video.avi";
$ff_command = "ffmpeg -f image2 -i {$path}/img%03d.jpg -vcodec libx264 -b 800k video.avi";
Most of these commands are creating a video file. But when I open that video nothing comes or first image is coming for a split second and nothing after that
Please let me know what I am doing wrong here
I noticed that video is too short to see. Is it possible to increase the video duration so that we can see all the images?
How to take pictures of the video through mplayer or ffmpeg to php?
try,
exec("ffmpeg -i $video_file_path -an
-y -f mjpeg -ss 00:02:00 -vframes 1 $image_path")
Assuming ffmpeg is installed on your server, you can use the following code to output the frame at exactly 2 minutes to a JPEG file:
function vidtojpeg($video_filename, $dimensions) {
exec("ffmpeg -i $video_filename -an -ss 00:01:59 -t 00:00:01 -r 1 -y -s $dimensions video%d.jpg");
}
In this function, the $video_filename parameter is self-explanatory. The $dimensions parameter accepts width and height of the outputted images in this format: WIDTHxHEIGHT. For example: 320x480 would be an acceptable parameter.
Converting the video to frames and getting the required frames based on timings can help. Try this : ffmpeg -i video.flv -r 25 -vcodec png -pix_fmt rgb32 %d.png
You can manipulate the formats and bitrate(-r) for getting the required frame in proper format.