<?php
/***************************************************************************
 *                              ffmpeg.php
 *                            -------------------
 *  Полнлценный модуль Файлобменника под phpBB-WAP
 *	Автор модуля: SatanHell
 *  2011 год
 ***************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = '../';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_obmen.'.$phpEx);
$id = isset($_REQUEST['id']) ? abs(intval($_REQUEST['id'])) : false;
if(class_exists('ffmpeg_movie'))
{
	$sql = "SELECT*FROM `" . UPLOAD_FILES_TABLE . "` WHERE `file_id`='".$id."'";
if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get upload_files information', '', __LINE__, __FILE__, $sql);
	}
$last = $db->sql_fetchrow($result);
$file = '../upload/'.$last['file_url'];

if(file_exists($file))
{
$mov = new ffmpeg_movie($file);
}
else
{
die('файл не найден');
}

$wn = $mov->GetFrameWidth();
$hn = $mov->GetFrameHeight();

$frame = 70;

$ff_frame = $mov->getFrame($frame);

if($ff_frame)
{
$gd_image = $ff_frame->toGDImage();

if($gd_image)
{
switch(trim($_GET['type']))
{
default:
$k = ($wn > $hn) ? $wn/128 : $hn/128;

$w = round($wn/$k);
$h = round($hn/$k);
$copy = true;
break;

case'small':
$w = 40;
$h = 40;
$copy = false;
break;
}

$new = imageCreateTrueColor($w, $h);
imageCopyResampled($new, $gd_image, 0, 0, 0, 0, $w, $h, $wn, $hn);
$marcer_movie = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['server_name']));
if($copy)
{
imagettftext($new, 15, 10, ceil(round($w/6)), ceil(round($h/2)), imagecolorallocate($new, 0, 0, 0), 'tahoma.ttf', $marcer_movie);
}

header('Content-type: image/gif');
imageGif($new);
}
else
{
die('невозможно сделать скриншот');
}
}
else
{
die('невозможно извлечь кадр');
}
}
?>