libgpac
Documentation of the core library of GPAC
python.libgpac.libgpac.FileIO Class Reference

FileIO object for file IO callbacks from libgpac. More...

Public Member Functions

def __init__ (self, url, obj)
 constructor for FileIO More...
 

Data Fields

 url
 the underlying gfio:// URL to be provided to GPAC More...
 

Detailed Description

The FileIO object is used to create input or output interfaces in which GPAC will read or write. This allows generating content in python without any disk IO, or passing python data as input to GPAC without intermediate file.

This object passed to the FileIO constructor must implement the following callbacks:

boolean open(string URL, string mode)

Opens the file in read or write mode.

  • URL: string containing file to open
  • mode: open mode (same as fopen)
  • return true if success, false otherwise
Note
There is no guarantee that the URL is checked for existence before calling open
There is no guarantee that the first call to open is on the URL provided for the constructor (e.g. for DASH generation, this will depend on the DASH profile used which may require to write the manifest after one or more segments)
void close()
def close()
close libgpac - see gf_sys_close
Definition: libgpac.py:359

Closes the file

int write(numpy buffer, unsigned long size)

Writes the file

  • buffer: numpy array to fill if numpy support, ctypes.c_ubyte otherwise
  • size: number of bytes to write starting from first byte in buffer
  • return number of bytes writen, at most the size of the array
int read(numy buffer, unsigned long size)

Reads the file

  • buffer: numpy array to read if numpy support, ctypes.c_ubyte otherwise
  • size: number of bytes to read
  • return number of bytes read, at most the size of the array
void seek(unsigned long long pos, int whence)

Seeks current position in file (same as fopen)

  • pos: position
  • whence: origin of the position
  • return 0 if no error, error code otherwise
unsigned long long tell()

Gets current position in file (same as ftell)

  • pos: position
  • return current position
boolean eof()

Checks if the current position is at the end of the file (same as feof)

  • return true if file end reached, false otherwise
boolean exists(string URL)

Checks if the given URL exists. This callback is optional

  • return true if associated URL exists, false otherwise
Warning
All these callbacks MUST perform synchronously

The URL passed to the constructor indentifies the file name wrapped. Some file types such as HLS or DASH manifest may imply reading or writing several files. To handle these cases, the object passed to the constructor will be cloned for each call to open().

Warning
This object is a shallow copy of the factory object, not an empty object (difference with NodeJS bindings).

All FileIO callbacks will be done in the main thread.

Constructor & Destructor Documentation

◆ __init__()

def python.libgpac.libgpac.FileIO.__init__ (   self,
  url,
  obj 
)
Parameters
urlurl for this fileIO factory
objinstance of the class used for IOs. This instance will be cloned (shallow copy) for each new file to open

Field Documentation

◆ url

python.libgpac.libgpac.FileIO.url