FFMPEG PHP Audio Conversion Basics


Published on

Learn how to convert audio files using FFMPEG and PHP exec function. Will also how how to record audio from a mic and turn documents into audio files.

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

FFMPEG PHP Audio Conversion Basics

  1. 1. FFMPEG Audio Tutorial www.prodigyview.com
  2. 2. OverviewObjectiveLearn how to convert audio files using ffmpeg and the phpfunction exec.Requirements Installed version of ffmpeg Understanding of the DEFINESEstimated Time10 minutes www.prodigyview.com
  3. 3. Follow Along With A Code Example1. Download a copy of the example code at www.prodigyview.com/source.2. Install the system in an environment you feel comfortable testing in.3. Proceed to examples/avi/FFMPEG_Audio.php http://www.prodigyview.com
  4. 4. execIn this tutorial we are going to be using the function exec.In PHP this function will allow you to execute programsdirectly on the command line.For more information, read the PHP doc.http://php.net/manual/en/function.exec.php http://www.prodigyview.com
  5. 5. Location of FFMPEGThe first thing we need to is access ffmpeg on yourserver. The program ffmpeg must be installed on yourserver environment.On my server ffmpeg is accessible from anywhere. But if yourffmpeg is only accessible from /usr/share/ffmpeg, then changeyour value to that or where ever ffmpeg is accessible from. Ifyou are unsure, ask your hosting provider. http://www.prodigyview.com
  6. 6. Input FileFor this example to work, we at least need a video thatalready exist. ProdigyView Example code comes with aaudio in mp3 format. PV_ROOT is one of DEFINES inProdigyView.1. PV_ROOT define for the top level directory of your application 2. Location of video file relative to the top level directory www.prodigyview.com
  7. 7. FFMPEG SyntaxThe syntax for converting a file is relatively easy. You need theaudio file to be converted and the location to save the output.Notice in the code at the bottom, we are using PV_VIDEO DEFINEas the location to save the file. Example Syntax: ffmpeg –i input_file.ext output_file.ext 1. Location of FFMPEG program 2. Location of file to convert 3. Output location and name of converted file
  8. 8. Format ConversionOne of the great things about FFMPEG is the conversionof formats merely by changing the extension. Rememberthat our input file was a .mp3, lets change it to a .wav1. Location of FFMPEG program 2. Location of file to convert 3. New file extension www.prodigyview.com
  9. 9. Add OptionsFFMPEG also has the ability to change the characteristicsof an audio file. Below we are going to change the bitrateto 128k. Remember that options passed always apply tothe next file. This means the-i applies to the input file andthe –b is applied to the output file.Apply option to input file Apply option to the output file www.prodigyview.com
  10. 10. Recoding From MicAwesome features of ffmpeg is to directly record audioinput from an outside source such as your mic. This willdiffer among your server environments but that basicswork like below.1. Open Sound System(OSS)specifies the sound input device 2. Output sound to file www.prodigyview.com
  11. 11. Hearing FilesOur last demonstration in this tutorial will converting andhearing sounds of files. With FFMPEG we are going toconvert the README.txt file the came with ProdigyView. Output file into dsp and convert link www.prodigyview.com
  12. 12. FFMPEG DocumentsThe arguments used here is only an example of the ffmpegarguments available. For more information on ffmpeg, visit:http://ffmpeg.org/ffmpeg.html#Audio-Options Review 1. FFMPEG must be installed to be used. 2. exec function can be used to access ffmpeg. 3. Ffmpeg follows the format of “ffmpeg –i input_file.ext output_file.ext” 4. Arguments must be added before the file that they are going to affect. 5. Change the file format by changing the extension of the output file www.prodigyview.com
  13. 13. More TutorialsFor more tutorials, please visit:http://www.prodigyview.com/tutorials www.prodigyview.com