About
The MAXON API ALIASES handles media data using Media Sessions. Such a session is used to connect a media source with a media output. This way one can load and save image files and convert media data.
Media Converter
maxon::MediaConverterInterface is the base interface for both maxon::MediaInputInterface and maxon::MediaOutputInterface (see below). It itself is based on:
maxon::MediaConverterInterface itself gives access to data streams. Typically one does not use these functions directly but with a maxon::MediaSessionInterface.
Media Inputs
maxon::MediaInputInterface gives access to the data of a given media source. It is based on maxon::MediaConverterInterface.
Typically one creates a media input by loading a media file. maxon::FileFormatDetectionInterface can be used to get the type of such a media file. Then maxon::FileFormatHandlerInterface::CreateHandler() is used to create a handler to access that media file.
Media Outputs
maxon::MediaOutputInterface allows to write media data into a given destination. It is based on maxon::MediaConverterInterface.
The typical destination is a media file which is represented by the maxon::MediaOutputUrlInterface. An instance can be obtained from the maxon::ImageSaverClasses namespace.
The utility function maxon::MediaSessionImport() can be used to read a media file and to write the data into the given media output.
Also image data can be written into a maxon::ImageTextureInterface. Such a target image is represented as a maxon::MediaOutputTextureInterface:
MediaSessionInterface
The maxon::MediaSessionInterface is used to connect a media input and an output and to perform the desired conversion:
Technical Details
A MediaConverterRef connects media inputs and outputs. The inputs create media streams which can be subscribed by the output. This way the input must only provide the information that is actually needed by the connected output.
Within the converter the media data is handled like this:
Analzye Phase:
- The output's Analyze() function calls all inputs to invoke their Analyze() function (see below). After that it checks all streams provided by the inputs. It searches for a suitable stream or streams and subscribes to it.
- The input's Analyze() function checks the source (e.g. a file) and creates the available media streams (maxon::MediaStreamInterface).
Execution Phase:
- The output's PrepareExecute() function calls the PrepareExecute() function of all inputs.
- The input's PrepareExecute() function checks if any of the created streams are subscribed. If so, a progress job is added (maxon::MediaSessionProgressInterface).
- The output's Execute() function calls the Execute() function of all inputs. Then it reads the media data accessible in the subscribed streams.
- The inputs Execute() function writes all data in the subscribed streams (maxon::MediaStreamPropertiesInterface, maxon::SetPixelHandlerStruct). When done, the progress is updated.
Examples
{
if (url.IsEmpty())
const maxon::FileFormatHandler importFileFormat = maxon::FileFormatDetectionInterface::Detect<maxon::MediaInputRef>(url)
iferr_return;
const maxon::MediaInputRef source = importFileFormat.CreateHandler<maxon::MediaInputRef>(url)
iferr_return;
const maxon::MediaOutputTextureRef destination = maxon::MediaOutputTextureClass().Create()
iferr_return;
destination.SetOutputTexture(targetTexture, maxon::ImagePixelStorageClasses::Normal())
iferr_return;
const maxon::MediaSessionRef session = maxon::MediaSessionObject().Create()
iferr_return;
session.ConnectMediaConverter(source, destination)
iferr_return;
}
{
if (url.IsEmpty() || image.IsEmpty())
const maxon::MediaOutputUrlRef destination = maxon::ImageSaverClasses::Png().Create()
iferr_return;
maxon::MediaSessionRef session = maxon::MediaSessionObject().Create()
iferr_return;
}
{
if (url.IsEmpty() || images.
IsEmpty() || invalidFps)
maxon::DataDictionary exportSettings;
exportSettings.Set(maxon::MEDIASESSION::EXPORT::QUALITY, 1.0)
iferr_return;
const maxon::ImageRef firstImage = images[0];
const maxon::ImageTextureRef source = maxon::ImageTextureClasses::TEXTURE().Create()
iferr_return;
const maxon::ImageRef imageData = firstImage;
source.Set(maxon::IMAGEPROPERTIES::IMAGE::EXPORTSETTINGS, exportSettings)
iferr_return;
const maxon::Id MP4 = maxon::MEDIASESSION::MP4::EXPORT::GetId();
if (correctedSize != inputSize)
{
}
maxon::MediaSessionRef session = maxon::MediaSessionObject().Create()
iferr_return;
for (auto& image : images)
{
currentTime += frameDuration;
}
return session.Close();
}
{
if (folder.IsEmpty() || images.
IsEmpty())
name += "@{2'0'}.png"_s;
sequenceURL.
Set(maxon::URLFLAGS::IMAGESEQUENCE_FIRSTFRAME, firstFrame)
iferr_return;
sequenceURL.
Set(maxon::URLFLAGS::IMAGESEQUENCE_LASTFRAME, lastFrame)
iferr_return;
const maxon::FileFormatHandler imageSequence = maxon::FileFormatHandlers::MovieImageSequence();
const maxon::MediaInputRef source = imageSequence.CreateHandler<maxon::MediaInputRef>(sequenceURL)
iferr_return;
const maxon::ImageTextureRef texture = maxon::ImageTextureClasses::TEXTURE().Create()
iferr_return;
const maxon::MediaOutputTextureRef destination = maxon::MediaOutputTextureClass().Create()
iferr_return;
destination.SetOutputTexture(texture, maxon::ImagePixelStorageClasses::Normal())
iferr_return;
const maxon::MediaSessionRef session = maxon::MediaSessionObject().Create()
iferr_return;
session.ConnectMediaConverter(source, destination)
iferr_return;
for (
maxon::Int frame = 0; frame <= lastFrame; ++frame)
{
currentTime += frameDuration;
}
return session.Close();
}
Further Reading