Adding a watermark to a video via ffmpeg

I didn’t mean you to add an extra line - I meant you to add the extra parameters (the second input file, and the extra filter specification) to all the existing places where you call ffmpeg in the existing code.

And this bit

$input_path = $full_dir . $file_upload['filename'];
ffmpeg -i video.mp4 -i watermark1.png -filter_complex "overlay=main_w-overlay_w-10:main_h-overlay_h-10" bottom_left.mp4"
$output_path = $full_dir . $thumb;

isn’t correct - you’ve just shoved the command line directly into your PHP code on the middle of the three lines quoted above. Have a look at all the places where you call ffmpeg in the code you posted in post #5, and modify those calls to have the extra parameters.

Thank you for your reply. Yes, what I have isn’t correct. I’m looking for any help with “the second input file, and the extra filter specification) to all the existing places where you call ffmpeg in the existing code”.
Thanks again

First, find all the lines in the code that you posted in post #5 that call “ffmpeg”. Have a look at the code around them, and see that there are quite a few, which IIRC deal with different video sizes. You’ll need to change each one, but for now if you know what size your test video is, you can just change one until you get it working.

Next, identify the two parameters you’ve added to ffmpeg in the examples - these specify the second input file, and where to overlay it. Those are the parameters mentioned in the article I linked to in post #19.

Then, it’s just a case of adding those two extra parameters to each and every time your code calls ffmpeg.

I know you mentioned earlier that you didn’t write the code, but your text editor will take care of the first step, and the article describes in some detail which two parameters you need to add for the second one.

Thanks for your reply. So, I believe you’re saying that I need to add that line of code into the file, with the correct input parameters pertaining to uploading, via the existing web script. Correct? Here is the file code that is needed, apparently, (according to a guy who knows the script, but is too busy with other projects to help me):

<?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;
    $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 {
        $request   = array();
        $request[] = (!in_array($_POST['video-location'], $_SESSION['uploads']['videos']));
        $request[] = (!in_array($_POST['video-thumnail'], $_SESSION['uploads']['images']));
        $request[] = (!file_exists($_POST['video-location']));
        if (in_array(true, $request)) {
            $error = $lang->error_msg;
        }
    }
    if (empty($error)) {
        $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);
        }
        $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 (!empty($_POST['category_id'])) {
            if (in_array($_POST['category_id'], array_keys($categories))) {
                $category_id = PT_Secure($_POST['category_id']);
            }
        }
        $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']);
        }
        $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']);
            }
        }
        $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
        );
        if ($pt->config->approve_videos == 'on' && !PT_IsAdmin()) {
            $data_insert['approved'] = 0;
        }
        $insert      = $db->insert(T_VIDEOS, $data_insert);
        if ($insert) {
            $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();
            }
            $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'];

            $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");
            $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 ($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");
                $upload_s3                  = PT_UploadToS3($filepath . "_360p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array( 
                    '360p' => 1,
                ));
            }

            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");
                $upload_s3 = PT_UploadToS3($filepath . "_480p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '480p' => 1
                ));
            }

            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");
                $upload_s3 = PT_UploadToS3($filepath . "_720p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '720p' => 1
                ));
            }

            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");
                $upload_s3 = PT_UploadToS3($filepath . "_1080p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '1080p' => 1
                ));
            }

            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");
                $upload_s3 = PT_UploadToS3($filepath . "_2048p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '2048p' => 1
                ));
            }

            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");
                $upload_s3 = PT_UploadToS3($filepath . "_4096p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '4096p' => 1
                ));
            }


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

            if (!empty($_SESSION['uploads']['images'])) {
                if (is_array($_SESSION['uploads']['images'])) {
                    foreach ($_SESSION['uploads']['images'] as $key => $file) {
                        if ($thumbnail == $file) {
                            unset($_SESSION['uploads']['images'][$key]);
                        } else {
                            //@unlink($file);
                        }
                    }
                    $_SESSION['uploads']['images'] = array();
                }
            }

            pt_push_channel_notifiations($video_id);
            $_SESSION['uploads'] = array();
            exit();
        }
    } else {
        $data = array(
            'status' => 400,
            'message' => $error_icon . $error
        );
    }
}

