nystudio107 / craft-transcoder

Transcode video & audio files to various formats, and provide video thumbnails
https://nystudio107.com/plugins/transcoder
Other
43 stars 12 forks source link

[FR] Feature request: add watermark to video #6

Open arifje opened 6 years ago

arifje commented 6 years ago

Sorry for the feature-request-spamming, got another idea for this great addon. We could definately use a watermark function! :-)

I used to have a script that added a watermark on top left, right or bottom left/right, and used different images for different video dimensions, so the size of the watermark was also in ratio with the size of the video.

So, it you let users upload these images, define the path and position in config (or as parameters!) it should be easy to implement. I'm sure you know how this all works, but here's a part of the code/idea. Maybe it will help you.

/ -----------------------------------------------
// video specs 
// -----------------------------------------------

$height = $video_data['height'];         
$width = $video_data['width'];   

// -----------------------------------------------
// determine logo dimension 
// -----------------------------------------------

$logo_1080 = '/path/to/logo_1080.png';
// etc.

if ($width >= 1900) {
    $logo_argument = $logo_1080;
} elseif ($width >= 1100 ) {
    $logo_argument = $logo_720;
} elseif ($width >= 800 ) {             
    $logo_argument = $logo_480;
} elseif ($width >= 600 ) {
    $logo_argument = $logo_360; 
} elseif ($width >= 350 || $width <= 380) { 
    $logo_argument = $logo_240;                       

// ----------------------------------------------
// logo offset                  
// ----------------------------------------------

$position = ' ';        

// increase offset for bigger videos (preseve offset ratio)

if($logo_offset_x > 0) {

    if ($width >= 1900) $logo_offset_x *= 5; // 1080p
    elseif ($width >= 1100 ) $logo_offset_x *= 3.5; // 720p
    elseif ($width >= 800 ) $logo_offset_x *= 2.5; // 480p
    elseif ($width >= 600 ) $logo_offset_x *= 2; // 360p
    elseif ($width >= 350 || $width <= 380) $logo_offset_x *=1; // 240p
}

if($logo_offset_y > 0) {       
    if ($width >= 1900) $logo_offset_y *= 5; // 1080p
    elseif ($width >= 1100 ) $logo_offset_y *= 3.5; // 720p
    elseif ($width >= 800 ) $logo_offset_y *= 2.5; // 480p
    elseif ($width >= 600 ) $logo_offset_y *= 2; // 360p
    elseif ($width >= 350 || $width <= 380) $logo_offset_y *=1; // 240p
}

$debug_string .= "[INFO] logo offset: " . $logo_offset_x . "/" . $logo_offset_y . "\n";

// ----------------------------------------------
// logo position
// ----------------------------------------------

$position = ' ';

switch($logo_position) {

    case 'top_left':
        $position = 'overlay=' . $logo_offset_x . ':' . $logo_offset_y;
    break;

    case 'top_right':       
        $position = 'overlay=main_w-overlay_w-' . $logo_offset_x . ':' . $logo_offset_y;
    break;

    case 'bottom_left': 
        $position = 'overlay=' . $logo_offset_x . ':main_h-overlay_h-' . $logo_offset_y;
    break;

    case 'bottom_right':
        $position = 'overlay=main_w-overlay_w-' . $logo_offset_x . ':main_h-overlay_h-' . $logo_offset_y;
    break;

    case 'center_middle':
        $position = 'overlay=main_w/2-overlay_w/2:main_h/2-overlay_h/2';
    break;

    default: 
        $position = 'overlay=main_w-overlay_w-' . $logo_offset_x . ':' . $logo_offset_y;
}   

// $position string is then added to the ffmpeg encode string / command
// example;  [watermark]; [in] [watermark] ' . $position . '

Cheers!

khalwat commented 6 years ago

Ah great, yeah for sure adding a watermark is very doable!

arifje commented 5 years ago

Hi mate, any chance these features will be integrated soon? Project seems a little bit quiet :-(

Thanks!

khalwat commented 5 years ago

It's a little quiet because thankfully, there haven't been many bug reports, so we're left with enhancements/feature requests.

My plan is to finish porting Retour, and then circle back and look at FRs for plugins like this one.

arifje commented 5 years ago

Cool, thanks. And maybe you can look into the my recent pull request: https://github.com/nystudio107/craft-transcoder/pull/7 :-)

Thanks!!