Tuesday 12th June 2007
by Sajith M.R![]()
Install ffmpeg library in your server first.
Place a video file of any type on current directory (or anywhere), here it is clock.avi .
Click more for source code:
extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
$ffmpegInstance = new ffmpeg_movie('clock.avi');
echo "getDuration: " . $ffmpegInstance->getDuration() .
"getFrameCount: " . $ffmpegInstance->getFrameCount() .
"getFrameRate: " . $ffmpegInstance->getFrameRate() .
"getFilename: " . $ffmpegInstance->getFilename() .
"getComment: " . $ffmpegInstance->getComment() .
"getTitle: " . $ffmpegInstance->getTitle() .
"getAuthor: " . $ffmpegInstance->getAuthor() .
"getCopyright: " . $ffmpegInstance->getCopyright() .
"getArtist: " . $ffmpegInstance->getArtist() .
"getGenre: " . $ffmpegInstance->getGenre() .
"getTrackNumber: " . $ffmpegInstance->getTrackNumber() .
"getYear: " . $ffmpegInstance->getYear() .
"getFrameHeight: " . $ffmpegInstance->getFrameHeight() .
"getFrameWidth: " . $ffmpegInstance->getFrameWidth() .
"getPixelFormat: " . $ffmpegInstance->getPixelFormat() .
"getBitRate: " . $ffmpegInstance->getBitRate() .
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate() .
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate() .
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate() .
"getVideoCodec: " . $ffmpegInstance->getVideoCodec() .
"getAudioCodec: " . $ffmpegInstance->getAudioCodec() .
"getAudioChannels: " . $ffmpegInstance->getAudioChannels() .
"hasAudio: " . $ffmpegInstance->hasAudio();
//___________________________________Code end here_____________________________________
I also can be used for file format conversion
Eg: exec(‘ffmpeg -i ‘.$SourcePath.’ ‘.$Destination);
Here $SourcePath any file of any format , and destionation also another format.
eg: exec(‘ffmpeg -i saji.3gp saji.flv’);
Tags: featured, ffmpeg, sample, source code
extension_loaded(‘ffmpeg’) or die(‘error in loading ffmpeg’);
if(exec(‘ffmpeg -i saman600.flv saman6001.avi’))
echo”success”;
else
echo”fail”;
output : fail
output : fail
Is there a problem with exec().
I have checked the phpinfo(); and ffmpeg turn on
I use ubuntu 10.04. Please help.
I downloaded ffmpeg.exe from some site.. i placed that exe file in server. after that i executed above code..Then i got an error msg like this
“Error in loading ffmpeg..
what sholud i do?
[...] ffmpeg sample code | Programming Ideas, Logics, Tips and Tricks – [...]
i’m installing ffmpeg and did this code
c:/ffmpeg/ffmpeg.exe –i d:/myfile.mpg d:/myfile.flv /y
on the DOS and then came this error
unable to find a suitable output format for ‘ui’
how can i solve this?
i’m using windows xp by the way.
thanks.
Hello!
I want to resize jpeg image. Already resized but problem is image quality not good. i.e. Original image size is 640*480. After resize 200* auto. Resize image not looking same as original image. Anybody give an idea..
Hi folk,
Currently I come to work with FFMPEG to convert video stream into flv in php. Can anyone give how could i do this using php? Does anybody has class or source code for that?
A little help appreciate…
Web-Farmer
http://www,letsnurture.com
i want to run ffmpeg in my system but its not run properly
and error msg are comming
“Error in loading ffmpeg”
pls help me
Hi Sajith,
New to use this FFmpeg. and to linux also.
I installed ffmpeg and trying to use the Library of the ffmpeg.
#include “libavcodec/avcodec.h”
#include “libavformat/avformat.h”
I am using simple sample code ,which takes vedio stream ,and convert it to someformat.
I am facing problem is when i wrote the C Code .
I complied it which is not the problem,but linking is getting problem.
It is giving like this
test.c:(.text+0xf6): undefined reference to `av_register_all’
test.c:(.text+0x12b): undefined reference to `av_open_input_file’
test.c:(.text+0×146): undefined reference to `av_find_stream_info’
test.c:(.text+0×183): undefined reference to `dump_format’
test.c:(.text+0x1f6): undefined reference to `avcodec_find_decoder’
test.c:(.text+0×242): undefined reference to `avcodec_open’
test.c:(.text+0×257): undefined reference to `avcodec_alloc_frame’
test.c:(.text+0x25f): undefined reference to `avcodec_alloc_frame’
test.c:(.text+0×294): undefined reference to `avpicture_get_………
Means it is unable to link with the contents of the header files ..
Please do guide me ..what is the worng thing i am doing.
Hello Expert,
I am trying to convert into .flv file from other format.
i am using this command
$srcFile = “/home/amitadut/public_html/gallery_video/robot.avi”;
$destFile = “/home/amitadut/public_html/gallery_video/robot.flv”;
$ffmpegPath = “/usr/local/bin/ffmpeg”;
$flvtool2Path = “/usr/local/bin/flvtool2″;
// Create our FFMPEG-PHP class
$ffmpegObj = new ffmpeg_movie($srcFile);
// Save our needed variables
$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
$srcFPS = $ffmpegObj->getFrameRate();
$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
$srcAR = $ffmpegObj->getAudioSampleRate();
// Call our convert using exec()
exec($ffmpegPath . ” -i ” . $srcFile . ” -ar ” . $srcAR . ” -ab ” . $srcAB . ” -f flv -s ” . $srcWidth . “x” . $srcHeight . ” ” . $destFile . ” | ” . $flvtool2Path . ” -U stdin ” . $destFile);
But file is creating with 0 kb filesize.
can you tell me why 0 kb is creating??????????/
i have also print some propeties of ffmpeg for you
srcWidth: 160
srcHeight: 112
srcFPS: 25
srcAB: 32
srcAR: 32000
getDuration: 9.60000038147
getFrameCount: 240
getFrameRate: 25
getFilename: /home/amitadut/public_html/gallery_video/robot.avi
getComment:
getTitle:
getAuthor:
getCopyright:
getArtist:
getGenre:
getTrackNumber: 0
getYear: 0
getFrameHeight: 112
getFrameWidth: 160
getPixelFormat: yuv420p
getBitRate: 183948
getVideoBitRate: 104857200
getAudioBitRate: 32000
getAudioSampleRate: 32000
getVideoCodec: mpeg1video
getAudioCodec: mp2
getAudioChannels: 1
hasAudio: 1
hi,
i need conversion of any video to ‘.flv’ using FFMPeg on fly in php code. this is need to done by uploading a video
thank you.
hi,
i have windows sever, i am using php for developing any video to flv using ffmpeg. please provide the php code for converstion any video to flv on fly.
thank you.
iam looking for ffmpeg php windows dll files, how to setup ffmpeg in wamp could you please help in this regard.
Please help me
How can I join two flv files ?
hi.
thanks for your work. i am happy. I hope you will work better in coming days.
Narayana
kathmandu
Nepal
Hey
Any one can tell me solution of pixlated video.Please see this link http://www.iceagevideo.com.In this video is pixlated. I am using ffmpeg to convert the video format to flv.I am also using -sameq in the ffmpeg command. Any one tell me solution then video will be clear
@ Rohit…. `best` is such a subjective term. Low quality bitrates are less than 300k, but then your video will get pixelated. If you use the -sameq switch in your ffmpeg command, then the quality will be as high as the original, but then it could stream slowly depending upon your server, the bandwidth coming out of it, the bandwidth of your users, and their machine spec’s. I like 500k bitrates, personally.
@Sajith: Thanks for the function list. Now I can make my encoding engine smarter.
Hey
Any one tell me which is best bit rate in ffmpeg so videos will low in buffering in video player
Hey
when i enter the above like this
extension_loaded(‘ffmpeg’) or die(‘Error in loading ffmpeg’);
$ffmpegInstance = new ffmpeg_movie(‘http://iceageadultvideo.com/flvideo/102.flv’);
echo “getDuration: ” . $ffmpegInstance->getDuration() .
“getFrameCount: ” . $ffmpegInstance->getFrameCount() .
“getFrameRate: ” . $ffmpegInstance->getFrameRate() .
“getFilename: ” . $ffmpegInstance->getFilename() .
“getComment: ” . $ffmpegInstance->getComment() .
“getTitle: ” . $ffmpegInstance->getTitle() .
“getAuthor: ” . $ffmpegInstance->getAuthor() .
“getCopyright: ” . $ffmpegInstance->getCopyright() .
“getArtist: ” . $ffmpegInstance->getArtist() .
“getGenre: ” . $ffmpegInstance->getGenre() .
“getTrackNumber: ” . $ffmpegInstance->getTrackNumber() .
“getYear: ” . $ffmpegInstance->getYear() .
“getFrameHeight: ” . $ffmpegInstance->getFrameHeight() .
“getFrameWidth: ” . $ffmpegInstance->getFrameWidth() .
“getPixelFormat: ” . $ffmpegInstance->getPixelFormat() .
“getBitRate: ” . $ffmpegInstance->getBitRate() .
“getVideoBitRate: ” . $ffmpegInstance->getVideoBitRate() .
“getAudioBitRate: ” . $ffmpegInstance->getAudioBitRate() .
“getAudioSampleRate: ” . $ffmpegInstance->getAudioSampleRate() .
“getVideoCodec: ” . $ffmpegInstance->getVideoCodec() .
“getAudioCodec: ” . $ffmpegInstance->getAudioCodec() .
“getAudioChannels: ” . $ffmpegInstance->getAudioChannels() .
“hasAudio: ” . $ffmpegInstance->hasAudio();
in my site of one video. It gives me following description.please tell me how i can get excellent quality video from this which will buffer too much
getDuration: 14.89getFrameCount: 445getFrameRate: 29.9166660309getFilename: http://iceageadultvideo.com/flvideo/102.flvgetComment: getTitle: getAuthor: getCopyright: getArtist: getGenre: getTrackNumber: 0getYear: 0getFrameHeight: 1200getFrameWidth: 1600getPixelFormat: yuv420pgetBitRate: 64000getVideoBitRate: getAudioBitRate: 64000getAudioSampleRate: 22050getVideoCodec: flvgetAudioCodec: mp3getAudioChannels: 2hasAudio: 1
Hey
Thanks for reply me. This is my site link http://www.iceageadultvideo.com.Please register here and upload any video. I am facing two problems in this site.One it takes too much time in uploading the videos and second in flash player i wanna fast speed flash player. I will be very thankful to you if u can help me in this
@Rohit
To work the uploading fast, do a queuing machanism for converting videos. See the implementation in mobshare.in
Register there and upload a pic, it wont come that time, instead a processing symbol will be shown. The real image will be displayed after a little bit time of processing
hi
how do i strip a certain section of a video(m3). say to post 5-10 sec audio to listen b4 some1 dwnloads it.. using ffmpeg
thanx
vasu
Hey
I have implemented the ffmpeg in the site, But it is not working well, Problem is the it takes too much time to upload the videos.can any one tells me how i can make it fast
Hi,
first of all i would thank you every one, i have learn lot from this discussion.
i’m having the same problem exec(‘ffmpeg ..’) is not working on my server. i have read all the previous comments & tried those actions
but the problem is still remaining. ffmpeg is working fine in my terminal & not working through my php code with exec(‘ ‘)
i have check error_log file; it’s saying(also tried with whoami..)
sh: /whoami: No such file or directory
sh: /pwd: No such file or directory
sh: /ffmpeg: No such file or directory
the file path is correct & it has this file permissions(i hv tried with chmod -R 777 filename)
-rwxrwxrwx 1 apache
please help me to solve this!
my server details are:
Linux and OS is Fedora ,Apache/2.2.3 (Fedora),PHP Version 5.2.6
or please let me know if there is another way to accomplish this… thanks.
Question I am trying to solve is this. We have flash based property tour tool that takes photos of property listings and displays them in sequence. Is there a way to take the swf that is displayed typically in a browser window and capture 30 seconds of it and convert to mpg using ffmpeg? Thanks in advance.
It seems as if you need to get a web host that has the ffmpeg library for php so that you can execute the ffmpeg commands with exec(). I found documentation of ffmpeg: http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html that helped out a lot. I assume that the exec() function requires parameters that can be found in the ffmpeg documentation such as:
exec(ffmpeg -f oss -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg)