Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Video File using PHP

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.

like image 295
Avinash Avatar asked May 05 '11 03:05

Avinash


People also ask

How to add video in php?

Store video file in a folder and insert file location in a MySQL database table. Display file using <video> element. Before setting max file size for file size validation make sure to check post_max_size and upload_max_filesize in php. ini file and update it accordingly if required.

What is php video format?

A php file cannot be a video file. But a php file can have a video header such that when you call the file, it can give you a video output. This is usually done through a server technique called URL rewriting or a post request from another file and target file understand which file needs to be outputted.

How to fetch video from database in php?

php $query1 = mysql_query("select * from video_title where id='541' and status=1"); while($qry1 = mysql_fetch_array($query1)) { $vid = $qry1['video']; ?>


2 Answers

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.

like image 179
Phil Lello Avatar answered Oct 24 '22 00:10

Phil Lello


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);
like image 41
fab23 Avatar answered Oct 24 '22 00:10

fab23