Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error When Reading MP4 File #4

Open
tetrahydra opened this issue Mar 31, 2018 · 15 comments
Open

Error When Reading MP4 File #4

tetrahydra opened this issue Mar 31, 2018 · 15 comments
Assignees

Comments

@tetrahydra
Copy link

Hello,

I am reading an MP4 file, and I am getting this error:

Duration: 612.437
Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/mediametadata/src/Adapters/Mp4Adapter.php on line 14

Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/mediametadata/src/Adapters/Mp4Adapter.php on line 21
Dimensions: x
Warning: Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/mediametadata/src/Adapters/Mp4Adapter.php on line 28
Framerate:

@wapmorgan
Copy link
Owner

Can you provide this file?

@wapmorgan wapmorgan self-assigned this Aug 1, 2018
@wapmorgan
Copy link
Owner

wapmorgan commented Aug 1, 2018

@tetrahydra ping

@tetrahydra
Copy link
Author

tetrahydra commented Aug 1, 2018

the code:

``
require('BinaryStream.php');

require('FileTypeDetector/ContentStream.php');
require('FileTypeDetector/Detector.php');
require('FileTypeDetector/TerminalInfo.php');

require('src/Exceptions/Exception.php');
require('src/Exceptions/FileAccessException.php');
require('src/Exceptions/ParsingException.php');

require('src/AudioAdapter.php');
require('src/ContainerAdapter.php');
require('src/VideoAdapter.php');

require('src/Adapters/Mpeg4Part12Adapter.php');
require('src/Adapters/Containers/MatroskaContainer.php');
require('src/Adapters/AacAdapter.php');
require('src/Adapters/AmrAdapter.php');
require('src/Adapters/AsfAdapter.php');
require('src/Adapters/AviAdapter.php');
require('src/Adapters/FlacAdapter.php');
require('src/Adapters/MkvAdapter.php');
require('src/Adapters/Mp3Adapter.php');
require('src/Adapters/Mp4Adapter.php');
require('src/Adapters/OggAdapter.php');
require('src/Adapters/WavAdapter.php');
require('src/Adapters/WmaAdapter.php');
require('src/Adapters/WmvAdapter.php');

require('src/MediaFile.php');

try {
$media = wapmorgan\MediaFile\MediaFile::open('2018-03-30 114535am.mp4');

if ($media->isAudio()) {
// calls to AudioAdapter interface
echo 'Duration: '.$media->getAudio()->getLength().PHP_EOL;
echo 'Bit rate: '.$media->getAudio()->getBitRate().PHP_EOL;
echo 'Sample rate: '.$media->getAudio()->getSampleRate().PHP_EOL;
echo 'Channels: '.$media->getAudio()->getChannels().PHP_EOL;
}
// for video
else {
// calls to VideoAdapter interface
echo 'Duration: '.$media->getVideo()->getLength().PHP_EOL;
echo 'Dimensions: '.$media->getVideo()->getWidth().'x'.$media->getVideo()->getHeight().PHP_EOL;
echo 'Framerate: '.$media->getVideo()->getFramerate().PHP_EOL;
}
} catch (wapmorgan\MediaFile\Exceptions\Exception $e) {
// not a media or file is corrupted
if ($e instanceof wapmorgan\MediaFile\Exceptions\ParsingException)
echo 'File is propably corrupted: '.$e->getMessage().PHP_EOL;
else if ($e instanceof wapmorgan\MediaFile\Exceptions\FileAccessException) {}
// file is not a media. Just skip
}

``

@wapmorgan
Copy link
Owner

It seems to be ok. Which file used?

@wapmorgan
Copy link
Owner

To resolve this problem I need file sample.

@alex-enchi
Copy link

alex-enchi commented Oct 29, 2018

Hi, i can confirm that this bug exists
Video sample with this stream error:

http://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4

Another video example with File is propably corrupted: This file does not have "moov" box!

http://techslides.com/demos/sample-videos/small.mp4 from article

PS:
Checked these files with id3 lib, width/height info there is accurate

@justtoprogram
Copy link

justtoprogram commented Nov 8, 2018

Hi Guys,

I can confirm that I am also receiving this bug.

Message: Warning: Invalid argument supplied for foreach() in .../Plugins/vendor/wapmorgan/media-file/src/Adapters/Mp4Adapter.php on line 14

Here are is an example video I had been testing:

https://drive.google.com/file/d/1h_W80ocTKd-DBc8oowbdxAuaRts1p6X5/view?usp=sharing

Edit:

I was trying to figure out what information was being parsed to the foreach loop with a var_dump & it is was outputting null

capture

capture

@justtoprogram
Copy link

Hi Guys, how are we going for a fix on this?

It's getting kind of urgent for our organisation?

@alex-enchi
Copy link

@justtoprogram if it is really urgent i would suggest to use https://github.com/JamesHeinrich/getID3

@justtoprogram
Copy link

I was avoiding that because I like this library. It does only what I need it to do.

@alex-enchi
Copy link

alex-enchi commented Nov 13, 2018

I am as well, but had to use it.
I have strong suspect that the reason why it is not working properly is because around Mpeg4Part12Adapter.php#L173 code depends on order of the markers. And I think in real life it can be different. Unfortunately I don't have enough knowledge to fix this. Maybe someone else can dig it.

@wapmorgan
Copy link
Owner

Going to discover it ...

@wapmorgan
Copy link
Owner

wapmorgan commented Apr 20, 2019

Really, I don't have the wish and time to fix it.

@Maxyandr
Copy link

I have the same problem with the .mp4 files.
File is propably corrupted: This file does not have "moov" box!
I think, that error caused because the moov atom is located at the end of mp4 file.
If you scan your mp4 file with the utility https://gpac.github.io/mp4box.js/test/filereader.html.
You can see the location of the moov atom.

But the library try to find moov atom at the beginning. I will try to fix.

@elonchen
Copy link

elonchen commented Jan 15, 2021

add/edit lines in Mpeg4Part12Adapter.php may help


public function __construct

  $this->stream->saveGroup('mdat_box_header', array(
        'i:size' => 32,
        's:type' => 4,
        'i:extended_size' => 64,
    ));

protected function scan()

   if ($this->getNextBoxType() == 'free'){
        $this->stream->skip(8);
    }

    if ($this->getNextBoxType() == 'mdat') {
        $this->stream->mark('mdat');;
        $this->mdat = $this->stream->readGroup('mdat_box_header');
        $len = $this->mdat['size'] - 16;
        if ($this->mdat['size'] == 1)
            $len = $this->mdat['extended_size'] - 16;
        $this->stream->skip($len); 
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants