2. Overview
Objective
Learn how to convert audio files using ffmpeg and the php
function exec.
Requirements
ï Installed version of ffmpeg
ï Understanding of the DEFINES
Estimated Time
10 minutes
www.prodigyview.com
3. Follow Along With A Code
Example
1. 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. exec
In this tutorial we are going to be using the function exec.
In PHP this function will allow you to execute programs
directly on the command line.
For more information, read the PHP doc.
http://php.net/manual/en/function.exec.php
http://www.prodigyview.com
5. Location of FFMPEG
The first thing we need to is access ffmpeg on your
server. The program ffmpeg must be installed on your
server environment.
On my server ffmpeg is accessible from anywhere. But if your
ffmpeg is only accessible from /usr/share/ffmpeg, then change
your value to that or where ever ffmpeg is accessible from. If
you are unsure, ask your hosting provider.
http://www.prodigyview.com
6. Input File
For this example to work, we at least need a video that
already exist. ProdigyView Example code comes with a
audio in mp3 format. PV_ROOT is one of DEFINES in
ProdigyView.
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. FFMPEG Syntax
The syntax for converting a file is relatively easy. You need the
audio file to be converted and the location to save the output.
Notice in the code at the bottom, we are using PV_VIDEO DEFINE
as 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. Format Conversion
One of the great things about FFMPEG is the conversion
of formats merely by changing the extension. Remember
that our input file was a .mp3, lets change it to a .wav
1. Location of FFMPEG program 2. Location of file to convert
3. New file extension
www.prodigyview.com
9. Add Options
FFMPEG also has the ability to change the characteristics
of an audio file. Below we are going to change the bitrate
to 128k. Remember that options passed always apply to
the next file. This means the-i applies to the input file and
the âb is applied to the output file.
Apply option to input file
Apply option to the output file
www.prodigyview.com
10. Recoding From Mic
Awesome features of ffmpeg is to directly record audio
input from an outside source such as your mic. This will
differ among your server environments but that basics
work like below.
1. Open Sound System(OSS)
specifies the sound input device
2. Output sound to file
www.prodigyview.com
11. Hearing Files
Our last demonstration in this tutorial will converting and
hearing sounds of files. With FFMPEG we are going to
convert the README.txt file the came with ProdigyView.
Output file into dsp and convert link
www.prodigyview.com
12. FFMPEG Documents
The arguments used here is only an example of the ffmpeg
arguments 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. More Tutorials
For more tutorials, please visit:
http://www.prodigyview.com/tutorials
www.prodigyview.com