12 Replies - 439 Views - Last Post: 01 May 2019 - 02:59 PM Rate Topic: -----

#1 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Help with adding the watermark again to the video

Posted 29 April 2019 - 04:34 PM

The web video script that I'm using, and trying to modify, works successfully integrating a watermark in the upper left corner of the video file, (so that when it's downloaded, the watermark stays on the video). In the ffmpeg php file code below, the watermarking starts with this line:

$watermark_image_full_path = "watermark.png";



at line 275 (out of 504 - about halfway).

I am wondering if there might be a way to make the watermark also display briefly in another location on the video again, maybe halfway through, when playing it.

<?php
if (IS_LOGGED == false || $pt->config->upload_system != 'on') {
    $data = array(
        'status' => 400,
        'error' => 'Not logged in'
    );
    echo json_encode($data);
    exit();
} else if ($pt->config->ffmpeg_system != 'on') {
    $data = array(
        'status' => 402
    );
    echo json_encode($data);
    exit();
} else {
    $getID3    = new getID3;
    $featured  = ($user->is_pro == 1) ? 1 : 0;
    $filesize  = 0;
    $error     = false;


if (PT_IsAdmin() && !empty($_POST['is_movie']) && $_POST['is_movie'] == 1) {
    if (empty($_POST['movie_title']) || empty($_POST['movie_description']) || empty($_FILES["movie_thumbnail"]) || empty($_POST['stars']) || empty($_POST['producer']) || empty($_POST['country']) || empty($_POST['quality']) || empty($_POST['rating']) || !is_numeric($_POST['rating']) || $_POST['rating'] < 1 || $_POST['rating'] > 10 || empty($_POST['release']) || empty($_POST['category']) || !in_array($_POST['category'], array_keys($pt->movies_categories))) {
        $error = $lang->please_check_details;
    }
    // $cover = getimagesize($_FILES["movie_thumbnail"]["tmp_name"]);
    // if ($cover[0] > 400 || $cover[1] > 570) {
    //     $error = $lang->cover_size;
    // }
}
else{
    $request   = array();
    $request[] = (empty($_POST['title']) || empty($_POST['description']));
    $request[] = (empty($_POST['tags']) || empty($_POST['video-thumnail']));
    if (in_array(true, $request)) {
        $error = $lang->please_check_details;
    } else if (empty($_POST['video-location'])) {
        $error = $lang->video_not_found_please_try_again;
    } else if (($pt->config->sell_videos_system == 'on' && $pt->config->who_sell == 'pro_users' && $pt->user->is_pro) || ($pt->config->sell_videos_system == 'on' && $pt->config->who_sell == 'users') || ($pt->config->sell_videos_system == 'on' && $pt->user->admin)) {
        if (!empty($_POST['set_p_v']) || $_POST['set_p_v'] < 0) {
            if (!is_numeric($_POST['set_p_v']) || $_POST['set_p_v'] < 0 || (($pt->config->com_type == 0 && $_POST['set_p_v'] <= $pt->config->admin_com_sell_videos)) ) {
                $error = $lang->video_price_error." ".($pt->config->com_type == 0 ? $pt->config->admin_com_sell_videos : 0);
            }
        }
    } else {
        $request   = array();
        $request[] = (!in_array($_POST['video-location'], $_SESSION['uploads']['videos']));
        $request[] = (!in_array($_POST['video-thumnail'], $_SESSION['ffempg_uploads']));
        $request[] = (!file_exists($_POST['video-location']));
        if (in_array(true, $request)) {
            $error = $lang->error_msg;
        }
    }
}
    if (empty($error)) {
        $file = $duration_file     = $getID3->analyze($_POST['video-location']);
        $duration = '00:00';
        if (!empty($file['playtime_string'])) {
            $duration = PT_Secure($file['playtime_string']);
        }
        if (!empty($file['filesize'])) {
            $filesize = $file['filesize'];
        }
        $video_res = (!empty($file['video']['resolution_x'])) ? $file['video']['resolution_x'] : 0;
        $video_id        = PT_GenerateKey(15, 15);
        $check_for_video = $db->where('video_id', $video_id)->getValue(T_VIDEOS, 'count(*)');
        if ($check_for_video > 0) {
            $video_id = PT_GenerateKey(15, 15);
        }
        if (PT_IsAdmin() && !empty($_POST['is_movie']) && $_POST['is_movie'] == 1) {
            $thumbnail = 'upload/photos/thumbnail.jpg';
            if (!empty($_FILES['movie_thumbnail']['tmp_name'])) {
                $file_info   = array(
                    'file' => $_FILES['movie_thumbnail']['tmp_name'],
                    'size' => $_FILES['movie_thumbnail']['size'],
                    'name' => $_FILES['movie_thumbnail']['name'],
                    'type' => $_FILES['movie_thumbnail']['type']
                );
                $file_upload = PT_ShareFile($file_info);
                $thumbnail = PT_Secure($file_upload['filename'], 0);
                // if (!empty($file_upload['filename'])) {
                //     $thumbnail = PT_Secure($file_upload['filename'], 0);
                //     $upload = PT_UploadToS3($thumbnail);
                // }
            }
        }
        else{
            $thumbnail = PT_Secure($_POST['video-thumnail'], 0);
            if (file_exists($thumbnail)) {
                $upload = PT_UploadToS3($thumbnail);
            }
        }

    $category_id = 0;
    $convert     = true;
    $thumbnail   = substr($thumbnail, strpos($thumbnail, "upload"), 120);
    // ******************************
    if (PT_IsAdmin() && !empty($_POST['is_movie']) && $_POST['is_movie'] == 1) {

        $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
        $i          = 0;
        preg_match_all($link_regex, PT_Secure($_POST['movie_description']), $matches);
        foreach ($matches[0] as $match) {
            $match_url            = strip_tags($match);
            $syntax               = '[a]' . urlencode($match_url) . '[/a]';
            $_POST['movie_description'] = str_replace($match, $syntax, $_POST['movie_description']);
        }
        $data_insert = array(
            'title' =>  PT_Secure($_POST['movie_title']),
            'category_id' => PT_Secure($_POST['category']),
            'stars' => PT_Secure($_POST['stars']),
            'producer' => PT_Secure($_POST['producer']),
            'country' => PT_Secure($_POST['country']),
            'movie_release' => PT_Secure($_POST['release']),
            'quality' => PT_Secure($_POST['quality']),
            'duration' => $duration,
            'description' => PT_Secure($_POST['movie_description']),
            'rating' => PT_Secure($_POST['rating']),
            'is_movie' => 1,
            'video_id' => $video_id,
            'converted' => '2',
            'size' => $filesize,
            'thumbnail' => $thumbnail,
            'user_id' => $user->id,
            'time' => time(),
            'registered' => date('Y') . '/' . intval(date('m'))
        );
        if (!empty($_POST['buy_price']) && is_numeric($_POST['buy_price']) && $_POST['buy_price'] > 0) {
            $data_insert['sell_video'] = PT_Secure($_POST['buy_price']);
        }
    }
    else{
        $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
        $i          = 0;
        preg_match_all($link_regex, PT_Secure($_POST['description']), $matches);
        foreach ($matches[0] as $match) {
            $match_url            = strip_tags($match);
            $syntax               = '[a]' . urlencode($match_url) . '[/a]';
            $_POST['description'] = str_replace($match, $syntax, $_POST['description']);
        }

        if (!empty($_POST['category_id'])) {
            if (in_array($_POST['category_id'], array_keys(get_object_vars($pt->categories)))) {
                $category_id = PT_Secure($_POST['category_id']);
            }
        }
        $video_privacy = 0;
        if (!empty($_POST['privacy'])) {
            if (in_array($_POST['privacy'], array(0, 1, 2))) {
                $video_privacy = PT_Secure($_POST['privacy']);
            }
        }
        $age_restriction = 1;
        if (!empty($_POST['age_restriction'])) {
            if (in_array($_POST['age_restriction'], array(1, 2))) {
                $age_restriction = PT_Secure($_POST['age_restriction']);
            }
        }
        $sub_category = 0;

        if (!empty($_POST['sub_category_id'])) {
            $is_found = $db->where('type',PT_Secure($_POST['category_id']))->where('lang_key',PT_Secure($_POST['sub_category_id']))->getValue(T_LANGS,'COUNT(*)');
            if ($is_found > 0) {
                $sub_category = PT_Secure($_POST['sub_category_id']);
            }
        }

        $continents_list = array();
        if (!empty($_POST['continents-list'])) {

            foreach ($_POST['continents-list'] as $key => $value) {
                if (in_array($value, $pt->continents)) {
                    $continents_list[] = $value;
                }
            }
        }
        $data_insert = array(
            'video_id' => $video_id,
            'user_id' => $user->id,
            'title' => PT_Secure($_POST['title']),
            'description' => PT_Secure($_POST['description']),
            'tags' => PT_Secure($_POST['tags']),
            'duration' => $duration,
            'video_location' => '',
            'category_id' => $category_id,
            'thumbnail' => $thumbnail,
            'time' => time(),
            'registered' => date('Y') . '/' . intval(date('m')),
            'featured' => $featured,
            'converted' => '2',
            'size' => $filesize,
            'privacy' => $video_privacy,
            'age_restriction' => $age_restriction,
            'sub_category' => $sub_category,
            'geo_blocking' => (!empty($continents_list) ? json_encode($continents_list) : '')
        );
        if (!empty($_POST['set_p_v']) && is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > 0) {
            $data_insert['sell_video'] = PT_Secure($_POST['set_p_v']);
        }
        if ( ($pt->config->approve_videos == 'on' && !PT_IsAdmin()) || ($pt->config->auto_approve_ == 'no' && $pt->config->sell_videos_system == 'on' && !PT_IsAdmin() && !empty($data_insert['sell_video'])) ) {
            $data_insert['approved'] = 0;
        }
    }
    // ******************************
    $insert      = $db->insert(T_VIDEOS, $data_insert);

    if ($insert) {
        $delete_files = array();
        if (!empty($_SESSION['ffempg_uploads'])) {
            if (is_array($_SESSION['ffempg_uploads'])) {
                foreach ($_SESSION['ffempg_uploads'] as $key => $file) {
                    if ($thumbnail != $file) {
                        $delete_files[] = $file;
                        unset($_SESSION['ffempg_uploads'][$key]);
                    }
                }
            }
        }
        if (!empty($delete_files)) {
            foreach ($delete_files as $key => $file2) {
                unlink($file2);
            }
        }
        if (isset($_SESSION['ffempg_uploads'])) {
            unset($_SESSION['ffempg_uploads']);
        }
        $data = array(
            'status' => 200,
            'video_id' => $video_id,
            'link' => PT_Link("watch/$video_id")
        );
        ob_end_clean();
        header("Content-Encoding: none");
        header("Connection: close");
        ignore_user_abort();
        ob_start();
        header('Content-Type: application/json');
        echo json_encode($data);
        $size = ob_get_length();
        header("Content-Length: $size");
        ob_end_flush();
        flush();
        session_write_close();
        if (is_callable('fastcgi_finish_request')) {
            fastcgi_finish_request();
        }

        if ($pt->config->queue_count > 0) {
            $process_queue = $db->getValue(T_QUEUE,'video_id',$pt->config->queue_count);
        }

        if ( (count($process_queue) < $pt->config->queue_count  && !in_array($video_id, $process_queue)) ||  $pt->config->queue_count == 0) {
            if ($pt->config->queue_count > 0) {
                $db->insert(T_QUEUE, array('video_id' => $insert,
                               'video_res' => $video_res,
                               'processing' => 2));
            }

            $ffmpeg_b                   = $pt->config->ffmpeg_binary_file;
            $filepath                   = explode('.', $_POST['video-location'])[0];
            $time                       = time();
            $full_dir                   = str_replace('ajax', '/', __DIR__);

            $video_output_full_path_240 = $full_dir . $filepath . "_240p_converted.mp4";
            $video_output_full_path_360 = $full_dir . $filepath . "_360p_converted.mp4";
            $video_output_full_path_480 = $full_dir . $filepath . "_480p_converted.mp4";
            $video_output_full_path_720 = $full_dir . $filepath . "_720p_converted.mp4";
            $video_output_full_path_1080 = $full_dir . $filepath . "_1080p_converted.mp4";
            $video_output_full_path_2048 = $full_dir . $filepath . "_2048p_converted.mp4";
            $video_output_full_path_4096 = $full_dir . $filepath . "_4096p_converted.mp4";

            $video_file_full_path       = $full_dir . $_POST['video-location'];


            $watermark_image_full_path = "watermark.png";


            // demo Video
            $video_time = '';
            $demo_video = '';
            if ($pt->config->demo_video == 'on' && !empty($data_insert['sell_video'])) {
                $have_demo = false;
                if (!empty($duration_file['playtime_seconds']) && $duration_file['playtime_seconds'] > 0) {
                    $video_time = round((10 * round($duration_file['playtime_seconds'],0)) / 100,0);
                    $video_time = '-t '.$video_time.'  -async 1';
                    $have_demo = true;
                }
            }




            // demo Video

            //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=426:-2 -crf 26 $video_output_full_path_240 2>&1");

            $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';
			$shell     = shell_exec($ffmpegCommand);




            $upload_s3 = PT_UploadToS3($filepath . "_240p_converted.mp4");
            $db->where('id', $insert);
            $db->update(T_VIDEOS, array(
                'converted' => 1,
                '240p' => 1,
                'video_location' => $filepath . "_240p_converted.mp4"
            ));
            if ($pt->config->queue_count > 0) {
                $db->where('video_id',$insert)->delete(T_QUEUE);
            }

            if ($video_res >= 3840) {

                //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=3840:-2 -crf 26 $video_output_full_path_4096 2>&1");

            $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_4096.' 2>&1';
			$shell     = shell_exec($ffmpegCommand);



                $upload_s3 = PT_UploadToS3($filepath . "_4096p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '4096p' => 1
                ));
                // demo Video

                if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                    $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()). "_video_4096p_demo.mp4";
                    $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=3840:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                    $upload_s3 = PT_UploadToS3($demo_video);
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        'demo' => $demo_video
                    ));
                }
                // demo Video
            }
            if ($video_res >= 2048) {
                //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=2048:-2 -crf 26 $video_output_full_path_2048 2>&1");

                $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_2048.' 2>&1';
				$shell     = shell_exec($ffmpegCommand);


                $upload_s3 = PT_UploadToS3($filepath . "_2048p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '2048p' => 1
                ));
                // demo Video
                if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                    $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_2048p_demo.mp4";
                    $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=2048:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                    $upload_s3 = PT_UploadToS3($demo_video);
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        'demo' => $demo_video
                    ));
                }
                // demo Video
            }
            if ($video_res >= 1920 || $video_res == 0) {
                //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1920:-2 -crf 26 $video_output_full_path_1080 2>&1");

            $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_1080.' 2>&1';
			$shell     = shell_exec($ffmpegCommand);


                $upload_s3 = PT_UploadToS3($filepath . "_1080p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '1080p' => 1
                ));
                // demo Video
                if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                    $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_1080p_demo.mp4";
                    $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1920:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                    $upload_s3 = PT_UploadToS3($demo_video);
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        'demo' => $demo_video
                    ));
                }
                // demo Video
            }
            if ($video_res >= 1280 || $video_res == 0) {

               //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1280:-2 -crf 26 $video_output_full_path_720 2>&1");

            $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_720.' 2>&1';
			$shell     = shell_exec($ffmpegCommand);

                $upload_s3 = PT_UploadToS3($filepath . "_720p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '720p' => 1
                ));
                // demo Video
                if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                    $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_720p_demo.mp4";
                    $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1280:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                    $upload_s3 = PT_UploadToS3($demo_video);
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        'demo' => $demo_video
                    ));
                }
                // demo Video
            }
            if ($video_res >= 854 || $video_res == 0) {
                //$shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=854:-2 -crf 26 $video_output_full_path_480 2>&1");

                $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_480.' 2>&1';
				$shell     = shell_exec($ffmpegCommand);



                $upload_s3 = PT_UploadToS3($filepath . "_480p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '480p' => 1
                ));
                // demo Video
                if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                    $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_480p_demo.mp4";
                    $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=854:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                    $upload_s3 = PT_UploadToS3($demo_video);
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        'demo' => $demo_video
                    ));
                }
                // demo Video
            }
            if ($video_res >= 640 || $video_res == 0) {
               // $shell                      = shell_exec("$ffmpeg_b -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");

            $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_360.' 2>&1';
			$shell     = shell_exec($ffmpegCommand);



               $upload_s3                  = PT_UploadToS3($filepath . "_360p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '360p' => 1,
                ));
                // demo Video
                if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                    $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_360p_demo.mp4";
                    $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                    $upload_s3 = PT_UploadToS3($demo_video);
                    $db->where('id', $insert);
                    $db->update(T_VIDEOS, array(
                        'demo' => $demo_video
                    ));
                }
                // demo Video
            }

            // demo Video
            if ($pt->config->demo_video == 'on' && empty($demo_video) && $have_demo == true) {
                $demo_video = substr($filepath, 0,strpos($filepath, '_video') - 10).sha1(time()) . "_video_240p_demo.mp4";
                $shell     = shell_exec("$ffmpeg_b $video_time -y -i $video_file_full_path -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=426:-2 -crf 26 ".$full_dir . $demo_video." 2>&1");
                $upload_s3 = PT_UploadToS3($demo_video);
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    'demo' => $demo_video
                ));
            }
            // demo Video


            if (file_exists($_POST['video-location'])) {
                unlink($_POST['video-location']);
            }


            pt_push_channel_notifiations($video_id);
            $_SESSION['uploads'] = array();
        }
        else{
            $db->insert(T_QUEUE, array('video_id' => $insert,
                               'video_res' => $video_res,
                               'processing' => 0));
            $db->where('id', $insert);
            $db->update(T_VIDEOS, array(
                'video_location' => $_POST['video-location']
            ));
        }
        exit();
    }
} else {
    $data = array(
        'status' => 400,
        'message' => $error_icon . $error
    );
}
}



