开发者

How to create dynamic video/slideshow from pictures in PHP

I have a dynamic archive (a folder on my ftp space) where are loaded images from webcam. Now i want to create an easy slideshow or video with these images each time the user want to watch it. No any transition options or othe开发者_开发百科rs....i need to build a siple timelapse from images captured by camera.

i've just try this http://www.maani.us/xml_slideshow/ it works fine (i can build with php a dynamic xml configuration file for the swf script) but i can't set the time transition less than 1 second...and is not free...

Any simple solution? (also javascript if it is better...) Thanx!


If you want the end result to be a video file you could do something similar to what I did when turning a series of Google Streetview panoramas into an immersive time-lapse video.

It's all done on the server using PHP & ffmpeg. Here's some sample code pared down from the original source.

ffmpeg command:

$makeMovieFfmpeg = "ffmpeg -r 4 -f image2 -i dir/%d.jpg -s 800x600 -r 15 -s 800x600 -b 1500kbs myvideo.avi 2>&1";

Explanation:

-r 4 //input framerate of 4fps
-f image2 //invoke the image2 file demuxer since we're working with a series of images
-i //location of image files with applied pattern where %d represents numeric sequence
-s //input image size
-r //output framerate of 15fps
-s //output video size
-b //set the bitrate
2>&1 //redirects stderr to stdout in order to make output available to PHP

Execute command:

print_r (exec($makeMovieFfmpeg,$ret,$err));


I think You can create GIF sequence like one in here:

http://www.dreamincode.net/forums/topic/53942-create-gif-images-using-gd/


PHP is a merely string manipulation language

You cannot create a slideshow in PHP. It's server-side language.


That's the best way i found: simple and speedy

<HTML>
<HEAD>
<TITLE>Video</TITLE>
</HEAD>
<BODY  BGCOLOR="#000000">
<img name="foto">
<SCRIPT LANGUAGE="JavaScript">
var Pic = new Array();

Pic[0] = '/images/image1.jpg'
Pic[1] = '/images/image2.jpg'
Pic[2] = '/images/image3.jpg'
//this part in real code is replaced with a PHP script that print image location dinamically

var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
//all images are loaded on client
index = 0;
function update(){
if (preLoad[index]!= null){
document.images['foto'].src = preLoad[index].src;
index++;
setTimeout(update, 1000);
}

}
update();

</script>

</BODY>
</HTML>


Ffmpeg is your best solution. https://www.ffmpeg.org/download.html

Fast way to create slideshow from image is running below command

ffmpeg -framerate 20 \
-loop 1 -t 0.5 -i 1.jpg \
-loop 1 -t 0.5 -i 2.jpg \
-loop 1 -t 0.5 -i 3.jpg \
-loop 1 -t 0.5 -i 4.jpg \
-c:v libx264 \
-filter_complex " \
[1:v][0:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b1v]; \
[2:v][1:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b2v]; \
[3:v][2:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b3v]; \
[0:v][b1v][1:v][b2v][2:v][b3v][3:v]concat=n=7:v=1:a=0,format=yuv420p[v]" -map "[v]" out.mp4

it will create a slideshow with blend effect.

You can check below memo for other effect https://github.com/letungit90/ffmpeg_memo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