Constructor: object Ogg (string $file[, integer $options=ANSI+CACHING [, string $cachedir="/cache.ogg"]])
- $file must be provided with full location. for an example: "/IMG/ogg/myfile.ogv". $file can be a relative path (no '/' at the beginning), an absolute path to the server document root (with a beginnin '/'), an absolute path to the server file system root, but within your public folders, or a remote http:// location. For instance, the class can only retrieve information from a remote (http://) ogg file if your server allows either the fsockopen() or fopen(http) calls in their configuration.
- $options is an optional parameter consisting a sum of the following constants: (CACHING or NOCACHING) + (ANSI or UTF8) + NOVENDORTAG + UPDATECACHE, with a default value of ANSI + CACHING.
- $cachedir is an optional parameter to define the absolute path where, from the root folder, the cache information should be stored (if enabled). The default is "/cache.ogg"
UTF8 or ANSI, defines the strings encoding of the extracted ogg information (for instance: comments, vendor, summary). Please note that this does NOT affect the way new comments will eventualy be written to the file later, which will automaticaly be converted (if necessary) to UTF8 by format standard.
CACHING or NOCACHING allows or disables caching the information of the file. Enabling will improve dramaticaly performances. Basicaly, the first time the constructor is parsing a file "/IMG/ogg/myfile.ogv", it will create a file "/
$cachedir/myfile.ogv.cache", that can be reused the next time. When a file is parsed, about 128kb of the file (64kb at the begnning and 64kb at the end) must be analysed to extract information.
UPDATECACHE (only if CACHING is enabled) is forcing the cache file to be overwritten (if existing) with up-to-date information fresh from the file. Warning: any previously user added information using the CacheUpdate() function will be lost.
NOVENDORTAG disables the automatic tagging of the vendor field with the version of this class, for reference or future debugging.
After the creation of the Ogg object or after any call of a public method of this class, it is strongly advised to check the public variable LastError. If LastError is
false everything is fine; else, LastError will contain a
string describing the problem.
If no problem occured, the public variable
Streams will be an
array with all king of information the library was able to retrieve, as shown in the previous example. The subarrays ['theora'] and ['vorbis'] will only be set if such stream was detected in the ogg file; therefore, checking for their presence will allow the user to see if the file is audio/video or only audio or only video.
Public method: integer WriteNewComments ([integer $refresh=5])
$refresh is an optional value in seconds after which the function will return (even if the writting is not complete). The interest of not writting the file is dual; in fact, the writting can take verrrrryyyyyy long, is the file is BIG. It is common to see video files with a size over 100++ MB. Unfortunately, it is not possibe with Ogg files just to "change" the comments in the middle of the file wihtin one shot : the whole file must be rewritten every time, taking a variable time. So splitting it in several calls in as many sessions will allow:
- Not to break the script php timeout "max_execution_time" (you can get it with a call to get_cfg_var("max_execution_time") or check your php.ini parameters file).
- to advise the front end user of the writting progress (most of the time, if nothing occurs after 10 seconds, the user might interrupt the process thinking something has failed).
So calling this function Will
begin to re-write the file with the comments you would have previously updated in the public array "
Streams" described below.
Return value: false if a problem occured (then check the LastError string to understand what went wrong) or the position in the file where the fonction ended. If the this value equals Streams['size'], then the file is complete (and the cache has been updated). Else, the calling script will have to call the other function "ContinueWrite()" (see below) in another session to continue the writting...
Public method: integer ContinueWrite ()
As explain before, this conction must be called as many times as necessary to complete the writting of the file started with the function "WriteNewComments()" previously described.
Return value: false if a problem occured (then check the LastError string to understand what went wrong) or the position in the file where the fonction ended. If the this value equals Streams['size'], then the file is complete (and the cache has been updated). Else, the calling script will have to call the same function again in another session to continue the writting...
Public method: string GetPicture ([int $framepos=1, [string $where=false]])
This functions extracts a jpeg picture from the frame '$framepos' of the video. if $framepos is omitted, the first frame of the video is extracted. The second parameter allows to specify where the picture will be stored; if omitted, this will store the picture in the cache folder with a name like 'myvideo.ogv.f1.jpg' (f1 designating the frame number). For future use, each extracted picture will be shown in the Streams[theora][pictures] array (see below). Before calling this function, user should check if the variable Streams[picturable] is true.
Return value: false if a problem occured (then check the LastError string to understand what went wrong) or the picture location.
Public method: bool CacheUpdate ()
It may be useful for the user to add his own fields to the Streams array and save it in cache for future use. This function simply allows to update the cache file with whatever the user added/modified in the
Streams array.
Warning ! If you change existing values, it will not really update the Ogg file, just the information displayed. Furthermore, Changing existing values like [commentlen] and [commentpos] could permanently damage the Ogg file if trying later to rewrite the comment tags !
Return value: false if a problem occured (then check the LastError string to understand what went wrong) or true and the cache file is updated.
Public variable: bool/string LastError
Contains either
false if no error recently occured, or a
string explaining the error in full text and in english.
Public variable: array Streams
This is the location where the class is storing whatever information it was able to get from the ogg file. While some parameters may be very useful from the calling application or the user, some are very technical and will most likely not be used. Anyway, all the information is here, and the variables have the same name as in the xiph.org documentation, and the same meaning. The most important variables will be described below, but don't hesitate to make a "print_r(
$this_array);" call to php to get an exhaustive list. However, some parameters will only appear in the array if they have a meaning for this file. For an example, you won't find vorbis related information if this is a pure video file !
- [oggfile] : Name and location of the ogg file given in parameter to the constructor
- [cachefile] : Name and location of the cache file associated, if caching is enabled
- [size] : File length in bytes
- [source] : either 'cache' or 'file' to mean from where the information was extracted
- [encoding] : either 'utf-8' or 'ansi' to describe encoding of the strings of this array, as requested in the constructor
- [summary] : An human readable summary information about the ogg file
- [duration] : Global duration of the ogg file. This is calculated as the biggest duration from the included streams
- [tmpfile] : Name and location of a temporary file written recently by a WriteNewComments() call. Basicaly, if this variable is present, it means that the rewritting of this Ogg file is in progress and should be continued using a call to the function ContinueWrite()
- [tmpfileptr] : Where the writting of the previous file stopped. By comparing this value to [size], we can estimate the percentage of the file that was already completed
- [picturable] : bool meaning is the script/server is able to extract a picture from this Ogg file.
- [skeleton] : The presence of this sub-array means that an Ogg Skeleton stream was found if this Ogg file. Below the list of variables of this sub-array:
- [version] : string in the form "major.minor" showing the Ogg Skeleton metadata version included in this file.
- [utc] : if available, 20 Byte string containing a UTC time in the form of "YYYYMMDDTHHMMSS.sssZ"
- [cmml] : The presence of this sub-array means that some CMML Metadata was found if this Ogg file. Below the list of variables of this sub-array:
- [version] : string in the form "major.minor" showing the Ogg CMML version included in this file.
- [serial] : Technical parameter to identify this stream amoung others
- [text] : CMML text string with the CMML Metadata content that was extracted
- [vorbis] : The presence of this sub-array means that a Vorbis stream was found if this Ogg file. Actually, if several vorbis streams would be present in a file (for an exemple: one for each supported language), only the first one will be analysed. Below the list of variables of this sub-array:
- [serial] : Technical parameter to identify this stream amoung others
- [channels] : Number of audio channels in this stream. For an example, '2' for a stereo stream
- [samplerate] : Sample rate in bytes per second
- [maxbitrate] : Maximal bitrate for a VBR encoding
- [nombitrate] : Nominal bitrate for a CBR encoding
- [minbitrate] : Minimal bitrate for a VBR encoding
- [bitrate] : Best calculated bitrate from previous values
- [vendor] : Vendor string (you might alter this value before eventualy re-writting the file)
- [comments] : array of as many entries as you have comments in this file (can be empty; you shallt alter theses values before eventualy re-writting the file)
- [commentlen], [commentpos], [commentnext], [commentleftSegments] : Technical values to allow eventualy rewritting the file. Those values should never be edited, or then the produced file will not be readable any more !
- [skeleton] : if some Ogg Skeleton information is available describing this stream, you will find here a string containing the "Message header fields" according to Rfc1822.
- [duration] : calculated duration (in seconds) of the stream
- [theora] : The presence of this sub-array means that a Theora stream was found if this Ogg file. Actually, if several Theora streams would be present in a file, only the first one will be analysed. Below the list of variables of this sub-array:
- [serial] : Technical parameter to identify this stream amoung others
- [vmaj], [vmin], [vrev] : Major, minor, revision version of the theora format
- [width], [height] : caculated image size in pixels
- [frate] : frame rate in frames per seconds, rounded at 0.01s
- [nombr] : Nominal bitrate
- [qual] : Quality
- [fmbw], [fmbh], [picw], [pich], [picx], [picy], [frn], [frd], [parn], [pard], [kfgshift], [pf], [cs] : Technical values. Check xiph.org documentation for more information
- [pixelaspectratio],[colorspace],[pixelformat] : pixel encoding information
- [vendor] : Vendor string (you might alter this value before eventualy re-writting the file)
- [comments] : array of as many entries as you have comments in this file (can be empty; you shallt alter theses values before eventualy re-writting the file)
- [commentlen], [commentpos], [commentnext], [commentleftSegments] : Technical values to allow eventualy rewritting the file. Those values should never be edited, or then the produced file will not be readable any more !
- [skeleton] : if some Ogg Skeleton information is available describing this stream, you will find here a string containing the "Message header fields" according to Rfc1822.
- [duration] : calculated duration (in seconds) of the stream
- [framecount] : Number of frames in the video
- [pictures] : array of already extracted pictures available in cache. The array key is the frame number.
v1.0 (August 2007)
First release, based mostly on the File_OGG pear package
http://pear.php.net/package/File_Ogg by David Grant. Added basic Theora support and caching, but kept same structure. This file was included with
Itheora v0.9 and later.
v1.1
Still based on the File_Ogg pear library, but with big structural changes and improved theora support.
v1.2
Intermediate version, to rewrite entirely the class, with first comment tags rewrite function, first ability to calculate Theora stream duration. This version was never published.
v1.3 (May 2008)
Complete rewritting of the class for performance improvement; now, only 64kb at the beggining and 64kB at the end is sufficient to get all the data. Added support to analyse remote http files (if server supports it). Separation from the Itheora project (which is still using it),
new own website and first official documentation.
v1.3e (June 2008)
Added picture extraction if php modules ffmpeg and gd2 are available.
Added CacheUpdate() fonction for user to add his own data to the Streams array and save it inside cache.
Added basic Ogg Skeleton and CMML MetaData handling capability
v1.3f (September 2008)
Corrected a bug for picture size not always accurate.
Corrected a bug for calculating duration with files written as streaming (with
VLC, for an example)
Corrected a bug with the picture extraction when caching is disabled or cache was lost and picture is already existing
Added the option UPDATECACHE to force analysing the file again and rewrite the cache file.
Note: If you use also the cortado java applet, you better use the wikimedia forked version, with cmml-skeleton support and less bugs, as it looks like fluemotion has given up since 2006 on developping and updating their applet. See links below.
v1.3g (November 2008)
Corrected a bug in cache handling