Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

A simple ffmpeg script

18 replies [Last post]

Hello

I need a simple video uploading video and then to convert to flv to be played with the JW player . I search on google but i dont find a simple script ( only huge scripts with admin panel etc )

On the web are only script with uploading videos images etc but not with this function : to convert to flv

Thank you

Thank you .. but i need a functional script .. here is only how to convert to flv . I need this and also a uploader ( so to upload the video and then to convert automaticly )

@Andrew,

I guess you didn't actually read that thread, because it contains a full page including a PHP upload script, some JavaScript and the HTML wrapper. Nobody is going to do your work for you.

I read all the posts but i think is not working the conversion to flv because i converted a wmv file ( about 0.4 MB ) and the output was a flv with 19 MB

It is good the flv ?

Using a recent release of ffmpeg (r14196), this command line converts WMV to FLV:

ffmpeg -i "VideoName.wmv" -sameq -acodec libmp3lame -ar 22050 -ab 96000 -deinterlace -nr 500 -s 320x240 -aspect 4:3 -r 20 -g 500 -me_range 20 -b 270k -f flv -y "VideoName.flv"

-sameq means keep the same quality
-acodec libmp3lame means use the lame MP3 library for the audio codec
-ar 22050 means use an audio sampling rate of 22050Hz
-ab 96000 means use an audio bit rate of 96000bps
-deinterlace means deinterlace the video
-nr 500 means use noise reduction of 500
-s 320x240 means make a video that is 320 pixels wide and 240 pixels high
-aspect 4:3 means maintain an aspect ratio (width:height) of 4:3
-r 20 means maintain a frame rate of 20fps
-g 500 means use a group of pictures of 500 (keyframes every 500 frames or 25 seconds at 20fps)
-me_range 20 means limit motion vectors range to 20
-b 270k means use a video bitrate of 270000bps
-f flv means output into an FLV container file
-y means overwrite if the ouput file already exists

There is a good ffmpeg tutorial here: http://www.dranger.com/ffmpeg/

Please learn to use Google.

Thank you for the link but is not php :)

stumbled across this thread and lol'd. If you take some time out to research ffmpeg and how to use it properly, you will find kLink is on the right track with using ffmpeg. And btw, kLinks code does go into a PHP file... :)

i bid on a job at rentacoder and now i want a prebuilt php file to satisfy the reqs

sorry just my opinion

u r teh suxor

end flame

kLink: It is <b>THE SOLUTION!!!!</b>
THX

Those of you who want this to work in a php file, need a little bit of time with the exec() function:

[?php
return exec($cmd);
?]

http://us.php.net/manual/en/function.exec.php

Or you could go this route:

[?php
return Proc_Close (Proc_Open ($cmd, array(), $foo));
?]

http://us.php.net/manual/en/function.proc-open.php

Oh - and I agree... learn how to use google (and PHP for that matter).

::sad face::

Can you scratch my balls for me?

not able to upload converted file in folder and also image

Hey, it's pretty simple kLink code, is very straight forward.
All you guys need to do is implement the following:

<?php
//taken from my ffmpeg library

function ffmpeg_exec($cmd)
{
$handle = popen($cmd, 'w');
pclose($handle);
}//fn ffmpeg_exec

function convertToFLV($video_src, $v_title, $ext=".flv")
{
//$ext = ".flv";
$ebuild = str_replace(".","",$ext);

if(!eregi("[a-z 0-9 $-_]",$video_src))
{
$vt = strip_invalidChars($v_title,true).$ext;
$arg = "ffmpeg -i ".$video_src." -ar 44100 -y -title ".$v_title." -f ".ebuild." ".$vt;//-s 320x240
$exec = ffmpeg_exec($arg);
if(file_exists($vt)){return 0;}
else{return 1;}
}//main if
else{return 0;}
}//fn convertToFLV

?>

This code works fine for me, however it's not the latest ffmpeg.exe. So you can substitute, the actual conversion line with kLink own.

Secondly, video upload is the same as an image upload [since its files you're dealing with].
Just make sure, within your php.ini file, you tweak the values-> max_execution_time, max_input_time, post_max_size, and upload_max_filesize.

Note: You can set these values within your .htaccess file(if on apache server) like this: php_value upload_max_filesize 330M

Cheers

Forgot to give you another fn,

<?php

function strip_invalidChars($i,$space=false)
{

$invalid = "_-+=)(*&^%$#@!~`'\":;{}][.,></?\|";
$cache = array();
$empty = array();

($space==true)?$i=str_replace(' ','',$i):'';

for($x=0; $x<strlen($invalid); $x++)
{
$c = substr($invalid,$x,1);
array_push($cache,$c);
array_push($empty,"");
}//loop

$trans = array_combine($cache,$empty);
$new_str = strtr($i,$trans);
return $new_str;
}//fn strip_invalidChars

?>

This is necessary, because a video name like this: test video.mov, will crash the script. Since the ffmpeg verson I'm using checks the space as an argument supplier, and evaluates the expression to the right as an argument.

ghkgghhkghkgkgkgkgkgk

You guys charging this dhead wanting you to wipe his a$$? I mean sheez... what a tool. Anyone with more than 30 mins of programming experience can write a PHP exec() function to call FFMPEG and do its schizzle... If not, you are a low-life, bottom feeding begging outsourcing a$$hole who needs to be spoonfed dogmeat. Ne1 who hires one of these bottomfeeders off rentacoder.com has only themselves to blame.

Nuff said.

also you don't need to write a sh1tload of PHP to handle space removal... Just a quick Bash script will do that, and just call the bash script with PHP exec(). You guys do it the hard way, huh.... This is really elementary stuff and I think you should all look in the mirror. You are so far from l33t that you should be embarrassed. Or maybe you are from some 3rd world country that hasn't invented books yet....

well i am working with a bottom feeder and need one of you to save my butt...who can actually make me a software script and website that works...paying for who ever knows what they are talking about..