Shoutbox

FFMPEG-PHP: converting videos - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: FFMPEG-PHP: converting videos (/showthread.php?tid=72377)

FFMPEG-PHP: converting videos by Weyzza on 03-06-2007 at 07:42 PM

I want to convert any videos to FLV format.

code:
<?php
convertToFlv( "test.avi", "test.flv" );

function convertToFlv( $input, $output ) {
   echo "Converting $input to $output<br />";
   $command = "ffmpeg -i $input -s 320x240 -ar 44100 -r 12 $output";
   echo "$command<br />";
   shell_exec( $command );
   echo "Converted<br />";
}
?>
For some reason, it doesn't output anything.
What am I missing here?

ffmpeg
ffmpeg support (ffmpeg-php)     enabled
ffmpeg-php version              0.5.0
libavcodec version              Lavc51.32.0
libavformat version             Lavf51.8.0

RE: FFMPEG-PHP: converting videos by WDZ on 03-06-2007 at 07:53 PM

shell_exec() isn't supposed to output anything... try putting an echo in front of it. :p


RE: FFMPEG-PHP: converting videos by Weyzza on 03-06-2007 at 08:03 PM

quote:
Originally posted by WDZ
shell_exec() isn't supposed to output anything... try putting an echo in front of it. :p
What I meant with "anything" was the output file :p

Anyways, I added an echo there, and it's still the same.
It even doesn't say whether the library/command is unavailable or something.

I have a strange feeling that I have to call it in another way (creating a new object, etc.).
RE: RE: FFMPEG-PHP: converting videos by WDZ on 03-06-2007 at 08:38 PM

quote:
Originally posted by Weyzza
What I meant with "anything" was the output file :p
I thought that might be the case, but still, there should be some kind of error message if it fails... :-/

quote:
Anyways, I added an echo there, and it's still the same.
It even doesn't say whether the library/command is unavailable or something.
:S

Try a simple test...
code:
<?php

$output = shell_exec("ffmpeg -formats");

echo "<pre>";
print_r($output);
echo "</pre>";

?>
If successful, that should display info about the formats FFmpeg supports, and confirm that you can run it. If it doesn't work, I'm not sure what the problem is... maybe you have to specify the absolute path to the FFmpeg binary or something.

quote:
I have a strange feeling that I have to call it in another way (creating a new object, etc.).
I doubt it... the ffmpeg-php extension is only "for accessing and retrieving information from video and audio files." It doesn't do conversion. Besides, that script I linked to in the shoutbox simply calls shell_exec()...
RE: RE: RE: FFMPEG-PHP: converting videos by Weyzza on 03-06-2007 at 08:54 PM

quote:
Originally posted by WDZ
code:
<?php

$output = shell_exec("ffmpeg -formats");

echo "<pre>";
print_r($output);
echo "</pre>";

?>

I tried it earlier, and it printed nothing.
quote:
maybe you have to specify the absolute path to the FFmpeg binary or something.
Tried with /usr/local/bin/ffmpeg. It didn't work, either :p
I will confirm my hosting provider soon.
quote:
I doubt it... the ffmpeg-php extension is only "for accessing and retrieving information from video and audio files." It doesn't do conversion. Besides, that script I linked to in the shoutbox simply calls shell_exec()...

So FFMPEG-PHP is not the same as FFMPEG?
* Weyzza slaps himself around a bit with a large trout.
RE: FFMPEG-PHP: converting videos by WDZ on 03-06-2007 at 09:11 PM

quote:
Originally posted by Weyzza
I will confirm my hosting provider soon.
k. :tongue:

quote:
So FFMPEG-PHP is not the same as FFMPEG?
Correct, ffmpeg is a command-line program that has nothing to do with PHP. ffmpeg-php is a PHP extension that incorporates some of the capabilities of ffmpeg.

Edit: I tested your convertToFlv() function on my localhost (Win32) and it worked fine. All I had to do was change the path to ffmpeg.exe.
RE: FFMPEG-PHP: converting videos by mysoogal on 05-03-2009 at 08:55 PM

its 2009 ! lol

this is what i'm looking for but , i really hate flv ! flash now supports h264 !

how can i change this,
---------------------------------------------------------------------------------------
<?php
convertToFlv( "test.avi", "test.flv" );

function convertToFlv( $input, $output ) {
   echo "Converting $input to $output<br />";
   $command = "ffmpeg -i $input -s 320x240 -ar 44100 -r 12 $output";
   echo "$command<br />";
   shell_exec( $command );
   echo "Converted<br />";
}
?>

----------------------------------------------------------------------------------------------------------

to support this,

mencoder video.mpeg -o output.mp4 -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encopts bitrate=300:level_idc=41:bframes=3:frameref=2: nopsnr: nossim: pass=1: threads=auto -oac mp3lame

i'm not sure if mencoder can be called through like php. which runs with ffmpeg-php i believe.

i just want to encode to h264 video, mp3 audio, and output container to be ogg or ogm.

and yes i do notice this post was made years ago lol who knows maybe i get reply


RE: FFMPEG-PHP: converting videos by Dr4g0n on 05-09-2009 at 03:28 PM

code:
<?php
convertToFlv( "test.avi", "test.flv" );

function convertToFlv( $input, $output ) {
   echo "Converting $input to $output<br />";
   $command = "mencoder $input -o $output -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encopts bitrate=300:level_idc=41:bframes=3:frameref=2: nopsnr: nossim: pass=1: threads=auto -oac mp3lame ";
   echo "$command<br />";
   shell_exec( $command );
   echo "Converted<br />";
}
?>

How about that? Uses the mencoder command you wanted.
RE: FFMPEG-PHP: converting videos by -dt- on 05-09-2009 at 03:36 PM

also remember if you're passing an argument into the command line, use http://php.net/escapeshellarg to make it safeish ;>


RE: FFMPEG-PHP: converting videos by Dr4g0n on 05-09-2009 at 03:42 PM

quote:
Originally posted by -dt-
also remember if you're passing an argument into the command line, use http://php.net/escapeshellarg to make it safeish ;>

Yeah thanks dt, slipped my mind.

code:
<?php
convertToFlv( "test.avi", "test.flv" );

function convertToFlv( $input, $output ) {
   $input = escapeshellarg($input);
   $output = escapeshellarg($output);
   echo "Converting $input to $output<br />";
   $command = "mencoder $input -o $output -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encopts bitrate=300:level_idc=41:bframes=3:frameref=2: nopsnr: nossim: pass=1: threads=auto -oac mp3lame ";
   echo "$command<br />";
   shell_exec( $command );
   echo "Converted<br />";
}
?>