Skip to content
WJunction - Webmaster Forum

Online Video Converter With ffmpeg (php)

Status
Not open for further replies.
I found this on a forum, well some of you might have seen this. No one shared this so I am doing it now.

PHP:
<?php

function ffmpeg_convert($input_file, $to_format, $output_dir=null)

{
	$input_file = realpath($input_file);
	$output_dir = is_dir($output_dir) ? $output_dir : dirname($input_file);

	$output_file = $output_dir.'/'.pathinfo($input_file, 
PATHINFO_FILENAME).'.'.$to_format;
	
	
$cmd = sprintf('ffmpeg -y -i %s -f %s %s %s > /dev/null 2>&1',
		escapeshellcmd($input_file),
		$to_format,

		(($to_format=='avi'||1)?'-f avi -vcodec mpeg4 -b 175k -g 300 -bf 2 -acodec libmp3lame -ab 32k':''),
		
escapeshellcmd($output_file)
	);
echo $cmd;
	exec($cmd, $output, $status);
	
	$success = empty($status);
	
return $success ? $output_file : false;
}
?>

Put ffmpeg also in the same folder as the script :)
 

2 comments

Status
Not open for further replies.

About the author

F
Senior Member · Joined
Well Maintaining Websites Now! Uploading, Designing, Coding, Learning, Blogging
1,588
Messages
203
Reactions
63
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom