You are here

public function TranscoderAbstractionFactoryFfmpeg::adminSettingsValidate in Video 7.2

Validate admin settings. This will call when Drupal admin settings validate.

Overrides TranscoderFactoryInterface::adminSettingsValidate

File

transcoders/TranscoderAbstractionFactoryFfmpeg.inc, line 547
File containing class TranscoderAbstractionFactoryFfmpeg

Class

TranscoderAbstractionFactoryFfmpeg
Class that handles FFmpeg transcoding.

Code

public function adminSettingsValidate($form, &$form_state) {
  $v =& $form_state['values'];
  if (!empty($v['video_ffmpeg_path'])) {
    $errorhelp = '';
    if (module_exists('video_ui')) {
      $errorhelp = '<br/>' . t('Visit the <a href="@ffmpeg-debug-page">FFmpeg debug page</a> for information thay may help you find the cause of this problem.', array(
        '@ffmpeg-debug-page' => url('admin/config/media/video/ffmpeg-info', array(
          'query' => array(
            'ffmpegpath' => $v['video_ffmpeg_path'],
          ),
        )),
      ));
    }
    if (!file_exists($v['video_ffmpeg_path']) || !is_executable($v['video_ffmpeg_path'])) {
      form_error($form['ffmpeg']['video_ffmpeg_path'], t('The path @path must point to an executable file.', array(
        '@path' => $v['video_ffmpeg_path'],
      )));
      return;
    }
    $toolkit = new PHPVideoToolkit($v['video_ffmpeg_path']);
    $ffmpeg = $toolkit
      ->getFFmpegInfo(FALSE);
    $ffmpegoravconv = NULL;
    if (!$ffmpeg['ffmpeg-found'] || ($version = self::getVersionFromOutput($ffmpeg['raw'], $ffmpegoravconv)) == NULL) {
      form_error($form['ffmpeg']['video_ffmpeg_path'], t('FFmpeg not found at %path. To convert videos and create thumbnails you have to install FFmpeg on your server. For more information please see the !documentation.' . $errorhelp, array(
        '%path' => $v['video_ffmpeg_path'],
        '!documentation' => l(t('documentation'), 'http://video.heidisoft.com/documentation/ffmpeg-installtion-scripts'),
      )));
    }
    elseif (empty($ffmpeg['codecs']['video']) || empty($ffmpeg['codecs']['audio'])) {
      form_error($form['ffmpeg']['video_ffmpeg_path'], t('FFmpeg version %version was found, but no supported codecs could be found. Please check whether FFmpeg and all support libraries have been installed correctly.' . $errorhelp, array(
        '%version' => $version,
      )));
    }
    else {
      drupal_set_message(t('%ffmpegoravconv version %version found on your system.', array(
        '%version' => $version,
        '%ffmpegoravconv' => $ffmpegoravconv,
      )), 'status');
    }

    // Clear FFmpeg information when the path has changed.
    cache_clear_all(self::INFO_CID, self::INFO_CACHE);
  }
  if (!empty($v['video_ffmpeg_qtfaststart_path'])) {
    if (!is_file($v['video_ffmpeg_qtfaststart_path'])) {
      form_error($form['ffmpeg']['helpers']['video_ffmpeg_qtfaststart_path'], t('The file %file does not exist.', array(
        '%file' => $v['video_ffmpeg_qtfaststart_path'],
      )));
    }
  }
  if (!empty($v['video_ffmpeg_flvtool2_path'])) {
    if (!is_file($v['video_ffmpeg_flvtool2_path'])) {
      form_error($form['ffmpeg']['helpers']['video_ffmpeg_flvtool2_path'], t('The file %file does not exist.', array(
        '%file' => $v['video_ffmpeg_flvtool2_path'],
      )));
    }
  }
}