SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to executre ffmpeg with exec function

    I finally got ffmpeg installed on my server, and I am trying to figure out how I can execute it with php's exec function to change a mpg file to a flv file.

    Anyone have an idea?

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In PHP.

    PHP Code:

    $cmd 
    'ffmpeg -i test.mpg -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 test.flv';


    exec($cmd); 
    Try the above, i've used it before, and its worked.

    ffmpeg -i test.mpg -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 test.flv


    Explanation:

    -i test.mppg - The path to the file to be converted

    test.flv - Output file.

    -s 320x240 - w/h of outputted image in pixels.

    Other ones are pretty much self-explanatory.

    Also, in either Windows, or Linux type just the executable name, and hit enter.. Usually shows the parameters and documentation.
    Kieran Allen, 16 years old
    Full time PHP developer,
    With 5 years experience in web development.
    www.kieran.in .. my blog.

  3. #3
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kieran.in View Post
    In PHP.

    PHP Code:

    $cmd 
    'ffmpeg -i test.mpg -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 test.flv';


    exec($cmd); 
    Try the above, i've used it before, and its worked.

    ffmpeg -i test.mpg -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 test.flv


    Explanation:

    -i test.mppg - The path to the file to be converted

    test.flv - Output file.

    -s 320x240 - w/h of outputted image in pixels.

    Other ones are pretty much self-explanatory.

    Also, in either Windows, or Linux type just the executable name, and hit enter.. Usually shows the parameters and documentation.
    Awesome. Is there a way to also snag a thumbnail preview of the converted file?

    Is there a control for the quality level?

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, use the following command line to create a thumbnail:

    ffmpeg -an -y -t 0:0:0.001 -i sourcefile.flv -f image2 filetest.jpg


    The 0:0:0.001 is a milisecond as you probabally could have guessed.

    Basically thats the point of when to take the 'shot'. So basically, set that to whatever place you wish to take the thumbnail shot.

    Make sure you include the -t, otherwise each frame will be saved as a JPG.

    Quality control on the previous line is the -ab out of 100, i believe.
    Kieran Allen, 16 years old
    Full time PHP developer,
    With 5 years experience in web development.
    www.kieran.in .. my blog.

  5. #5
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Note that FFmpeg doesn't support the newer RealVideo codecs, so you won't be able to get a screenshot of .rm and .rv clips. What I do in that case is make a black image with GD of the same width and height as the video and place a RealPlayer logo in the center of it. At least that way my thumbnail gallery will display something other than the image's ALT text.

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by World Wide Weird View Post
    Note that FFmpeg doesn't support the newer RealVideo codecs, so you won't be able to get a screenshot of .rm and .rv clips. What I do in that case is make a black image with GD of the same width and height as the video and place a RealPlayer logo in the center of it. At least that way my thumbnail gallery will display something other than the image's ALT text.
    Good point.
    Kieran Allen, 16 years old
    Full time PHP developer,
    With 5 years experience in web development.
    www.kieran.in .. my blog.

  7. #7
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I attempted this code:

    PHP Code:
    $cmd '/usr/bin/ffmpeg -i /path/to/video/video.mpg -ab 90 -ar 22050 -b 500 -r 15 -s 640x480 /path/to/video/video.flv';
    exec($cmd); 
    It creates the .flv file, however, there is no data in the .flv file. It's 0KB in size.

  8. #8
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try directing the output to a log file and check the error messages:
    Code php:
    $cmd = '/usr/bin/ffmpeg -i /path/to/video/video.mpg -ab 90 -ar 22050 -b 500 -r 15 -s 640x480 /path/to/video/video.flv 2> /path/to/log_file';
    exec($cmd);
    Make sure the log_file has correct permissions.
    Saul

  9. #9
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no output to the log.txt that was created either. I placed '777' permissions on the log.txt file.

  10. #10
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well that's odd. Do you have shell access to the server? Can you run the command there?
    Saul

  11. #11
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Well that's odd. Do you have shell access to the server? Can you run the command there?
    When I attempt to run it from the bash, I get the error: Error while opening codec for output stream #0.1 - maybe incorrect parameters such as bit_rate, rate, width or height

  12. #12
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, try removing the params and try without them.
    Saul

  13. #13
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I found my problem.

    The parameter -ab is not for the video quality like I thought, its for the audio bitrate.

    http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html

    This command seems to have worked:

    PHP Code:
    $cmd '/usr/bin/ffmpeg -i /path/to/video/video.mpg -acodec mp3 -ab 32 -ac 1 -ar 44100 -s 640x480 /path/to/video/video.flv'

  14. #14
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well there you go.

    Another thing I keep noticing is people specifying the bitrates without the k suffix. According to the documentation, the settings are in bits/s, that means that -ab 32 should set the bitrate to 32 bits/s. Theoretically you should specify -ab 32k if you want it in Kbits. It might actually default to 64k as 32 bits are too low to use.

    I'd use 32k, to be safe.
    Saul

  15. #15
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bradical1379 View Post
    There is no output to the log.txt that was created either. I placed '777' permissions on the log.txt file.
    FFmpeg sends its output to STDERR, not STDOUT. Therefore you need to redirect the error output, not the program output, to the log file.

  16. #16
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    Well there you go.

    Another thing I keep noticing is people specifying the bitrates without the k suffix. According to the documentation, the settings are in bits/s, that means that -ab 32 should set the bitrate to 32 bits/s. Theoretically you should specify -ab 32k if you want it in Kbits. It might actually default to 64k as 32 bits are too low to use.

    I'd use 32k, to be safe.
    I noticed to have a constant quality (but a variable bitrate), use the option '-qscale n' when 'n' is between 1 (excellent quality) and 31 (worst quality).

    So I just set the '-qscale' to 5 and let the bitrate '-ab' be variable.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •