Transcoder Plugins

Transcoder Plugins can be used to transcode item shapes using external third party transcoders. A transcoder plugin nees only a single method that accepts a single argument; an instance of portal.transcode_framework.utils.TranscodeJobHelper

This is a skeleton for a transcoder plugin:

from portal.pluginbase.core import TranscoderPlugin, implements


class ExampleTranscoderPlugin(TranscoderPlugin):
    plugin_guid = "b51ba6b3-d9f9-40f9-9d5b-e7a1ac6bd03b"

def __init__(self):
    # Name of the plugin. Must be unique.
    self.name = "External transcoder plugin"

    # The name of a Django view as defined in urls.py used to create a new instance of the plugin.
    # Optional if the plugin does not have any settings that can be altered.
    self.create_view = "external_transcoder_plugin_new"

    # The name of a Django view used to update the settings of an instance of the plugin.
    # The view takes one argument, shapetagname, which is the name of the shape tag
    # associated with the plugin instance.
    # Optional if the plugin does not have any settings that can be altered.
    self.update_view = "external_transcoder_plugin"
    # This is the role Cantemo will validate against when transcoding
    # They can be custom roles created for the transcode plugin or reused already existing Cantemo roles
    self.role = 'custom_transcode_role'

def __call__(self, helper):
    """
    This method performs the actual transcoding.
    The helper argument is an instance of TranscodeJobHelper
    """

    # get the source VSShape to transcode from
    source_shape = helper.getSourceShape()

    # if this plugin instance has any settings that can be altered,
    # the values can be retrieved through the helper
    value = helper.get("name_of_setting")

    # do some transcoding...
    # update transcode progress
    helper.setJobProgress(61)

    # import the result
    helper.importTargetShape(file_path=path_to_transcoded_file, storage_id=id_of_storage)

transcoderplugin = ExampleTranscoderPlugin()

If the plugin requires settings this is how such a settings view might look. The PluginSettings class is a dictionary-like class that saves all of its properties to the shape-tag identified by shapetagname, and an instance of PluginSettings can be found in the PluginHelper object that is provided to the plugin:

from django.shortcuts import redirect
from django import forms
from portal.generic.baseviews import ClassView
from portal.transcode_framework.utils import PluginSettings

class WatchfolderTranscoderView(ClassView):
   def __call__(self):
       shapetagname = self.kwargs.get("shapetagname", None)

       if self.request.method == "GET":
           # edit existing configuration
           if shapetagname:
               # the first argument of PluginSettings must match the name of the plugin
               settings = PluginSettings("External transcoder plugin", shapetagname, self.request.user)
               form = ConfigurationForm(settings)
               return self.main(self.request,
                                template_name="ext_transcoder_plugin/configuration.html",
                                extra_context={"shapetagname": shapetagname,
                                               "pluginname": "External transcoder plugin",
                                               "form": form})

           # new plugin instance
           form = ConfigurationForm()
           return self.main(self.request,
                            template_name="ext_transcoder_plugin/configuration.html",
                            extra_context={"pluginname": "External transcoder plugin",
                                           "form": form})

       if self.request.method == "POST":
           form = ConfigurationForm(self.request.POST)
           if not form.is_valid():
               return self.main(self.request,
                                template_name="ext_transcoder_plugin/configuration.html",
                                extra_context={"shapetagname": shapetagname,
                                               "pluginname": "External transcoder plugin",
                                               "form": form})

           if not shapetagname:
               shapetagname = form.cleaned_data["profile_name"]

           settings = PluginSettings(PLUGIN_NAME, shapetagname, self.request.user, form.cleaned_data)
           if not settings.save():
               raise Exception()
           return redirect("watchfolder_transcoder_plugin", shapetagname)


class ConfigurationForm(forms.Form):

   # form fields
   profile_name = forms.CharField(help_text="Profile name", required=True)
   some_setting = forms.CharField(help_text="Value", required=True)

Error handling

If an exception occurs in the plugin, the corresponding Vidispine job will fail, and the stacktrace will be saved to the metadata field _portalException in the job.

Additionally, an error message can be set in the plugin using:

helper.setErrorMessage("Transcoding failed because of reason.")

This error will be displayed to the user on the Cantemo job page, and the error message will also be included in the _portalError metadata field.

ITranscoderPlugin

class portal.generic.plugin_interfaces.ITranscoderPlugin

A plugin interface for dispatching transcode jobs to an external transcoder.

Requires: * __call__(helper)

Args: * helper - an instance of portal.transcode_framework.utils.TranscodeJobHelper

Returns * None

TranscodeJobHelper

class portal.transcode_framework.utils.TranscodeJobHelper(transcode_job, transcode_preset)

Helper object containing useful methods and properties.

PluginSettings

class portal.transcode_framework.utils.PluginSettings(plugin_name, shape_tag_name, user, settings=None)

Note

Remember to include roles for your plugin