I have looked at this link: https://ffmpeg.org/f....html#overlay-1

And after looking at the example there:
"Make a sliding overlay appearing from the left to the right top part of the screen starting since time 2:"
overlay=x='if(gte(t,2), -w+(t-2)*20, NAN)':



and the example:
"Insert 2 different transparent PNG logos (second logo on bottom right corner) using the ffmpeg tool:

ffmpeg -i input -i logo1 -i logo2 -filter_complex 'overlay=x=10:y=H-h-10,overlay=x=W-w-10:y=H-h-10' output



but have not succeeded with this latest attempt (to add a second watermark and set a time of '15' seconds):

$ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.'-i '.$watermark_image_full_path.' -i '.$watermark_image_full_path.'-filter_complex "overlay=10:10,scale=640:-2, overlay=10:10 'if(gte(t,15), -w+(t-2)*20, NAN)',scale=640:-2,"-vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';



any guidance/assistance is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with adding the watermark again to the video

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6252
  • View blog
  • Posts: 24,024
  • Joined: 23-August 08

Re: Help with adding the watermark again to the video

Posted 29 April 2019 - 04:51 PM

Also posted here: https://forums.phpfr...n-to-the-video/
Was This Post Helpful? 0
  • +
  • -

#3 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: Help with adding the watermark again to the video

