9

I have scenario for creating a video files using diff. assets like images, audio file.

What I want to do is, Find audio files from the particular folder and set it as background music, and fetch images from particular folder and show those images one by one.

So basically I have images and audio files and I want create a video file using those assets using PHP.

Can any one please suggest the start up point for this? Have done image capture from video and converting the video using Ffmpeg so I have think of Ffmpeg but, I think it will not allow to create a video.

hakre
  • 193,403
  • 52
  • 435
  • 836
Avinash
  • 6,064
  • 15
  • 62
  • 95

4 Answers4

17

ffmpeg will allow you to create videos from still images.

For example, to create a video with a 10fps frame rate, from images 001.jpg .... 999.jpg:

ffmpeg -r 10 -b 1800 -i %03d.jpg test1800.mp4

You can mux streams (audio and video) like (add relevant codec options for bitrate, etc)

ffmpeg -i video.mp4 -i audio.wav -map 1.1 -map 2.1 output.mp4

I'm not going to go into more detail, as ffmpeg is a pain (args change in incompatible ways between versions, and depending on how it was compiled), and finding a rate/compression/resolution setting that is good for you is trial-and-error.

Phil Lello
  • 8,377
  • 2
  • 25
  • 34
  • any other alternate solution for this? – Avinash May 05 '11 at 03:50
  • first command is not creating a video slides, It have created a video file but with only last images it have got from folder. so no video playing because it have only one image to show. :( – Avinash May 10 '11 at 11:59
  • You will need to have the files named as specified above; 001.jpg to 999.jpg – Phil Lello May 12 '11 at 00:02
  • i have already done the file names in that pattern, generating file have only first image in video and track length showing 0 sec. – Avinash May 12 '11 at 12:27
5

Under Ubuntu you need PHP5, ffmpeg and access to ffmpeg binary, this can be easy achieved with:

apt-get install php5 ffmpeg

I'm using this php function to generate an mp4 video from one gif image and one mp3 file, both source image and output video files are 720x576 pixels:

function mix_video($audio_file, $img_file, $video_file) {
    $mix = "ffmpeg -loop_input -i " . $img_file . " -i " . $audio_file . " -vcodec mpeg4 -s 720x576 -b 10k -r 1 -acodec copy -shortest " . $video_file;
    exec($mix);
}

example use:

$audio_file = "/path/to/mp3-file";
$img_file = "/path/to/img-file";
$video_file = "/path/to/video-file";

mix_video($audio_file, $img_file, $video_file);
fab23
  • 59
  • 1
  • 3
  • fmpeg version 2.7.6-0ubuntu0.15.10.1 Copyright (c) 2000-2016 the FFmpeg developers built with gcc 5.2.1 (Ubuntu 5.2.1-22ubuntu2) 20151010 gives output: Unrecognized option 'loop_input'. – Lisitso Feb 19 '16 at 13:12
4

Phil's solution is the correct approach. Work out what needs to be done by documenting yourself on ffmpeg (it's messy, and I can't blame him for not wanting to do your homework), and then call it from within php.

Cursory googling reveals php wrappers (e.g. http://ffmpeg-php.sourceforge.net/). If none are recent/complete enough, stick to issuing the needed shell commands from php.

Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154
3
ImageMagick convert -delay 100 -quality 75 photo1.jpg photo2.jpg movie.mpg

Or

http://dvd-slideshow.sourceforge.net/wiki/Main_Page
Danzan
  • 958
  • 5
  • 8
  • imagemagick creating a video, but is there any option that I can add Transition to the images, like fade in , fade out, etc..... – Avinash May 17 '11 at 07:08