"", "width" => ""); @return: (String) $execution_instrution @description: prepare the right video aspect for the ffmpeg encoding */ function build_ffmpeg_aspect_exec($aspect){ $exec =''; $exec .= ' -s '.$aspect["output"]["width"].'x'.$aspect["output"]["height"]; $exec .=' -aspect '.$aspect["output"]["ratio"]; if(isset($aspect["output"]["pad"])){ $exec .=' -padtop '.$aspect["output"]["pad"]["top"]; $exec .=' -padbottom '.$aspect["output"]["pad"]["bottom"]; $exec .=' -padcolor 000000'; } if(isset($aspect["output"]["crop"])){ $exec .=' -croptop '.$aspect["output"]["crop"]["top"]; $exec .=' -cropbottom '.$aspect["output"]["crop"]["bottom"]; } return $exec; } /* @param $input_file @return: (array) $file @description: try to get the most information about the given multimedia file by asking ffmpeg to write it in an array */ function ffmpegGetInputFileInformation($input_file){ exec(ffmpeg_binary.' -i '.$input_file.' 2>&1 | grep "Duration"',$file_information); $file_information_split = split(',', $file_information[0]); $file_duration = split('Duration: ', $file_information_split[0]); $file["duration"] = verifyColonTime(trim($file_duration[1])); $file_bitrate_split = split(',', $file_information_split[2]); $file_bitrate = split('bitrate: ', $file_information[0]); #$file["bitrate"] = trim($file_bitrate[1]); if(eregi('kb/s', trim($file_bitrate[1]))) $file["bitrate"] = (int) trim(array_shift(split('kb/s', $file_bitrate[1]))); $file["estimated_filesize"] = ($file["duration"]["total_lenght"] / ($file["bitrate"]/1024)); $file["estimated_filesize_hr"] = formatBytes($file["estimated_filesize"]); return $file; } /* @param $input_file @return: (array) $video @description: try to get the most video settings information about the given multimedia file by asking ffmpeg to write it in an array */ function ffmpegGetInputFileVideoInformation($input_file){ //here we are throwing the input file to ffmpeg and grep an array out of the ffmpeg information result exec(ffmpeg_binary.' -i '.$input_file.' 2>&1 | grep "Video" | awk -F"Video: " "{ print $2 }"',$video_information); $video_information_split = split(',', $video_information[0]); $codec_split = split('Video: ',$video_information_split[0]); $video["codec"] = trim($codec_split[1]); $video["colorspace"] = trim($video_information_split[1]); //figure out the resolution preg_match('/[1-9][0-9]+x[1-9][0-9]+/', trim($video_information_split[2]), $video_resolution, PREG_OFFSET_CAPTURE); $video["resolution"] = $video_resolution[0][0]; //split up the resolution in width and height $video_resolution_split = split('x',$video["resolution"]); $video["width"] = $video_resolution_split[0]; $video["height"] = $video_resolution_split[1]; //get additional information if(eregi('tbr', $video_information_split[3])) $video["tbr"] = trim(array_shift(split('tbr',$video_information_split[3]))); if(eregi('tbn', $video_information_split[4])) $video["tbn"] = trim(array_shift(split('tbn',$video_information_split[4]))); if(eregi('tbc', $video_information_split[5])) $video["tbc"] = trim(array_shift(split('tbc',$video_information_split[5]))); return $video; } /* @param $input_file @return: (array) $audio @description: try to get the most audio settings information about the given multimedia file by asking ffmpeg to write it in an array */ function ffmpegGetAudioSettings($input_file){ echo 'getAudioSettings'; //here we are throwing the input file to ffmpeg and grep an array out of the ffmpeg information result exec(ffmpeg_binary.' -i '.$input_file.' 2>&1 | grep "Audio" | awk -F"Audio: " "{ print $2 }"', $audio_information); $audio_settings = split(', ',$audio_information[0]); $codec_split = split('Audio: ',$audio_settings[0]); $ffmpeg["settings"]["audio"]["codec"] = trim($codec_split[1]); //Channels $audio_settings[2]; if(eregi('mono', $audio_settings[2])) $ffmpeg["settings"]["audio"]["channels"]=1; if(eregi('stereo|2 channels', $audio_settings[2])) $ffmpeg["settings"]["audio"]["channels"]=2; if(eregi('ac3|aac|5.1', $audio_settings[2])) $ffmpeg["settings"]["audio"]["channels"]=6; $ffmpeg["settings"]["audio"]["channelformat"]=$audio_settings[2]; if(strlen($audio_settings[4]>2)) $ffmpeg["settings"]["audio"]["bitrate"]=$audio_settings[4]; eregi('[0-9]+', $audio_settings[1], $match); $ffmpeg["settings"]["audio"]["samplingrate"] = $match[0]; return $ffmpeg["settings"]["audio"]; } ?>