Check if two videos are the same using php

I have searched many times, but I have not found any solution, so in this case I can not publish any code. Sorry for this.

I had a problem: how can I check that 2 or more videos are the same, for example, I have a media folder and a lot of video uploads in this folder, and then when I upload a new video, you need to check that the video is already coming out or not.

1. if i have video demo.mp4 then when i will try to upload same video then give error
2. if i change video name like demo.mp4 to demo1.mp4 then i will give same error cause video name different but video content same
3. if i upload video demo5.mp4 then show me no error

i already verified image comparison using

include('compareImages.php');
     $new_image_name = $uploadfile_temp; 
     $compareMachine = new compareImages($new_image_name);
     $image1Hash = $compareMachine->getHasString(); 
     $files = glob("uploads/*.*");
      $check_image_duplicate = 0;
      for ($i = 0; $i < count($files); $i++) {
           $filename = $files[$i];
           $image2Hash = $compareMachine->hasStringImage($filename); 
           $diff = $compareMachine->compareHash($image2Hash);
           if($diff < 10){
              $check_image_duplicate = 1;
              //unlink($new_image_name);
               break;
              }

        }

but I can not compare the video. someone helps me

+4
source share
1 answer

, : http://php.net/manual/en/function.md5-file.php#94494 .

<?php
define('READ_LEN', 4096);

if(files_identical('demo.mp4', 'demo1.mp4'))
    echo 'files identical';
else
    echo 'files not identical';

//   pass two file names
//   returns TRUE if files are the same, FALSE otherwise
function files_identical($fn1, $fn2) {
    if(filetype($fn1) !== filetype($fn2))
        return FALSE;

    if(filesize($fn1) !== filesize($fn2))
        return FALSE;

    if(!$fp1 = fopen($fn1, 'rb'))
        return FALSE;

    if(!$fp2 = fopen($fn2, 'rb')) {
        fclose($fp1);
        return FALSE;
    }

    $same = TRUE;
    while (!feof($fp1) and !feof($fp2))
        if(fread($fp1, READ_LEN) !== fread($fp2, READ_LEN)) {
            $same = FALSE;
            break;
        }

    if(feof($fp1) !== feof($fp2))
        $same = FALSE;

    fclose($fp1);
    fclose($fp2);

    return $same;
}
?>
+3

Source: https://habr.com/ru/post/1677384/


All Articles