Skip to content

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

Description

@arifje

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions