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

标签 php video

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

我遇到了一个问题,我如何检查 2 个或更多视频,就像我在这个文件夹中有媒体文件夹和许多视频上传一样,然后当我上传新视频时,我需要检查该视频是否已经退出。

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

        }

但我无法比较视频。有人帮帮我

最佳答案

经过测试并且工作正常,代码取自: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;
}
?>

关于php - 使用 php 检查两个视频是否相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44032351/

相关文章:

php - 在 php 中获取唯一的命中数

php - MySQL 从单个选择中进行多次插入

php - 如何通过 Magento API 以编程方式将属性分配给特定属性集?

php - 在 Mac OS X 10.5.8 上为 PHP 安装 Mcrypt 扩展

android - 处理程序 postDelayed - 每秒打印一些东西

php - 此类和子方法如何使用?

python - Pygame/MoviePy - 视频以糟糕的帧率显示,窗口大小比我的屏幕大

css - 为什么 noverblaster 视频播放器总是在其他元素之上

video - 使用 FFMpeg 覆盖 PNG 时质量不佳