tonches / moovrelocator

Automatically exported from code.google.com/p/moovrelocator
Other
0 stars 0 forks source link

Private variable are not reset when processing another file with the same instance of moverelocator object #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Process multiple files with the MoveRelocator object
2. First file will work ok, the next one crashes
3. example will not work:

<?php

$files = array(
    '/home/jambon/64_preview.mp4',
    '/home/jambon/63_preview.mp4',
    '/home/jambon/62_preview.mp4'
); 

foreach($files as $file)
{
    echo move_datas($file)."\n";
}

function move_datas($file)
{
    $tmpFile = $file.'-tmp.mp4';
    $moovrelocator = moovrelocator::getInstance();

    $ret = true;

    if($ret === true)
        $ret = $moovrelocator->setInput($file);

    if($ret === true)
        $ret = $moovrelocator->setOutput($tmpFile);

    if($ret === true)
        $ret = $moovrelocator->fix();

    if($ret === true) {
        unlink($file);
    rename($tmpFile,$file);
        $ret = 'moov atom location successfuly moved to top of file!'."\n";
    }

    return $ret;
}
?>

This will not work because some private variables are not reset between two 
files.

I propose to create the private function like this : 

    private function closeFile()
    {
        $this->_fileAtoms = array();

    $this->_lastAtom = null;

    $this->_successfullyParsed = false;

    $this->_fileValid = null;

        if ($this->_fp) {
            @fclose($this->_fp);
        }
    }

replace the __destruct magic method as :

    public function __destruct()
    {
        // close handle
        $this->closeFile();
    }

and add the following line at the beginnig of the function setInput() :

    $this->closeFile();

Yeaba

romain

Original issue reported on code.google.com by imp...@gmail.com on 11 Aug 2010 at 12:40

GoogleCodeExporter commented 8 years ago

Original comment by phpflues...@googlemail.com on 10 Sep 2010 at 4:22

GoogleCodeExporter commented 8 years ago
Thanks Yeaba! Your updates to the class worked beautifully for me.  I was 
experiencing the same issue when running my entire database of .m4a files 
through Moov Relocator.  It would process the first song well but error out on 
the rest.

One thing I've noticed: it seems that songs over 5 minutes process well with 
Moov Relocator but songs less than 5 minutes error on 
$moovrelocator->setInput($inFile);

Is that because songs less than 5 minutes do not have the atoms at the end of 
the file?

Original comment by mattyc...@gmail.com on 29 Apr 2011 at 4:43

GoogleCodeExporter commented 8 years ago
I've added the changes as recommended.
Thanks for figuring this out.

Benjamin

Original comment by phpflues...@googlemail.com on 26 Aug 2011 at 7:32