使用PHP检查两个视频是否相同

4

我已经搜索了很多次,但没有找到任何解决方案,所以在这种情况下我无法发布任何代码。非常抱歉。

我遇到了一个问题,如何检查两个或更多视频是否相同,就像我有一个媒体文件夹和许多视频上传到这个文件夹中,当我上传新的视频时,需要检查视频是否已存在。

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

我已经使用图像比较进行了检查

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;
              }

        }

但是我无法比较视频。有人可以帮助我吗?

系统("md5sum <文件名>"); 比较这两个:https://dev59.com/nk_Sa4cB1Zd3GeqP9yhq - pokeybit
1
或者尝试:http://php.net/manual/en/function.md5-file.php#94494 - pokeybit
谢谢。正在检查你的链接。 - Shafiqul Islam
你能提供任何关于如何检查demo.mp4和demo1.mp4视频的答案吗? - Shafiqul Islam
1个回答

3

已测试并正常工作,代码来自: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;
}
?>

非常完美,我也在你提供的链接中找到了。非常感谢。 - Shafiqul Islam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接