Not correct. Here’s what I think you need to do:

I can see six lines in that code that appear to call ffmpeg in different ways depending on the video resolution. Find those lines, add the two parameters for the overlay, bingo. Probably.

1 Like

Thanks for your reply.
Can you give me an example of what the “the second input file, and the extra filter specification” might look like?

Yes. Have a read of the article I linked to in post #19, that describes the two parameters in some detail. Also have a detailed look at the ffmpeg command you posted at the start of #20 - that contains the second input file, and the other parameter that governs where the second file is overlaid onto the video.

Does this help at all? It pretty much tells you exactly which parts of the command line are the two parameters that deal with the watermark.

Thanks again for taking the time to provide your great guidance.

I tried this, (adding in a modified $shell line) without success:

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

            $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");
            $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 ($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");
                $shell  					= shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark1.png -filter_complex "overlay=10:10" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
               $upload_s3                  = PT_UploadToS3($filepath . "_360p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '360p' => 1,
                ));
            }

            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");
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark1.png -filter_complex "overlay=10:10" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_480p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '480p' => 1
                ));
            }

            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");
                $shell    = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark1.png -filter_complex "overlay=10:10" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_720p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '720p' => 1
                ));
            }

            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");
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark1.png -filter_complex "overlay=10:10" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_1080p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '1080p' => 1
                ));
            }

            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");
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark1.png -filter_complex "overlay=10:10" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_2048p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '2048p' => 1
                ));
            }

            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");
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark1.png -filter_complex "overlay=10:10" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_4096p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '4096p' => 1
                ));
            }
.....

I look forward to any comments/suggestions

You’ve used double-quotes inside a string that you surrounded with double quotes. Either escape them, or use single quotes. Surprised you don’t get a syntax error.

Thanks for your reply. Much appreciated.
I have removed the quotes from here: “overlay=10:10”
and now I see this appear after upload:

Media error: Format(s) not supported or sources not found
mejs.download-file: https://…com/upload/videos/2018/08/6SWCpSImGQrsVXGgIh7A_24_549ebe0d36bccb10faf72b81e303ce50_video_360p_converted.mp4

mejs.download-file: https://…com/upload/videos/2018/08/Ubud1OqKHK7MPjvtbHw5_24_cdab9c4bc2a4eccc7c478526abb530d8_video_240p_converted.mp4

I look forward to any comments. Much thanks again

There may be a reason for those quotes being there, so just removing them may not be the correct solution. As I said earlier, perhaps escape them inside the string, or change the line to use single-quotes around the outer string instead of double quotes.

Thanks for your reply. I tried what I think is escaping the string:
/‘overlay=10:10/’
and then also tried replacing
“$ffmpeg_b -y … etc. … 2>&1”);
with
‘ffmpeg_b -y … etc. … 2>&1’);
a single quote, without success - same media error message.
any additional idea/suggestion/solution, will be welcomed.

Escaping uses \ not /

“$ffmpeg … "overlay=10:10" …”

Thanks for your message.
Yes, I got it correct in the testing, just not explaining in the posting:
\‘overlay=10:10\’
also this does not work:
“$ffmpeg … “overlay=10:10” …”

Still getting the media error.
Any other suggestions will be appreciated

Obviously it doesn’t, it’s missing more than half of all parameters, I was just showing where the double quotes go and how to escape them.

Here as a full example that should work.

$shell = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark1.png -filter_complex \"overlay=10:10\" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");