Posted 29 April 2019 - 05:04 PM

The most obvious thing is that your quotes are not escape properly, if you want to have a single quote inside a string that is single-quoted then you need to escape it. I don't think those quotes are even supposed to be there, though.

It looks like the overlay filter takes this by default:

overlay=x:y

unless you name everything, then it's like this:

overlay=x=x_value:y=y_value

So you're telling it to still display the same thing at the same position as the first one. What position do you want to display it at? You're trying to tell it to display at 10x10 again.

You need to understand what this is doing, too:

overlay=x='if(gte(t,2), -w+(t-2)*20, NAN)'

That gives it a function to run to determine the X position of the overlay. It says that if t (I assume t means the current time) is greater or equal to 2, then X should be -w plus (t - 2) times 20. If t is not greater than or equal to 2, then X is NAN so it won't show. If you want to display the image in a specific place then just put that position in instead of using the formula to calculate it.
Was This Post Helpful? 0
  • +
  • -

#4 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Re: Help with adding the watermark again to the video

Posted 29 April 2019 - 10:03 PM

Thanks for your reply and explanation, very helpful.
Yes, 't' is the time, so if I don't use the formula and just put in the position instead, as you suggest, something like this?

$ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.'-i '.$watermark_image_full_path.' -i '.$watermark_image_full_path.'-filter_complex "overlay=10:10,scale=640:-2, overlay=20:20 '(t,15)',scale=640:-2,"-vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';




