0

Can any one help me. I looking to convert a video file into flv using php and ffmpeg. I have tried some of the existing solution on stackoverflow but with no luck.

exec('ffmpeg -i Videos/robot.avi -ab 96k -b 700k -ar 44100 -s 640x480 -acodec mp3 Videos/robot.flv');

This is my code nothing happens when I execute this.

3 Answers 3

2

I assume your ffmpeg command works from CLI OK. If not, get that working first.

If you are trying to output FLV created on-the-fly with PHP and ffmpeg, try this:

<?php
  header("video/x-flv");
  passthru('ffmpeg -i Videos/robot.avi -ab 96k -b 700k -ar 44100 -s 640x480 -acodec mp3 Videos/robot.flv');
?>

#### EDIT #####

Here is a link to ffmpeg documentation that talks about using STDOUT: http://www.ffmpeg.org/ffmpeg-doc.html#TOC41

I think you should be able to do this:

<?php
  header("video/x-flv");
  passthru('ffmpeg -i Videos/robot.avi -ab 96k -b 700k -ar 44100 -s 640x480 -acodec mp3 -f flv pipe:');
?>
Sign up to request clarification or add additional context in comments.

7 Comments

Hello thank you for the reply. I have tried the code: exec('ffmpeg -i Videos/robot.avi -ab 96k -b 700k -ar 44100 -s 640x480 -acodec mp3 Videos/robot.flv'); using php but nothing happens. The file is not converted. I do not know if passthru is suppose to be a function. I really hope you can assist me.
passthru() and exec() are almost the same thing, except passthru() will return the results of the command you execute.
Also, you should modify your command to output the flv to STDOUT instead of writing to a file.
Wikipedia can explain: en.wikipedia.org/wiki/…
STDOUT is sort of like what a command outputs. Instead of writing the FLV to a file, it could just output raw data. You want that b/c you need to send the raw data through PHP to the web browser.
|
2

Check out this example: https://trac.ffmpeg.org/wiki/PHP

You should get it running in your CLI first before writing a PHP script.

After reading the example it seems like you want to use

shell_exec("insert ffmpeg command here");

Here's an ffmpeg php class that might be helpful:

https://github.com/olaferlandsen/FFmpeg-PHP-Class

Comments

0

I needed 'sudo' to run it on my local machine. For video/x-flv you need: "Content-Type: video/x-flv". My code:

<?php

    header("Content-Type: video/x-flv");
    passthru('sudo ffmpeg -i Videos/robot.avi -ab 96k -b 700k -ar 44100 -s 640x480 -acodec mp3 -f flv pipe:');

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.