Merge several mp4 video using ffmpeg and php [on hold]
- by rihab
I would like to merge several videos using ffmpeg and php. I want to retrieve the names of the videos dynamically but I can't merge all the videos together I only get i-1 merged videos
This is the code I use:
<?php
$checkBox = $_POST['language'];
$output=rand();
function conv($checkBox){
$tab=array();
for($i=0; $i<sizeof($checkBox); $i++)
{
$intermediate=rand();
$tab[$i]=$intermediate;
exec("C:\\ffmpeg\\bin\\ffmpeg -i C:\\wamp\\www\\video_qnb\\model\\input\\$checkBox[$i].mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts C:\\wamp\\www\\video_qnb\\model\\output\\$intermediate.ts");
}
return $tab;
}
$t=conv($checkBox);
for($i=0;$i<sizeof($t); $i++)
{
if($i!=0)
{
if(sizeof($t)<=2)
{
exec('C:\\ffmpeg\\bin\\ffmpeg -i "concat:C:\\wamp\\www\\video_qnb\\model\\output\\'.$t[$i-1].'.ts|C:\\wamp\\www\\video_qnb\\model\\output\\'.$t[$i].'.ts" -c copy -bsf:a aac_adtstoasc C:\\wamp\\www\\video_qnb\\model\\output\\'.$output.'.mp4');
}
else
{
exec('C:\\ffmpeg\\bin\\ffmpeg -i "concat:C:\\wamp\\www\\video_qnb\\model\\output\\'.$t[$i-1].'.ts|C:\\wamp\\www\\video_qnb\\model\\output\\'.$t[$i].'.ts" -c copy -bsf:a aac_adtstoasc C:\\wamp\\www\\video_qnb\\model\\output\\'.$output.'.mp4');
exec("C:\\ffmpeg\\bin\\ffmpeg -i C:\\wamp\\www\\video_qnb\\model\\output\\".$output.".mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts C:\\wamp\\www\\video_qnb\\model\\output\\i.ts");
exec('C:\\ffmpeg\\bin\\ffmpeg -i "concat:C:\\wamp\\www\\video_qnb\\model\\output\\i.ts|C:\\wamp\\www\\video_qnb\\model\\output\\'.$t[$i+1].'.ts" -c copy -bsf:a aac_adtstoasc C:\\wamp\\www\\video_qnb\\model\\output\\final.mp4');
$i++;
}
}
}
?>
Can anyone help me??