2

I'm using the getID3 library to get the details of a remote video file. I'm trying to read a portion of the file to get the details of the file, however some videos don't have the full details at the start.

For these videos, I'm trying to download the full video, and then extract the relevant information. However, even after the video has downloaded completely, getID3->analyze($filename), returns the same erroneous file info.

But when I copy the video, and then run the function analyze($filename.'copied.mp4') on copied video, it returns the correct info even though the file contents are same. Perhaps getID3 isn't loading the video again, however, how can I fix this issue without copying the video.

Please find the code below.

if ($fp_remote = fopen($remotefilename, 'r')) {
    echo 'conn opened'; 
    $localtempfilename = tempnam('/home/xerox/abc', 'whateva').'.mp4';
    if ($fp_local = fopen($localtempfilename, 'wb')) {
        $count = 0;
        $countExpiry = 8;
        while ($buffer = fread($fp_remote, 8192)) {
            $count++;
            fwrite($fp_local, $buffer);
            if ($count >= $countExpiry) {
                fflush($fp_local);
                $getID3 = new getID3;
                $ThisFileInfo = $getID3->analyze($localtempfilename);
                if ($ThisFileInfo["error"]){
                    print "problem encouterd";
                    $countExpiry += 1000;
                } else {
                 break;}
            }
        }
        fclose($fp_local);
        $getID31 = new getID3;
        copy ( $localtempfilename, $localtempfilename.'_copied.mp4' );
        $ThisFileInfoz = $getID31->analyze($localtempfilename.'_copied.mp4');
        // Delete temporary file
        unlink($localtempfilename);
        fclose($fp_remote);
    var_dump($ThisFileInfoz);
    }

}
bilalba
  • 783
  • 1
  • 7
  • 22

1 Answers1

0

A call to clearstatcache solved the problem for me,

since repeated calls to things like filesize will be cached by the filesystem and getID3 won't read beyond end-of-file.

source: James Heinrich, developer of getID3.

bilalba
  • 783
  • 1
  • 7
  • 22