Skip to content

Commit

Permalink
Merge pull request #358 from StudioMaX/mp3-freeformat
Browse files Browse the repository at this point in the history
Fix a free format mp3 files
  • Loading branch information
JamesHeinrich committed Dec 22, 2021
2 parents a99e0a2 + 71ddc92 commit 73e16a9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions getid3/module.audio.mp3.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ public function GuessEncoderOptions() {
$encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min'];
}

if (isset($thisfile_mpeg_audio['bitrate']) && $thisfile_mpeg_audio['bitrate'] === 'free') {
$encoder_options .= ' --freeformat';
}

if (!empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev']) || !empty($thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'])) {
$encoder_options .= ' --nogap';
}
Expand Down Expand Up @@ -750,7 +754,8 @@ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $S
unset($thisfile_mpeg_audio_lame['long_version']);

// It the LAME tag was only introduced in LAME v3.90
// http://www.hydrogenaudio.org/?act=ST&f=15&t=9933
// https://wiki.hydrogenaud.io/index.php/LAME#VBR_header_and_LAME_tag
// https://hydrogenaud.io/index.php?topic=9933

// Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html
// are assuming a 'Xing' identifier offset of 0x24, which is the case for
Expand Down Expand Up @@ -786,7 +791,7 @@ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $S
$thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;

// bytes $A7-$AE Replay Gain
// http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
// https://web.archive.org/web/20021015212753/http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
// bytes $A7-$AA : 32 bit floating point "Peak signal amplitude"
if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') {
// LAME 3.94a16 and later - 9.23 fixed point
Expand Down Expand Up @@ -914,7 +919,7 @@ public function decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $S


// LAME CBR
if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) {
if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1 && $thisfile_mpeg_audio['bitrate'] !== 'free') {

$thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
$thisfile_mpeg_audio['bitrate'] = self::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']);
Expand Down

0 comments on commit 73e16a9

Please sign in to comment.