Jump to content

Need help with simple ffmpeg class


inutero

Recommended Posts

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
$source="cat.mpeg";
$destination="cat.flv";

class convert
{

	function convert($source,$destination)
	{
	// this will create a .flv from .wmv
	// you can chnage the other parameters if you are an expert 
	exec("ffmpeg -i -f {$source}  {$destination}");

	}
}




$jf=new convert($source,$destination);


?>

 

The problem is the variables don't seem to be read, I'm pretty sure it is the way I have written them. I know ffmpeg works because if I replace the $source & $destination the conversion works fine.

 

Any tips on how to correct this?

Link to comment
https://forums.phpfreaks.com/topic/104177-need-help-with-simple-ffmpeg-class/
Share on other sites

You are not declaring the variables inside the class, so I don't think it will work. Try this instead...

 

<?php
class convert {
    var $source;
    var $destination;
    function convert() {
        // this will create a .flv from .wmv
        // you can chnage 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();
?>

 

That should work if it is loading the files correctly, but don't hold your breath, I haven't tested it. If not, there is an OOP forum, which may help a little more, as people in their are more familiar with classes and other OOP stuff.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.