inutero Posted May 5, 2008 Share Posted May 5, 2008 Ok, I'm rather new to php so sorry for that. I'm trying to use ffmpeg to convert videos to flv, I can get it to work but I want the input and output files to be variables. My current code looks like this: <?php class convert { var $source; var $destination; function convert() { // this will create a .flv from a video file // you can change the other parameters if you are an expert exec("ffmpeg -i -f {$this->source} {$this->destination}"); } } $jf=new convert(); $jf->source="cat.mpeg"; $jf->destination="cat.flv"; $jf->convert(); ?> The problem is the variables don't seem to be read, I'm pretty sure it is the way they are written. I know ffmpeg works because if I replace the $source & $destination the conversion works fine. Any tips on how to correct this? Quote Link to comment https://forums.phpfreaks.com/topic/104178-solved-problem-with-simple-ffmpeg-class/ Share on other sites More sharing options...
dooper3 Posted May 5, 2008 Share Posted May 5, 2008 aha! Just realised what I did was wrong in the other board... try changing this line: $jf=new convert(); To this: $jf=new convert; Quote Link to comment https://forums.phpfreaks.com/topic/104178-solved-problem-with-simple-ffmpeg-class/#findComment-533330 Share on other sites More sharing options...
inutero Posted May 5, 2008 Author Share Posted May 5, 2008 Still nothing Current code: <?php class convert { var $source; var $destination; function convert() { // this will create a .flv from a video file // you can change the other parameters if you are an expert exec("ffmpeg -i -f {$this->source} {$this->destination}"); } } $jf=new convert; $jf->source="cat.mpeg"; $jf->destination="cat.flv"; $jf->convert(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/104178-solved-problem-with-simple-ffmpeg-class/#findComment-533335 Share on other sites More sharing options...
inutero Posted May 6, 2008 Author Share Posted May 6, 2008 Solved it using: <?php class convert { function convert($source,$destination) { /* @source=source file including full physical path @destination=destination file including full physical path*/ // this will create a .flv from .wmv // you can chnage the other parameters if you are an expert exec("ffmpeg -i '{$source}' -acodec libmp3lame -ar 22050 -ab 32 -f flv {$destination}"); } } $source=$file; $destination="{$file}.flv"; $jf=new convert($source,$destination); ?> Quote Link to comment https://forums.phpfreaks.com/topic/104178-solved-problem-with-simple-ffmpeg-class/#findComment-534187 Share on other sites More sharing options...
dooper3 Posted May 14, 2008 Share Posted May 14, 2008 Now it isn't really a class, just a function, but what would work and leave it much as before is taking the variables outside the quotes for the exec function, so just changing the exec line to the following: exec("ffmpeg -i -f {".$this->source."} {".$this->destination."}"); Oh, and leave off the () after "new convert" as we mentioned before. Quote Link to comment https://forums.phpfreaks.com/topic/104178-solved-problem-with-simple-ffmpeg-class/#findComment-540756 Share on other sites More sharing options...
448191 Posted May 14, 2008 Share Posted May 14, 2008 aha! Just realised what I did was wrong in the other board... try changing this line: $jf=new convert(); To this: $jf=new convert; Ehm.. Those are functionally exactly the same. <?php class convert { var $source; var $destination; function convert() { // this will create a .flv from a video file // you can change the other parameters if you are an expert exec("ffmpeg -i -f {$this->source} {$this->destination}"); } } $jf=new convert(); $jf->source="cat.mpeg"; $jf->destination="cat.flv"; $jf->convert(); ?> This code calls convert() twice. Once as the constructor (with source and destination still at NULL) and once after construction (source and destination should be populated). So it 'should' work (probably there is some error in the execution of ffmpeg the second time), but not correctly in any case. Try this instead: <?php //php4 class Conversion { var $_source; var $_destination; function Conversion($src, $dest) { $this->_source = $src; $this->_destination = $dest; } function execute($options = '-i -f') { return exec("ffmpeg $options {$this->_source} {$this->_destination}"); } } $conversion = new Conversion("cat.mpeg", "cat.flv"); $conversion->execute(); /** * OR: * */ //php5 class Conversion { private $_source; private $_destination; function __construct($src, $dest) { $this->_source = $src; $this->_destination = $dest; } function execute($options = '-i -f') { return exec("ffmpeg $options {$this->_source} {$this->_destination}"); } } $conversion = new Conversion("cat.mpeg", "cat.flv"); $conversion->execute(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/104178-solved-problem-with-simple-ffmpeg-class/#findComment-541367 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.