You are here

function zencoder_add_job in Video 6.3

File

plugins/zencoder.inc, line 284
Provide a api for video conversion and auto thumbnailing using ffmpeg.

Code

function zencoder_add_job($file) {

  // Make sure this points to a copy of Zencoder.php on the same server as this script.
  //  require_once("../lib/zencoder/Zencoder.php");
  require_once dirname(__FILE__) . '/../lib/zencoder/Zencoder.php';

  // API Key
  $api_key = variable_get('zencoder_api_key', "");

  // File details
  $filename = $file->name;

  // Bucket
  $bucket = variable_get('s3_api_bucket', '');

  // New Encoding Job

  //28022009063.mp4

  //    "input": "s3://' . $bucket . '/' . $filename . '"
  //    "input": "s3://heidi_test/28022009063.mp4"
  // Get varialbes
  $lable = $filename;
  $base_url = $folder;
  $filename = $filename;
  $width = variable_get('zc_width', '');
  $height = variable_get('zc_height', '');
  $quality = variable_get('zc_quality', 3);
  $speed = variable_get('zc_speed', 3);
  $upscale = variable_get('zc_upscale', '');
  $stretch = variable_get('zc_stretch', '');
  $frame_rate = variable_get('zc_frame_rate', '');
  $max_frame_rate = variable_get('zc_max_frame_rate', '');
  $keyframe_interval = variable_get('zc_key_frame_interval', '');
  $video_bitrate = variable_get('zc_vid_bit_rate', '');
  $bitrate_cap = variable_get('zc_bit_rate_cap', '');
  $buffer_size = variable_get('zc_buffer_size', '');
  $h264_profile = variable_get('zc_h245_profile', 1);
  $h264_level = variable_get('zc_h245_level', 0);
  $skip_video = variable_get('zc_skip_video', '');
  $audio_codec = variable_get('zc_audio_codec', 'aac');
  $audio_bitrate = variable_get('zc_audio_bitrate', '');
  $audio_channels = variable_get('zc_audio_channels', 2);
  $audio_sample_rate = variable_get('zc_audio_sample_rate', '');
  $skip_audio = variable_get('zc_skip_audio', '');
  $thumn_no = $thumds;
  $thumb_size = $size;
  $thumb_base = $baseurl;
  $thumb_prefix = $filename;
  $notify_url = variable_get('zc_notify_url', '');
  $notify_email = variable_get('zc_notify_email', '');
  $start_clip = variable_get('zc_start_clip', '');
  $clip_length = variable_get('zc_clip_length', '');
  $encoding_job = new ZencoderJob('
{
  "input":"s3://heidi_test/28022009063.mp4",
  "output":[{
      "label":"web",
      "base_url":"s3://heidi_test",
      "filename":"28022009063.mp4.flv",
      "width":400,
      "height":600,
      "quality":3,
      "speed":3,
      "upscale":1,
      "stretch":1,
      "frame_rate":1100,
      "max_frame_rate":2100,
      "keyframe_interval":2,
      "video_bitrate":20000,
      "bitrate_cap":32,
      "buffer_size":700,
      "h264_profile":"baseline",
      "h264_level":5,
      "skip_video":1,
      "audio_codec":"mp3",
      "audio_bitrate":123,
      "audio_channels":2,
      "audio_sample_rate":2344,
      "skip_audio":1,
      "thumbnails":{
        "number":5,
        "size":"128X128",
        "base_url":"s3://heidi_test",
        "prefix":"zc_thumb"
      },
      "notifications":[
        "http://locahost.com",
        "heshanmw@gmail.com"
      ],
      "start_clip":3,
      "clip_length":23
    }
  ],
  "api_key":"' . $api_key . '"
}');

  // Check if it worked
  if ($encoding_job->created) {

    // Success
    //    echo "w00t! \n\n";
    //    echo "Job ID: ".$encoding_job->id."\n";
    //    echo "Output '".$encoding_job->outputs["web"]->label."' ID: ".$encoding_job->outputs["web"]->id."\n";
    // Store Job/Output IDs to update their status when notified or to check their progress.
  }
  else {

    // Failed
    //    echo "Fail :(\n\n";
    //    echo "Errors:\n";
    foreach ($encoding_job->errors as $error) {

      //      echo $error."\n";
      watchdog('video_render', $error);
    }
  }
}