mediamosa_transcode_profile_form

Versions
mediamosa-21
mediamosa_transcode_profile_form($node, $form_state)

Implements hook_form().

Code

sites/all/modules/mediamosa/core/node/mediamosa_node_mediamosa_transcode_profile.inc, line 202

<?php
function mediamosa_transcode_profile_form($node, $form_state) {
  // If we're inserting a new node, set some defaults:
  if (!isset($node->nid)) {
    $node->app_id = 0;
    $node->tool = 'ffmpeg';
    $node->is_default_profile = 'FALSE';
    $node->file_extension = '';
  }

  $form = array();

  $form['required'] = array(
    '#type' => 'fieldset',
    '#title' => t('Transcode profile'),
    '#description' => t('Required parameters for a transcoding profile.'),
  );

  // Get the apps for the drop down listing.
  $apps = _mediamosa_get_apps();

  $form['required'][mediamosa_transcode_profile_db::APP_ID] = array(
    '#title' => t('Application'),
    '#type' => 'select',
    '#default_value' => $node->{mediamosa_transcode_profile_db::APP_ID},
    '#required' => TRUE,
    '#options' => $apps,
    '#description' => t('The application that owns this profile.'),
  );

  $form['required']['title'] = array(
    '#title' => t('Profile name'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#description' => t('The name of this transcode profile.'),
    '#default_value' => mediamosa_node::default_value('title', $node),
    '#maxlength' => mediamosa_transcode_profile_db::PROFILE_LENGTH,
  );

  $form['required'][mediamosa_transcode_profile_db::IS_DEFAULT_PROFILE] = array(
    '#title' => t('Is this the default profile?'),
    '#type' => 'select',
    '#default_value' => mediamosa_node::default_value(mediamosa_transcode_profile_db::IS_DEFAULT_PROFILE, $node),
    '#options' => array(mediamosa_transcode_profile_db::IS_DEFAULT_PROFILE_TRUE => t('Yes'), mediamosa_transcode_profile_db::IS_DEFAULT_PROFILE_FALSE => t('No')),
    '#required' => TRUE,
    '#description' => t('If a transcoding profile is ommited from a transcoding request, the default profile will be choosen.'),
  );

  $form['required'][mediamosa_transcode_profile_db::TOOL] = array(
    '#title' => t('Encoder used'),
    '#type' => 'select',
    '#default_value' => mediamosa_node::default_value(mediamosa_transcode_profile_db::TOOL, $node),
    '#options' => array('ffmpeg' => t('FFMpeg'), 'windows' => t('Windows')),
    '#description' => t('The encoding tool used to perform the transcoding. Currently there are 2 options available: FFMpeg and Windows (used for WMV).'),
    '#required' => TRUE,
  );

  $form['required'][mediamosa_transcode_profile_db::FILE_EXTENSION] = array(
    '#title' => t('File extension'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#description' => t('This file extension is only used for the generated filename, which will be the original filename (minus original extension) plus this extension.'),
    '#default_value' => mediamosa_node::default_value(mediamosa_transcode_profile_db::FILE_EXTENSION, $node),
    '#maxlength' => mediamosa_transcode_profile_db::FILE_EXTENSION_LENGTH,
  );

  if (empty($node->tool)) {
    $node->tool = 'ffmpeg'; // Default.
  }

  $tools = mediamosa_transcode_profile::get_by_tool(NULL, $node->tool)->fetchAll();

  // Comments below items.
  $comments = array(
    'videocodec' => t('Force video codec to codec. Use the copy special value to tell that the raw codec data must be copied as is. If libx264 (h264) is used, be sure to use libfaac audiocodec@default'),
    'videobitrate' => t('Set the video bitrate in bit/s@default'),
    'size' => t('Set frame size using format WIDTHxHEIGHT@default'),
    'qmax' => t('Maximum video quantizer scale (VBR)@default'),
    'fps' => t('Set frame rate (Hz value, fraction or abbereviation@default'),
    'audiosamplingrate' => t('Set the audio sampling frequency@default'),
    'audiocodec' => t('Force audio codec to codec. Use the copy special value to specify that the raw codec data must be copied as is@default'),
    'maintain_aspect_ratio' => t('Force audio codec to codec. Use the copy special value to specify that the raw codec data must be copied as is@default'),
    'audiobitrate' => t('Set the audio bitrate in bit/s@default'),
    'audiochannels' => t('The allowed value is between 0 and 2@default')
  );

  $form['tool_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('@tool parameters', array('@tool' => drupal_ucfirst($node->tool))),
    '#collapsed' => FALSE,
    '#collapsible' => TRUE,
  );

  // Skip these, not changable or internal.
  $tools_to_skip = array(
    'internal_previous_job',
    'internal_file_extension',
    'startposition',
    'duration',
  );

  // Show all parameters for profile.
  foreach ($tools as $key => $tool) {

    // get the name of the parameter.
    $name = $tool[mediamosa_transcode_mapping_db::NICE_PARAMETER];

    if (in_array($name, $tools_to_skip)) {
      continue;
    }

    // Convert the allowed value to array.
    $tool[mediamosa_transcode_mapping_db::ALLOWED_VALUE] = trim($tool[mediamosa_transcode_mapping_db::ALLOWED_VALUE]) == '' ? array() : explode(';', $tool[mediamosa_transcode_mapping_db::ALLOWED_VALUE]);

    // Tool required?
    $is_required = $tool[mediamosa_transcode_mapping_db::REQUIRED] == mediamosa_transcode_mapping_db::REQUIRED_TRUE;

    // Put required higher.
    $weight = $is_required ? 0 : 15;

    // Get the value.
    $value = isset($node->commands{$name}) ? $node->commands{$name} : $tool[mediamosa_transcode_mapping_db::DEFAULT_VALUE];

    $descriptions = array();
    $description = isset($comments[$name]) ? $comments[$name] : '';

    if (!empty($description) && isset($tool[mediamosa_transcode_mapping_db::DEFAULT_VALUE])) {
      $description = strtr($description, array('@default' => ' (default = @value).'));
      $description = strtr($description, array('@value' => $tool[mediamosa_transcode_mapping_db::DEFAULT_VALUE]));
      $descriptions[] = $description;
    }
    elseif (!empty($description)) {
      $descriptions[] = strtr($description, array('@default' => '.'));
    }

    // Get the tool.
    $tool_name = drupal_ucfirst(str_replace('_', ' ', $name));

    if (empty($tool[mediamosa_transcode_mapping_db::ALLOWED_VALUE])) {
      // Add allowed value to description.
      $descriptions[] = t('The allowed value is between @min_value and @max_value.', array('@min_value' => $tool[mediamosa_transcode_mapping_db::MIN_VALUE], '@max_value' => $tool[mediamosa_transcode_mapping_db::MAX_VALUE]));

      $form['tool_options']['options_' . $name] = array(
        '#description' => implode(' ', $descriptions),
        '#type' => 'textfield',
        '#title' => t($tool_name),
        '#required' => $is_required,
        '#default_value' => $value,
        '#size' => 25,
        '#weight' => $weight
      );
    }
    else {// Select box.
      $options = array();
      foreach ($tool[mediamosa_transcode_mapping_db::ALLOWED_VALUE] as $allowed_value) {
        $options[$allowed_value] = $allowed_value;
      }

      $descriptions[] = strtr('Possible values: @options.', array('@options' => implode(', ', $options)));

      $form['tool_options']['options_' . $name] = array(
        '#description' => implode(' ', $descriptions),
        '#type' => 'select',
        '#title' => t($tool_name),
        '#required' => $is_required,
        '#default_value' => $value,
        '#options' => $options,
        '#weight' => $weight,
      );
    }
  }

  return $form;
}
?>