would that code be valid? Does it now (correctly) say put the 2nd image at a location of 20:20 once 15 seconds has elapsed? If it is incorrect, can you please provide a little more guidance.

Much thanks again.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,045
  • Joined: 12-December 12

Re: Help with adding the watermark again to the video

Posted 30 April 2019 - 03:15 AM

Quote

would that code be valid?

What happens when you try it?
Was This Post Helpful? 0
  • +
  • -

#6 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Re: Help with adding the watermark again to the video

Posted 30 April 2019 - 07:20 AM

What happens is I am unable to upload a file. Nothing happens upon selecting "Submit".
Any additional help is appreciated
Was This Post Helpful? 0
  • +
  • -

#7 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: Help with adding the watermark again to the video

Posted 30 April 2019 - 09:54 AM

Quote

would that code be valid?

No, you keep putting single quotes in, and you still have a static x,y position but then just add some time after it. That doesn't look like how their examples say to do it.

What's wrong with this string:

$string = 'The person said 'Hello' and I responded.';

Look at the highlighting. You're doing the same thing.
Was This Post Helpful? 0
  • +
  • -

#8 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Re: Help with adding the watermark again to the video

Posted 30 April 2019 - 11:28 AM

Thanks a lot for your reply.

This line now works:

$ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=50:50:enable=between(t\,5\,5+2),scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_720.' 2>&1';



