static function GetEncodedTime($logfile) { if (!file_exists($logfile)) { transcode::log("can't open FFMPEG-Log '" . $logfile . "'"); return false; } else { $FFMPEGLog = @file_get_contents($logfile); $dPos = strpos($FFMPEGLog, " Duration: "); self::$duration = self::durationToSecs(substr($FFMPEGLog, $dPos + 11, 11)); $FFMPEGLog = str_replace("\r", "\n", $FFMPEGLog); $lines = explode("\n", $FFMPEGLog); $line = $lines[count($lines) - 2]; if ($tpos = strpos($line, "time=")) { $bpos = strpos($line, " bitrate="); $time = substr($line, $tpos + 5, $bpos - ($tpos + 5)); return $time; } else { return false; } } }
static function item_created($item) { if ($item->is_movie()) { transcode::log("Item created - is a movie. Let's create a transcode task or 2.."); $ffmpegPath = module::get_var("transcode", "ffmpeg_path"); $fileObj = self::_getVideoInfo($item->file_path()); transcode::log($fileObj); // Save our needed variables $srcFile = $item->file_path(); $srcWidth = transcode::makeMultipleTwo($fileObj->video->width); $srcHeight = transcode::makeMultipleTwo($fileObj->video->height); $aspect = $srcWidth / $srcHeight; $srcFPS = $fileObj->video->fps; $srcAR = $fileObj->audio->samplerate; if ($srcAR > 44100) { $srcAR = 44100; } $accepted_sample_rates = array(11025, 22050, 44100); if (!in_array($srcAR, $accepted_sample_rates)) { // if the input sample rate isn't an accepted rate, find the next lowest rate that is $below = true; $rate = 0; if ($srcAR < 11025) { $rate = 11025; } else { foreach ($accepted_sample_rates as $r) { transcode::log("testing audio rate '" . $r . "' against input rate '" . $srcAR . "'"); if ($r < $srcAR) { $rate = $r; } } } $srcAR = $rate; } $srcACodec = module::get_var("transcode", "audio_codec"); $heights = array(); if (module::get_var("transcode", "resolution_240p")) { array_push($heights, 240); } if (module::get_var("transcode", "resolution_360p")) { array_push($heights, 360); } if (module::get_var("transcode", "resolution_480p")) { array_push($heights, 480); } if (module::get_var("transcode", "resolution_576p")) { array_push($heights, 576); } if (module::get_var("transcode", "resolution_720p")) { array_push($heights, 720); } if (module::get_var("transcode", "resolution_1080p")) { array_push($heights, 1080); } if (!is_dir(VARPATH . "modules/transcode/flv/" . $item->id)) { @mkdir(VARPATH . "modules/transcode/flv/" . $item->id); } $xtraFlags = module::get_var("transcode", "ffmpeg_flags", ""); foreach ($heights as $destHeight) { transcode::log("srcHeight: " . $srcHeight . ", destheight: " . $destHeight); // don't bother upscaling, there's no advantage to it... if ($destHeight > $srcHeight) { continue; } $destFormat = module::get_var("transcode", "format", "flv"); $destWidth = floor($destHeight * $aspect); if ($destWidth % 2) { $destWidth = ceil($destHeight * $aspect); } transcode::log("destination resolution: " . $destWidth . "x" . $destHeight); $destFile = VARPATH . "modules/transcode/flv/" . $item->id . "/" . $destWidth . "x" . $destHeight . ".flv"; switch ($destHeight) { case 240: $destVB = 128; $srcAB = 16 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 360: $destVB = 384; $srcAB = 16 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 480: $destVB = 1024; $srcAB = 32 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 576: $destVB = 2048; $srcAB = 32 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 720: $destVB = 4096; $srcAB = 64 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; case 1080: $destVB = 8192; $srcAB = 64 * ($fileObj->audio->channels ? $fileObj->audio->channels : 2); break; } $destVB *= 1024; $srcAB *= 1024; $cmd = $ffmpegPath . " " . "-i \"" . $srcFile . "\" "; if ($fileObj->audio->has) { $cmd .= "-y -acodec " . $srcACodec . " " . "-ar " . $srcAR . " " . "-ab " . $srcAB . " "; } else { $cmd .= "-an "; } $cmd .= "-vb " . $destVB . " " . "-f " . $destFormat . " " . "-s " . $destWidth . "x" . $destHeight . " " . $xtraFlags . " " . "\"" . $destFile . "\""; transcode::log($cmd); $task_def = Task_Definition::factory()->callback("transcode_task::transcode")->name("Video Transcode to " . $destWidth . "x" . $destHeight)->severity(log::SUCCESS); $task = task::create($task_def, array("ffmpeg_cmd" => $cmd, "width" => $destWidth, "height" => $destHeight, "item_id" => $item->id)); task::run($task->id); } } }