1. First download latest version of ‘ffmpeg’ from their website.

2. Then upload that folder of ffmpeg in your current wordpress theme, althogh you can put anywhere you want but make sure you have to give proper path to that folder.

3. Access that folder by giving path to theme using ‘get_stylesheet_directory()’ function if uploaded in wordpress current theme.

4. code snippet to create thumbnail of video while uploading a video file.

 

if(isset($_FILES['file']) && !empty($_FILES['file']))
{
	$uuid = $wpdb->get_var("SELECT uuid( )");		
	$upload_dir = wp_upload_dir();
	$mediapath =  $upload_dir['basedir'].'/usermedia/video/';
	$fileName = time().'_'.$_FILES['file']['name'];	
	$videoFile = $_FILES['file']['tmp_name'];			
	$fileTmpLoc = $_FILES['file']['tmp_name'];			
	$fileloc = $mediapath.$fileName;
	move_uploaded_file($videoFile, $mediapath.$fileName);	
	$path = get_stylesheet_directory();
	$ffmpeg = $path."\\ffmpeg\\bin\\ffmpeg";	
	$fileSize = 2;//$_FILES["file"]["size"];
	$jk = $upload_dir['basedir'].'/usermedia/video/thumb/' . $uuid . '.jpg';
	$file = current(explode(".", $fileName));
	$size = "120*90";
	$getFromSecond = 1;	
	$cmd = "$ffmpeg -i $fileloc -an -ss $getFromSecond -s $size $jk";
	shell_exec($cmd);	
	echo "uploaded";
}

Leave a Reply