Go
Not registered? Sign up!

A simple ffmpeg script

Google Translate
16 posts | return to the Modules forum | get the rss feed for this thread

Aug. 06, 2008Andrew

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

Aug. 06, 2008kLink

Look here: http://jeroenwijering.com/?thread=3495

Aug. 07, 2008Andrew

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 )

Aug. 07, 2008kLink

@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.

Aug. 07, 2008Andrew

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 ?

Aug. 07, 2008kLink

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.

Aug. 08, 2008Andrew

Thank you for the link but is not php wink

Aug. 25, 2008lol

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... wink

Oct. 11, 2008suck at life

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

Nov. 09, 2008clauZ

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

Dec. 22, 2008zeroasterisk

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).

Jan. 22, 2009sadTiger

::sad face::

Can you scratch my balls for me?

Feb. 19, 2009hi

not able to upload converted file in folder and also image

Jul. 28, 2009Skovoski

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

Jul. 28, 2009Skovoski

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.

Aug. 29, 2009gkgtkk

ghkgghhkghkgkgkgkgkgk

Add a reaction

You can also return to the category or try this search for related threads.


 

Search the Forums

Go

Support

Support Here are some helpful links to learn more about the JW Player™:

Monetize Your Video

Monetize Your Video Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!

Why Buy a License?

Why Buy a License? If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS. Our licenses are very inexpensive, so what are you waiting for? Buy a license today.