PDA

View Full Version : FFMPEG pointers


medibco
04-28-2007, 11:28 AM
Hi all,

I am very new to FFMPEG but heard that it was one of the best ways to encode video serverside. What i'm after is for some general pointers in executing some basic FFMPEG commands from a php script.

The project i'm working on is a media sharing site where registered users will be able to upload a video in a wide range of formats and other users will be able to download the same file. What i would like to do is to create a smaller (say 200x200 px) copy of the uploaded file in .flv format, for viewing on the site. If i'm right in thinking i believe FFMPEG can do this.

If any one can give me some general pointers as to how to do this then that would be fantastic. The php script that i want to run the conversion from resides in the directory public_html/test_media/test.php

Thanks

Leo

medibco
04-28-2007, 12:08 PM
OK i'm starting at the beginning by just trying to list the formats FFMPEG supports. the code in my public_html/test_media/test.php file is:

exec("../usr/local/bin/ffmpeg --formats");

Nothing happens when i run this, is the path pointing to the correct location?

cheers

Leo

Cirtex Admin
04-28-2007, 01:36 PM
exec("/usr/local/bin/ffmpeg -i /home/user/public_html/file.avi -f flv -acodec mp3 -ab 64 -ac 1 /home/user/public_html/converted/converterd.flv");

This is a sample code and also note you might want to check with some existing conversion scripts to see how things are done.

Cheers

medibco
04-28-2007, 02:10 PM
hi
sorry for my naiveness but i have tried your example but to no avail. My php file is as follows:
<? exec("/usr/local/bin/ffmpeg -i /home/user/public_html/test_media/test.avi -f flv -acodec mp3 -ab 64 -ac 1 /home/user/public_html/test_media/test.flv"); ?>

the test_media folder has full permissions set as does the test.avi file.

When i run the code i just get a blank screen, so i would assume there are no errors in the script.

Should i be seeing something happen on the page like it taking the time it takes to convert the file, to load?

thanks again

leo

Ozu33
04-28-2007, 04:01 PM
Hi, Medibco

The best way to test to see if your FFMPEG command is working is to use the command line. Upload a video into your home directory, then SSH into that directory and enter your desired FFMPEG command on that movie into the command line. That will allow you to see the FFMPEG progress as it works, if it works; otherwise it will allow you to see the error message so you know what needs fixing

After you've done that you can move on to making it work in PHP. One trick there is to get the value returned by exec and print it out:

$command = "[Your desired FFMPEG command]";
exec($command,$status);
echo "Exit status code of command is $status";

brendandonhue
04-29-2007, 02:09 AM
You might want to try using passthru() and it will show you the output of the command you're running.

medibco
04-29-2007, 06:47 PM
thanks for all the replys,

I tried executing the ffmpeg command in the command line and managed to successfully convert a file that resided in the root directory but any file that i tried to convert in the public_html directory returned an I/O ERROR which suggested that the file was either corrupt or truncated. When i try to convert a non-existing file i get the same error which makes me think that it could be a permissions problem with the public_html directory or my paths are wrong.

I shall keep trying different options though, and thanks again for the replies

leo

medibco
04-30-2007, 06:50 PM
ok i have now checked the permissions of my public_html folder and everything seems fine.

when i run this command in the command line shell:
ffmpeg -i /public_html/file.avi -f flv -acodec mp3 -ab 64 -ac 1 /public_html/converterd.flv
i get this error:
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et
al.

/public_html/file.avi: I/O error occured

Usually that means that input file is truncated and/or corrupted.

Any Ideas what this means? As i said earlier i have managed to successfully convert a file using this command:
ffmpeg -i file.avi -f flv -acodec mp3 -ab 64 -ac 1 converterd.flv
but as soon as i target anything within my public_html folder i get this error.

Any help would be greatly appreciated

Thanks

medibco
04-30-2007, 07:19 PM
For anyone who wants to understand the basics of using ffmpeg, i came accross this site:

http://www.linuxjournal.com/article/8517

Although this hasn't solved my issue, it was a great help in understanding the basics of how ffmpeg works and should be used.

Just thought it may be of some use to someone

Josh
04-30-2007, 07:28 PM
Bookmarked will have a read sometime, thanks! I can't help you I'm new to ffmpeg too, thanks for the links ;) lol

chris
05-01-2007, 12:55 PM
Hi,

I am new to ffmpeg too, in fact just started today!
The script below seems to work to convert avi files to flv files, but the quality is not good and i wondered if anyone can point me in the right direction re syntax to control bitrate of output video (the input file has a bitrate of nearly 1 MB but I can't get beyond 256 kbps on the output.

Anyway here's the code if you want to try it:-

//path to my directory
$current_dir = getcwd();

$file = "Anglesey1.avi";
$temp_file_array = explode(".",$file);
$temp_file_name = $temp_file_array[0]."_temp";
$temp_file = $temp_file_name.".flv";
$new_file = $temp_file_array[0].".flv";

exec("/usr/local/bin/ffmpeg -i /$current_dir/$file -f flv -acodec mp3 -ab 256k -ac 1 /$current_dir/$temp_file");

//flvtool2 is used to fix meta data from temp file and saves it as new file
exec("/usr/local/bin/flvtool2 -Uv /$current_dir/$temp_file /$current_dir/$new_file");



//Creating thumbnails from the created .flv file:

exec("/usr/local/bin/ffmpeg -i /$current_dir/$new_file -an -ss 00:00:03 -an -r 2 -vframes 1 -y /$current_dir/%d.jpg");
echo <img src='1.jpg' border='0'>";

chris
05-02-2007, 07:21 AM
Sorry,

exec("/usr/local/bin/ffmpeg -i /$current_dir/$file -f flv -acodec mp3 -ab 256k -ac 1 /$current_dir/$temp_file");

I've worked out that ab controls the audio bitrate not the video!


exec("/usr/local/bin/ffmpeg -i /$current_dir/$file -f flv -acodec mp3 -b 512k -ac 1 /$current_dir/$temp_file");

will give better quality.

This works on avi and wmv files fine, but not with mp4 files. Any ideas or pointers anyone?

Cheers,

Chris

chris
05-03-2007, 06:09 AM
Wow, I'm overwhelmed with the responses!! Fortunately I've solved the problem alluded to in my last posting so I shall sign off and hope that something I said was useful to someone...

medibco
05-03-2007, 12:54 PM
Hi Chris,

Thanks for the replies, they have been a great help in getting it going. I found out that it was my paths that were slightly wrong. I didn't realize that php had 'getcwd();' function. I'm sure that will be extremely useful in the future.

I'm glad that you have ironed out all your bugs, and i'm sorry i couldn't help you.

btw did you manage to find any good resources which explained the different ffmpeg commands, because i'm still looking for a decent one.

Thanks again for your help

leo

chris
05-04-2007, 05:24 AM
Hi Leo,

Glad you found my posting helpful, I was having a frustrating and unusually grumpy day yesterday! Help with ffmpeg isn't esy to come by but try http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html for official documentation and there is a mail list which helped me solve the problem with converting mp4's at
http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user

All the best,

Chris