It shows the watermark after 5 seconds, for 2 seconds, then disappears successfully.

Regarding single quotes, I'm sure you are correct, but the single quotes seem to work successfully in my original posted code, and in this code also where it shows the watermark for 2 seconds (if you're referring to this for example: '.$watermark_image_full_path.').

Now, I'm trying to add back in the original constant watermark part, in order to have both, as per my original goal:

"overlay=10:10,scale=640:-2"



but, haven't succeeded with having both there yet. This is my latest unsuccessful code attempt:

$ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -i watermark.png -filter_complex "overlay=10:10,scale=640:-2; \ overlay=50:50:enable=between(t\,5\,5+2),scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';



any additional guidance is appreciated
Was This Post Helpful? 0
  • +
  • -

#9 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: Help with adding the watermark again to the video

Posted 30 April 2019 - 12:46 PM

In this code:

$ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.'-i '.$watermark_image_full_path.' -i '.$watermark_image_full_path.'-filter_complex "overlay=10:10,scale=640:-2, overlay=20:20 '(t,15)',scale=640:-2,"-vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';

That will not execute at all. That is a syntax error in PHP. PHP thinks the string ends with the single quote after over=20:20, and it sees (t,15) as PHP code. That is a syntax error, after a string there needs to be a semicolon or an operator like a concatenation operator. Since that code has a syntax error, PHP cannot determine the structure of the code and it will not run any of the code in that file at all. So that would not work, PHP would not even execute the first line of code in the file that contains that because it cannot parse the code structure to know how to even start running it. The first thing PHP does is build an execution plan and it does that by reading the code and building a structure, and if the code contains any syntax error at all then PHP cannot build that structure, it cannot create an execution plan, and it will not run anything. You can try it for yourself, put the above line of code inside a PHP file with anything else in it - maybe just echo statements to print messages to the screen, and nothing will run. You will not see the result of any code you have in that file, you will either see a fatal error message about a parse or syntax error, or you will see a blank page if PHP is not configured to send error messages to the browser.

