ffmpeg video basics for php tutorial

13
FFMPEG Basics http:// www.prodigyview.com

Upload: prodigyview

Post on 05-Dec-2014

13.034 views

Category:

Technology


2 download

DESCRIPTION

Learn how to convert videos in PHP using ffmpeg and php exec function.

TRANSCRIPT

Page 1: FFMPEG Video Basics for PHP Tutorial

FFMPEG Basics

http://www.prodigyview.com

Page 2: FFMPEG Video Basics for PHP Tutorial

OverviewObjective

Learn how to convert videos using ffmpeg and the php function exec.

Requirements

Installed version of ffmpeg

Understanding of the defines

Estimated Time

8 minutes

www.prodigyview.com

Page 3: FFMPEG Video Basics for PHP Tutorial

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_Video.php

http://www.prodigyview.com

Page 4: FFMPEG Video Basics for PHP Tutorial

execIn 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

Page 5: FFMPEG Video Basics for PHP Tutorial

Location of FFMPEGThe 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

Page 6: FFMPEG Video Basics for PHP Tutorial

Input FileFor this example to work, we at least need a video that already exist. ProdigyView Example code comes with a video in mp4 format.

1. PV_ROOT define for the top level directory of your application

2. Location of video file relative to the top level directory

Page 7: FFMPEG Video Basics for PHP Tutorial

SyntaxThe syntax for converting a file is relatively easy. You need the video 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

Page 8: FFMPEG Video Basics for PHP Tutorial

Parameters

FFMPEG has arguments that affect the output of a file. Remember that the arguments must be set before the file they will affect. Below we are going to change the aspect ratio for the output.

1. FFMPEG program 2. File to convert 3. Arguments that will change the aspect of the output file

4. Location and name of the output file

http://www.prodigyview.com

Page 9: FFMPEG Video Basics for PHP Tutorial

Changing File Formats

Up until now, we’ve been working within the same format, mp4. FFMPEG is a great piece of software because you easily change the formats of the video file by changing the extension.

3. Change the video to an avi

Page 10: FFMPEG Video Basics for PHP Tutorial

Cropping a VideoIn this example, we are going to change video formats and also crop the video. Looking at the documentation for ffmpeg, we have croptop, cropbottom, cropleft, cropright.

1. Arguments for cropping the video

2. Change the video format to an avi

http://www.prodigyview.com

Page 11: FFMPEG Video Basics for PHP Tutorial

PaddingIn this last example, we will add some padding to the video, and set the color of the padding. By now, you should understand the pattern that goes into converting a video.

1. Use the exec function and location of the ffmpeg program

2. The location of the file to convert

3.Arguments that add padding to the output file

4. Location and name of the output file 5. Change format of the output file

http://www.prodigyview.com

Page 12: FFMPEG Video Basics for PHP Tutorial

Review1. 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

FFMPEG DocumentsThe arguments used here is only an example of the ffmpeg arguments available. For more information on ffmpeg, visit: http://ffmpeg.org/ffmpeg.html#Video-Options

Page 13: FFMPEG Video Basics for PHP Tutorial

www.prodigyview.com

More Tutorials

For more tutorials, please visit:

http://www.prodigyview.com/tutorials