Ver Mensaje Individual
  #5 (permalink)  
Antiguo 23/11/2010, 16:39
Avatar de xcorpion
xcorpion
 
Fecha de Ingreso: octubre-2003
Ubicación: m é x i c o
Mensajes: 676
Antigüedad: 20 años, 6 meses
Puntos: 4
Respuesta: ¿como remover bordes negros en capturas de videos?

Valla, sin querer queriendo encontre en php.net una función que calcula el tamaño del borde negro, si les sirve aca esta: http://www.php.net/manual/en/function.imagecolorat.php

Código PHP:
<?php
    define
("DEBUG_OUT",TRUE);
    
$border_size find_border_size($path);
    
print_r($border_size);
    
/*
     * $border = max(find_border_size("img.jpg"));
     * $thumb_size_x = 180+(2*$border);
     * $thumb_size_y = 240+(2*$border);
     * $thumb_size = $thumb_size_x . "x" . $thumb_size_y; (String to use in the -s param of ffmpeg)
     * $crop_cmd = "-croptop $border -cropbottom $border -cropright $border -cropleft $border";
     */
    
function find_border_size($path)
    {
        
/* The pad var is essentially a 'feather' value. Unless one of the RGB values rises
         * above $pad we are saying to continue. You can try different values but with 10 I
         * would still get a decent sized border due to the bleedover of the movie into
         * the hat.
         */
        
$pad 20;
        
$border_y 0;
        
$border_x 0;

        if(!
file_exists($path))
        {
            if(
DEBUG_OUT) echo("Error: $path not found.\n");
            return 
FALSE;
        }
        else
        {
            if(
DEBUG_OUT) echo("Opening: $path ...\n");
        }
        
$im = @imagecreatefromjpeg($path);
        if(!
$im) return FALSE;
        
$height imagesy($im);
        
$width imagesx($im);

        
/* Let's start at 0, 0 and keep going till we hit a color */
        
if(DEBUG_OUT) echo("Image - Height: $height / Width: $width\n");
        
/* Border Height(Y) */
        
$center_width ceil($width/2);
        for(
$i=0$i<$height$i++)
        {
            
$rgb imagecolorat($im,$center_width,$i);
            
$r = ($rgb >> 16) & 0xFF;
            
$g = ($rgb >> 8) & 0xFF;
            
$b $rgb 0xFF;
            if(
DEBUG_OUT) echo("Height: ($center_width,$i) R: $r / G: $g / B: $b\n");
            if(
$r >= $pad || $g >= $pad || $b >= $pad)
            {
                
$border_y $i;
                if(
$border_y == $height$border_y 0;
                break;
            }
        }

        
/* Border Width(X) */
        
$center_height ceil($height/2);
        for(
$i=0$i<$width$i++)
        {
            
$rgb imagecolorat($im,$i,$center_height);
            
$r = ($rgb >> 16) & 0xFF;
            
$g = ($rgb >> 8) & 0xFF;
            
$b $rgb 0xFF;
            if(
DEBUG_OUT) echo("Width: ($i,$center_width) R: $r / G: $g / B: $b\n");
            if(
$r >= $pad || $g >= $pad || $b >= $pad)
            {
                
$border_x $i;
                if(
$border_x == $width$border_x 0;
                break;
            }
        }

        
/* I am making the border a multiple of 2 since I am sending these values to FFMpeg */
        
if($border_x != 0)
        {
            
$border_x /= 2;
            
$border_x round($border_x);
            
$border_x *= 2;
        }
        if(
$border_y != 0)
        {
            
$border_y /= 2;
            
$border_y round($border_y);
            
$border_y *= 2;
        }
        if(
DEBUG_OUT) echo("Border Width: $border_x / Border Height: $border_y\n");
        return array(
$border_x,$border_y);
    }
?>