![]() |
mp3 duration
Hi,
Pardon me for speaking english, my last attempt at google translation did not work too well ;), I am trying to determine an mp3's duration without loading the file, I need it to work with CBR and VBR. Thank you. |
Re: mp3 duration
Maybe
![]() |
Re: mp3 duration
Hi again. ;-)
You can use Mp3FileUtils for this also.
Delphi-Quellcode:
The duration (in seconds) is then stored in mpegInfo.Dauer ("Dauer" is german for "duration" - maybe I should change this. ;-))
var Id3v1Tag: TId3v1Tag;
Id3v2Tag: TId3v2Tag; mpegInfo: TMpegInfo; stream: TFileStream; begin stream := TFileStream.Create(aFileName, fmOpenRead or fmShareDenyWrite); Id3v2Tag.ReadFromStream(stream); // Read the id3v2Tag first (recommended, reading MPEG-Info will be much slower otherwise) // Seek to the end of the ID3Tag, if exists if Not Id3v2Tag.exists then stream.Seek(0, sobeginning) else stream.Seek(Id3v2Tag.size, soFromBeginning); // read MPEG-Information (like duration, bitrate, and so on) MpegInfo.LoadFromStream(Stream); // optionally: read the old id3v1-Tag Id3v1Tag.ReadFromStream(stream); stream.free; end; |
Re: mp3 duration
When I try to use loadfromstream i get an access violation. :(
|
Re: mp3 duration
Try Audio Tools Library 2.3 it works with CBR and VBR
![]() AudioGenie is a fast 32Bit ActiveX-OCX/Dll with over 345 functions to read audio file information (like Bitrate, Samplerate, Frames, Duration, Version-Number, etc). ![]() Or Bass.dll ( ![]()
Delphi-Quellcode:
function TAudioEngine.Get_MP3_Bitrate: WORD; const MPEG_BIT_RATES: array[1..3] of array[1..3] of array[0..15] of word = (( { Version 1, Layer I } (0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0), { Version 1, Layer II } (0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,0), { Version 1, Layer III } (0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,0)), { Version 2, Layer I } ((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0), { Version 2, Layer II } (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0), { Version 2, Layer III } (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0)), { Version 2.5, Layer I } ((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0), { Version 2.5, Layer II } (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0), { Version 2.5, Layer III } (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0) )); var framehead, fpos: DWORD; Version, layer, bitrate_index: DWORD; fHandle : integer; FileFS : THandleStream; begin fpos := BASS_StreamGetFilePosition(Channel, BASS_FILEPOS_DECODE) + BASS_StreamGetFilePosition(Channel, BASS_FILEPOS_START); fHandle := CreateFile(PChar(Cur_FileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE,0); if fHandle = INVALID_HANDLE_VALUE then exit; FileFS := THandleStream.Create(fHandle); FileFS.Seek(fpos, soFromBeginning); FileFS.Read(framehead, SizeOf(framehead)); FileFS.Free; CloseHandle(fHandle); framehead := ((framehead and $ff) shl 24) or ((framehead and $ff00) shl 8) or ((framehead and $ff0000) shr 8) or ((framehead and $ff000000)shr 24); // reverse byte order if ((framehead shr 21) = $7ff) then // got frame sync begin layer := (framehead shr 19) and 3; version := (framehead shr 17) and 3; bitrate_index := (framehead shr 12) and 15; Result := MPEG_BIT_RATES[version][layer][bitrate_index]; end else Result:= 0; end; Only for CBR (Bass.dll)
Delphi-Quellcode:
var
fFileSize, fBitRate : DWORD; fFloatPos : FLOAT; fFileSize:= BASS_StreamGetFilePosition(Channel, BASS_FILEPOS_END); fFloatPos:= BASS_ChannelBytes2Seconds(Channel, BASS_StreamGetLength(Channel)); fBitRate:= Trunc((fFileSize /(125 * fFloatPos))+0.5); if Odd(fBitRate) then Dec(fBitRate); Result:= fBitRate; have fun :wink: |
Re: mp3 duration
Zitat:
Delphi-Quellcode:
This should work.
Id3v1Tag := TId3v1Tag.Create;
Id3v2Tag := TId3v2Tag.Create; mpegInfo := TMpegInfo.Create; |
DP-Maintenance
Dieses Thema wurde von "fkerber" von "Open-Source" nach "Multimedia" verschoben.
I move this thread because it\\\'s not an open source program but a question. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:11 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz