jjrjr1
Posts: 942
|
| Posted: 02/06/2008, 5:53 AM |
|
Hi
I have been working on a large project with many challenges. As a result I hvae learned many new things. I would like to share those if anyone needs his functionality. CCS is a great tool and we certainly have a great community here.
I had a requirement to convert any video uploaded into one format at the server. I made some code that does this using FFmpeg from CCS.
If anyone is interested, Let me know.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Gena
Posts: 591
|
| Posted: 02/06/2008, 6:17 AM |
|
Yes, it's very interesting!
_________________
Gena |
 |
 |
Zye
Posts: 56
|
| Posted: 02/06/2008, 6:19 AM |
|
Hi John
Once again you have a function that I really need to know about right now. I have only just signed up for a VPS system with PHP 5/ MySQL 5 installed (for a client). FPDF dosn't support PHP 5 Ahhh!
I got the host providers to install FFmpeg. Now I need to know how to use it. Any info that you would share on the subject would be of imense value and help me out a lot.
Hoping you get enough support. 
Cheers and many thanks
Zye ...
|
 |
 |
Zye
Posts: 56
|
| Posted: 02/07/2008, 5:35 AM |
|
bump ...
Can you help me out if I PM you John
Cheers ...
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 02/07/2008, 5:49 AM |
|
Hi
First FFmpeg can only be used with srever packages that allow root access such as VPS or Dedicated server. You habe the first issue resolved.
I am not to sure about how your vendor compliled ffmpeg for you. you might want to download it and complie it yourself. Ypou also might want to add some additional codecs that ffmpeg does not come with. It is nive to do that but not totally necessary. A note is that ffmpeg does not come with the QCELP coded for mobile phone audio. I cannot find a good source for that so you have to address that when converting those (The sample CCS code deals with that.) Also, you will find very limited documentation on the net that helps with ffmpeg conversion commands so you might have to play with that. The CCS sample here uses FFmpeg and converts all video to mpg video files. It also converts the mobile phone 3gp etc files to mpg without audio. The tagret compiled version of FFmpeg this code sample works on is the latest FFmpeg version (using the svn link) with FAAD and lib3flame codecs linkws if.
With all that said. Here is the code I used. An important thing to remember is that after the file is converted the database needs to be updated with the new file upload name. That code is here also.
Useful links:
ffmpeg Documentation: http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC1
Down Load FFmpeg: http://ffmpeg.mplayerhq.hu/download.html
Helpful PHP classes and doc: http://www.phpclasses.org/browse/package/3747.html
Note: I did not implement the above code but the information was helpful.
The FAAD and Libmp3lame codecs can be found on sourceforge.net
the CCS code below needs to be in the control's after process file event:
// Video Convert to MPG
global $FFtest; // I used this to control if a video woule be processed or not
global $uploaddir; //Where the file is uploaded to directory path
$videoname=$Component->GetValue();
$invideo= $uploaddir.$videoname;
$ovideo=$invideo;
$ovideo= strrev($videoname);
$ovideo = substr($ovideo,strpos($ovideo,"."));
$ovideo= strrev($ovideo)."mpg";
$renamevideo=$ovideo;
$ovideo=$uploaddir.$ovideo;
$codec=" -acodec mp2 ";
if (strpos($invideo,"3gp") || strpos($invideo,"3gpp") || strpos($invideo,"3g2")){$codec="-an";} // prevents ffmpeg from failing if it is a mobile phone upload no audio codec
if ($FFtest==0){
exec("ffmpeg -i ".$invideo." -y -f vcd -vcodec mpeg1video -r 29.97 -s 740x576 ".$codec." ".$ovideo);
$db = new clsDBMobiGolf(); // is the name of your database object and this code fixes the database with the new filename
$fields = array(
array("Name" => "vid_filename", "DataType" => ccsText, "Value" => $renamevideo)
);
$sql = CCBuildUpdate("mg_video", $fields, $db) . " WHERE vid_filename = " . $db->ToSQL($videoname, ccsText);
$db->query($sql);
exec("rm ".$invideo); // If you want to debug change this to a passthru and have the program die() here so you can check out what has happened.
}
// End Video Convert to MPG
I hope that helps.
Let me know if you need more info.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 02/07/2008, 6:00 AM |
|
Zye
I'm online now. Not sure how to PM though....
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 02/07/2008, 7:50 AM |
|
Zye...
Still need help? I have been waiting to see if you wanted to PM me...
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Zye
Posts: 56
|
| Posted: 02/07/2008, 9:37 AM |
|
Hi John
If you go to 'My Profile' at the top of these forums (While you are logged in) . Click on 'Inbox' to your left you will see a few messages. Cheers.
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 02/16/2008, 4:23 PM |
|
Hi
If anyone has had a problem getting ffmpeg to run from the exec command in CCS, try this
In the exec statement I found some servers require the full path name to execute ffmpeg.
that path should be /usr/local/bin/ffmpeg on most servers.
Hope that helps if you are having problems
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Zye
Posts: 56
|
| Posted: 03/01/2008, 9:04 PM |
|
Hi John and peeps
Long time bogged down. I have had no joy with converting my video files to FLV with CCS. Is your above code for Windows OS John? I am using Linux platform. The class that you mentioned has just been updated - http://www.phpclasses.org/browse/package/3747.html
I set up the examples for the class and voila! I have managed to convert one of my AVI files to FLV, audio and all. The other two files that I tested (AVI and MPG) failed to convert, with a possible codec error. At least I know that my server has all the right installs (except maybe some codecs). I tried to apply the example to my CCS project and I get nothing at all. The only thing that I have managed to do previously in CCS is get thumbnails using this code:
$maxThumbnails=2;
$thumbnailsFrom=1;
$ffmpegObj = new ffmpeg_movie($invideo);
$totalTime=$ffmpegObj->getDuration();
$frameRate=$ffmpegObj->getFrameRate();
$thumbIncrements=(($totalTime*$frameRate)-($thumbnailsFrom*$frameRate))/$maxThumbnails;
$wide=$ffmpegObj->getFrameWidth();
$high=$ffmpegObj->getFrameHeight();
$startFrame=$thumbnailsFrom*$frameRate;
for($t=0;$t<$maxThumbnails;$t++){
//$image= @imagecreatetruecolor($wide,$high);
$thumbFile=$invideo.".".$t.".png";
$currFrame=floor($startFrame+($thumbIncrements*$t));
//echo "<br>thumb of frame $currFrame: ".$thumbFile;
$thumb=$ffmpegObj->getFrame($currFrame);
if ($thumb) {
$thumbImage = $thumb->toGDImage();
if ($thumbImage) {
imagepng($thumbImage,$thumbFile);
imagedestroy($thumbImage);
}
}
}
It renders OK. I don't understand as yet how I can get the thumbs but not the video. I think it is maybe because of the file move from the temp to the file foler. My video conversion part of the code is in a mess at the moment, with all my experimenting. If I get a bit closer I will post it. Thanks for your help John. I hope I can crack this soon and move on to enhance/finish it.
A good link for Linux FFmpeg tips can be found at: http://vexxhost.com/blog/category/ffmpeg/
Zye ...
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 03/02/2008, 6:43 AM |
|
Hey Zye.
Long time no see.
The code I posted is is running on a linux server (Actually RedHat) The code works and is installed at my test server www.realtest.biz/mobi . The implementation there converts videos uploaded to mpg for the golf trainers. If you want to see it work there let me know.
In your example it seems you used the ffmpeg class object to convert to flv. I did not use the class but actually ran the commands myself in CCS. The code I posted is added in CCS in the Afterprocess event for a upload control
On thing I learned on some servers to exec from CSS the command for ffmpeg might need to be the entire path.
eg: exec (/usr/bin/ffmpeg ......your input stuff...)
What is the error? Just files are not being created? A couple of thoings you can try for trouble shooting is
1. Go to your linux console using your terminal software and execute the ffmpeg command directly at the linux level. You will see any ffmpeg errors generated such as codec or parameter errors.
2. You may also be able to accomplish the same thing as above by replacing the exec() for the ffmpeg with passthru(/usr/bin/ffmpeg ....your input stuff);die(); in the script i posted. This will stop the script and allow you to see what is happening within the CCS context.
I did not convert to flv but or use the class I downloaded either. But I do know that you need flvtool and mp3lame installed and compiled properly.
Let me know if that helps.
John
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 03/02/2008, 1:13 PM |
|
Hey Zye
I put a quick demo of a small script to demo this conversion on my test site.
Try it at http://realtest.biz/convertmedia.php
I only implemented mpg conversion at this time. I will add other later.
This is entirely a CCS script running on a linux redhat server.
If you need anything else let me know.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Zye
Posts: 56
|
| Posted: 03/02/2008, 2:56 PM |
|
Hi John
Many thanks 
I just tried your demo and it works just great. Congrats ... what an inspiration. The file that didn't convert (as mentioned in my previous post) using the class, converted to mpg just fine with your setup. Right! I am going to crack on with it. I will try mpg first off, to see if it is successful. I went straight into flv conversion, which is my goal but hasn't worked for me thus far. Great site development on the Mobi by the way.
Check back with you soon.
Cheers
Zye ...
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 03/03/2008, 10:04 AM |
|
Hi
Thanks, Glad you liked the demo. I added a couple more conversions to the dropdown menu.
If I get some time today I will do a FLV to see how that works.
Did I give you a link to Mobi? Where did you find it? That was a very fun project. If you want to see the back end let me know.
John
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 03/03/2008, 12:16 PM |
|
Hey Zye
I played with the FLV conversion and got it to work on my demo site.
Check it out at http://realtest.biz/convertmedia.php
I used the ffmpeg class. There was a bug in the ffmpeg class.
edit ffmpeg.php find the SetFormatToFLV method.
You will see the -acodec set to mp3. That does not work if you are using the latest ffmpeg with the latest libmp3lame. I think if you check ffmpeg you will find libmp3lame as a codec not mp3. So... change mp3 to libmp3lame.
Then try using the class with example1 that came with the class.
I do not have a flv player so I have not tested the output file yet. But it seems to create it fine.
Let me know if that helps.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Zye
Posts: 56
|
| Posted: 03/03/2008, 1:48 PM |
|
Hi John
I just lost my post with this forum reply timeout. Arrrrrrrhhhhh!!!! vex
I am glad that there is a topic edit for me to polish up my post ... dratt! anyways!
Alas! I have had great success (avi, mpg, wmv) with the line of code below, replacing your conversion line in your code:
exec($ffmpegPath." -i ".$invideo." -ar 22050 -ab 32 -f flv -s 320×240 - | ".$flvtool2Path." -U stdin ".$ovideo);
Hooray! up and running.
A player can be got from: http://www.jeroenwijering.com/?item=jw_flv_media_player
Also do a search for Flow Player.
I am seeking to implement a file upload progress meter next. I know that there are more accurate Ajax/CGI scripts and PHP core patches. http://www.devpro.it/javascript_id_96.html
Haven't managed to get anything going as yet. xajax upload and xupload look interesting. This feature is very much needed for video upload file sizes.
Many thanks once again. Your demo is working great.
I will check back soon.
Zye ...
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 03/05/2008, 9:45 AM |
|
That's great news.
I am not sure but I think you need to use the MP3 codec. I seem to think I remember reading that FLV files to be completely compatible with all players it needs to be MP3 audio.
You could actually specify that in your command line -acodec libmp3lame .
Also if you use the ffmpeg class you need to modify the setformattoflv method to libmp3lame.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jurijs
Posts: 1
|
| Posted: 05/04/2008, 7:40 AM |
|
Hi, i am from a little group, thats creates movies and other stuff. We wont to add video player to our web. Our hosting is under Linux. So we installed ffmpeg and now we are searching for php code(script) to upload and auto convert media file.
1. upload -> 2.convert to flv trough ffmpeg 3-> delete uploaded media file 4-> leave flv converted file. ( scheme )
Sorry for my bad English, we really need help, i hope someone will help us.
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 05/04/2008, 4:05 PM |
|
Hi
Did you try the code i posted above?
Go to my test site: http://realtest.biz
You will see an example of video conversion using ffmpeg on a linux server with PHP code generated by CCS.
I works pretty well.
Let me know how I can Help.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |