MediaFile
MediaFile copied to clipboard
Error When Reading MP4 File
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:
Can you provide this file?
@tetrahydra ping
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 }
``
It seems to be ok. Which file used?
To resolve this problem I need file sample.
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
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
Hi Guys, how are we going for a fix on this?
It's getting kind of urgent for our organisation?
@justtoprogram if it is really urgent i would suggest to use https://github.com/JamesHeinrich/getID3
I was avoiding that because I like this library. It does only what I need it to do.
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.
Going to discover it ...
Really, I don't have the wish and time to fix it.
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.
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);
}