The code you posted in your previous post does not contain a syntax error, there are no single quotes there which break the string, so it will try to build that command and run ffmpeg.

You'll need to check the documentation for ffmpeg to see how to build the complex filter option. I would question whether that slash is correct.
Was This Post Helpful? 0
  • +
  • -

#10 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Re: Help with adding the watermark again to the video

Posted 30 April 2019 - 03:34 PM

Thanks again for your help/informative reply.
This has succeeded:

$ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -i '.$watermark_image_full_path.' -filter_complex "overlay=10:10,scale=640:-2, overlay=180:180:enable=between(t\,5\,5+2),scale=640:-2" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1';



Yet, on the uploaded test videos, the first watermark in the upper left corner looks small and unsharp, but the 2nd watermark, that displays in the middle after 5 seconds, looks to be the correct size, and sharp.

Any ideas on how to improve that will be welcomed.

This post has been edited by chrisjchrisj: 30 April 2019 - 03:36 PM

Was This Post Helpful? 0
  • +
  • -

#11 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: Help with adding the watermark again to the video

Posted 30 April 2019 - 05:30 PM

I suggest looking into the scale filter to see what you're telling it to do.
Was This Post Helpful? 0
  • +
  • -

#12 chrisjchrisj   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 04-February 19

Re: Help with adding the watermark again to the video

Posted 01 May 2019 - 01:15 PM

Thanks for your reply.
I have looked into the scale filter, but can't seem to find a solution for this particular issue.
Any other ideas/suggestions are appreciated
Was This Post Helpful? 0
  • +
  • -

#13 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2282
  • View blog
  • Posts: 6,971
  • Joined: 15-January 14

Re: Help with adding the watermark again to the video

Posted 01 May 2019 - 02:59 PM

I would just play around with the various options to see what does what, I haven't looked into the filter_complex option enough to know exactly what you're telling it. It would probably be faster to log in with ssh and just run the ffmpeg commands directly instead of changing the PHP code, but however you want to do it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1