JamesHeinrich / getID3

http://www.getid3.org/
Other
1.14k stars 244 forks source link

RemoveID3v2 avdataoffset issue when id3v1 and id3v2 #314

Open toto4ds opened 3 years ago

toto4ds commented 3 years ago

Hello, The problem does not appear when you use only id3v2

PHP 7.4.16 GETID3_VERSION 1.9.20-202006061653

Code: write 'id3v1', 'id3v2.4':

$TagFormatsToWrite = ['id3v1', 'id3v2.4'];

$tagwriter = new \getid3_writetags;
$tagwriter->filename = $this->path;
$tagwriter->tagformats = $TagFormatsToWrite;
$tagwriter->overwrite_tags = true;
$tagwriter->tag_encoding = 'UTF-8';
$tagwriter->remove_other_tags = true;

$tagwriter->tag_data = $TagData;
if ($tagwriter->WriteTags()) 

delete ''id3v2':

$tagwriter = new \getid3_writetags;
$tagwriter->filename       = $this->path;
$tagwriter->DeleteTags(['id3v2']);

before delete get analyze:

$getID3 = new \getID3;
$getID3->encoding = 'UTF-8';
$getID3->analyze($this->path);

file cbr320mb10.mp3: analyze result:

"avdataoffset" => 4096 "avdataend" => 11665156

dump $OldThisFileInfo in RemoveID3v2() result:

["avdataoffset"]=> int(4096) ["avdataend"]=> int(11665284) ["warning"]=> array(1) { [0]=> string(98) "Too much data in file: expecting 11661060 bytes of audio data, found 11661188 (128 bytes too many)" }

The error is that he does not see the id3v1 tag? Although there is no such problem when analyzing

file 1second.mp3: analyze result:

"filesize" => 5376 "avdataoffset" => 4096 "avdataend" => 5248

dump $OldThisFileInfo in RemoveID3v2() result:

["filesize"]=> int(5376) ["error"]=> array(2) { [0]=> string(43) "Invalid MPEG audio header () at offset 5248" [1]=> string(50) "Could not find valid MPEG synch before end of file" } ["warning"]=> array(17) { [0]=> string(67) "Frame at offset (4096) is valid, but the next one at (5248) is not." [1]=> string(82) "VBR file with no VBR header. Bitrate values calculated from actual frame bitrates." [2]=> string(67) "Frame at offset (4168) is valid, but the next one at (5248) is not." [3]=> string(67) "Frame at offset (4240) is valid, but the next one at (5248) is not." [4]=> string(67) "Frame at offset (4312) is valid, but the next one at (5248) is not." [5]=> string(67) "Frame at offset (4384) is valid, but the next one at (5248) is not." [6]=> string(67) "Frame at offset (4456) is valid, but the next one at (5248) is not." [7]=> string(67) "Frame at offset (4528) is valid, but the next one at (5248) is not." [8]=> string(67) "Frame at offset (4600) is valid, but the next one at (5248) is not." [9]=> string(67) "Frame at offset (4672) is valid, but the next one at (5248) is not." [10]=> string(67) "Frame at offset (4744) is valid, but the next one at (5248) is not." [11]=> string(67) "Frame at offset (4816) is valid, but the next one at (5248) is not." [12]=> string(67) "Frame at offset (4888) is valid, but the next one at (5248) is not." [13]=> string(67) "Frame at offset (4960) is valid, but the next one at (5248) is not." [14]=> string(67) "Frame at offset (5032) is valid, but the next one at (5248) is not." [15]=> string(67) "Frame at offset (5104) is valid, but the next one at (5248) is not." [16]=> string(67) "Frame at offset (5176) is valid, but the next one at (5248) is not." }

and error:

Undefined index: avdataoffset if ($OldThisFileInfo['avdataoffset'] !== false) {

if run a second time, there are no problems and errors, but the id3v1 tag also disappears thx

toto4ds commented 3 years ago

easy way to repeat, the code for writing is the same: 1) write ['id3v1', 'id3v2.4'], 2) write ['id3v2.4']

But if I run the analyze() before WriteTags(), there is no errors

toto4ds commented 3 years ago

After removing from the laravel, the error is not reproduced. I will investigate further and report the result later.

toto4ds commented 3 years ago

Continuation of the survey. It's not laravel fault.

The following code has been written which does not work as expected:

require_once('vendor/james-heinrich/getid3/getid3/getid3.php');
require_once('vendor/james-heinrich/getid3/getid3/write.php');

$TagData = ['title' => ['Title me']];
$path = '1second.mp3';

for ($a=1; $a<=6; $a++) {
    if ($a%2) {
        $TagFormatsToWrite = ['id3v1', 'id3v2.4'];
    } else {
        $TagFormatsToWrite = ['id3v2.4'];
    }

    $tagwriter = new \getid3_writetags;
    $tagwriter->filename = $path;
    $tagwriter->tagformats = $TagFormatsToWrite;
    $tagwriter->overwrite_tags = true;
    $tagwriter->tag_encoding = 'UTF-8';
    $tagwriter->remove_other_tags = true;

    $tagwriter->tag_data = $TagData;
    if ($tagwriter->WriteTags()) {
        if (!empty($tagwriter->warnings)) {
            echo 'WriteTags '.$a.' warnings: '.implode($tagwriter->warnings)."\n";
        } else {
            echo 'Tags '.$a.' update'."\n";
        }
    } else {
        echo 'WriteTags '.$a.' errors: '.implode($tagwriter->errors)."\n";
    }
}

result for 1second.mp3

Tags 1 update WriteTags 2 errors: Tag format "id3v2.4" is not allowed on "" files WriteTags 3 errors: Tag format "id3v1" is not allowed on "" files WriteTags 4 errors: Tag format "id3v2.4" is not allowed on "" files WriteTags 5 errors: Tag format "id3v1" is not allowed on "" files WriteTags 6 errors: Tag format "id3v2.4" is not allowed on "" files

result for cbr320mb10.mp3 is no error

"remove_other_tags" set to "false" works without errors

on PHP 7.3.27 same problem on GETID3_VERSION 1.9.20-202104081001 same problem 1second.mp3 at https://drive.google.com/file/d/1T_6GzI0LGppcMjhiL98lhgMD7dxNv2a8/view?usp=sharing