(it’s the one inside the if ($video_res >= 640 || $video_res == 0) { block)

Thanks for your reply.

I have added your ‘full example’, thanks for that, to the code below. However, I’m not sure what you mean by “it’s the one inside the…”, as I’ve modified, with part of your example, several lines, as you can see. Yet, I still see the media errors(described in #30), and no files upload. Any additional help will be welcomed. Much thanks again.

<?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;
    $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 {
        $request   = array();
        $request[] = (!in_array($_POST['video-location'], $_SESSION['uploads']['videos']));
        $request[] = (!in_array($_POST['video-thumnail'], $_SESSION['uploads']['images']));
        $request[] = (!file_exists($_POST['video-location']));
        if (in_array(true, $request)) {
            $error = $lang->error_msg;
        }
    }
    if (empty($error)) {
        $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);
        }
        $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 (!empty($_POST['category_id'])) {
            if (in_array($_POST['category_id'], array_keys($categories))) {
                $category_id = PT_Secure($_POST['category_id']);
            }
        }
        $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']);
        }
        $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']);
            }
        }
        $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
        );
        if ($pt->config->approve_videos == 'on' && !PT_IsAdmin()) {
            $data_insert['approved'] = 0;
        }
        $insert      = $db->insert(T_VIDEOS, $data_insert);
        if ($insert) {
            $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();
            }
            $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'];

            $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark.png -filter_complex \"overlay=10:10\" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=426:-2 -crf 26 $video_output_full_path_240 2>&1");
            $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 ($video_res >= 640 || $video_res == 0) {
                $shell   = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark.png -filter_complex \"overlay=10:10\" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=640:-2 -crf 26 $video_output_full_path_360 2>&1");
                $upload_s3                  = PT_UploadToS3($filepath . "_360p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '360p' => 1,
                ));
            }

            if ($video_res >= 854 || $video_res == 0) {
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark.png -filter_complex \"overlay=10:10\" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=854:-2 -crf 26 $video_output_full_path_480 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_480p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '480p' => 1
                ));
            }

            if ($video_res >= 1280 || $video_res == 0) {
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark.png -filter_complex \"overlay=10:10\" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1280:-2 -crf 26 $video_output_full_path_720 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_720p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '720p' => 1
                ));
            }

            if ($video_res >= 1920 || $video_res == 0) {
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark.png -filter_complex \"overlay=10:10\" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=1920:-2 -crf 26 $video_output_full_path_1080 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_1080p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '1080p' => 1
                ));
            }

            if ($video_res >= 2048) {
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark.png -filter_complex \"overlay=10:10\" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=2048:-2 -crf 26 $video_output_full_path_2048 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_2048p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '2048p' => 1
                ));
            }

            if ($video_res >= 3840) {
                $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i watermark.png -filter_complex \"overlay=10:10\" -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=3840:-2 -crf 26 $video_output_full_path_4096 2>&1");
                $upload_s3 = PT_UploadToS3($filepath . "_4096p_converted.mp4");
                $db->where('id', $insert);
                $db->update(T_VIDEOS, array(
                    '4096p' => 1
                ));
            }


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

            if (!empty($_SESSION['uploads']['images'])) {
                if (is_array($_SESSION['uploads']['images'])) {
                    foreach ($_SESSION['uploads']['images'] as $key => $file) {
                        if ($thumbnail == $file) {
                            unset($_SESSION['uploads']['images'][$key]);
                        } else {
                            //@unlink($file);
                        }
                    }
                    $_SESSION['uploads']['images'] = array();
                }
            }

            pt_push_channel_notifiations($video_id);
            $_SESSION['uploads'] = array();
            exit();
        }
    } else {
        $data = array(
            'status' => 400,
            'message' => $error_icon . $error
        );
    }
}

Is your watermark.png in the correct location, or should you specify the full path for it?

Thanks for your reply. I have added watermark.png into the root folder, ajax folder and video folder, to try to figure out the correct location. I’m be interested in any help regarding the correct location, and any suggestions as to what would be considered the full path for it.
Thanks again

Why not copy it into the folder where the videos are stored, and use similar code to the block that creates the $video_file_full_path variable used in the conversion?

Thanks for your suggestion. Can you please give me an example of what you mean by “use similar code to the block that creates the $video_file_full_path variable used in the conversion”? like this?


 $shell     = shell_exec("$ffmpeg_b -y -i $video_file_full_path -i /home/user/public_html/watermark.png -filter_complex 'overlay=10:10' -vcodec libx264 -preset {$pt->config->convert_speed} -filter:v scale=426:-2 -crf 26 $video_output_full_path_240 2>&1");