AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

mp3 duration

Ein Thema von DmVinny · begonnen am 3. Apr 2009 · letzter Beitrag vom 4. Apr 2009
Antwort Antwort
DmVinny

Registriert seit: 2. Apr 2009
5 Beiträge
 
#1

mp3 duration

  Alt 3. Apr 2009, 19:35
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.
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.534 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: mp3 duration

  Alt 3. Apr 2009, 19:51
Maybe this thread could help (VB, but this does not matter due to using mciSendString).
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Benutzerbild von Gausi
Gausi

Registriert seit: 17. Jul 2005
845 Beiträge
 
Delphi 11 Alexandria
 
#3

Re: mp3 duration

  Alt 3. Apr 2009, 19:59
Hi again.

You can use Mp3FileUtils for this also.
Delphi-Quellcode:
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;
The duration (in seconds) is then stored in mpegInfo.Dauer ("Dauer" is german for "duration" - maybe I should change this. )
The angels have the phone box.
  Mit Zitat antworten Zitat
DmVinny

Registriert seit: 2. Apr 2009
5 Beiträge
 
#4

Re: mp3 duration

  Alt 3. Apr 2009, 21:37
When I try to use loadfromstream i get an access violation. :(
  Mit Zitat antworten Zitat
Wishmaster

Registriert seit: 14. Sep 2002
Ort: Steinbach, MB, Canada
301 Beiträge
 
Delphi XE2 Architect
 
#5

Re: mp3 duration

  Alt 4. Apr 2009, 09:55
Try Audio Tools Library 2.3 it works with CBR and VBR
http://mac.sourceforge.net/atl/


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).
http://www.audiogenie.de/en/index.htm

Or

Bass.dll (http://www.un4seen.com/)
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
  Mit Zitat antworten Zitat
Benutzerbild von Gausi
Gausi

Registriert seit: 17. Jul 2005
845 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: mp3 duration

  Alt 4. Apr 2009, 10:02
Zitat von DmVinny:
When I try to use loadfromstream i get an access violation.
Sorry, I forgot to add to create the objects
Delphi-Quellcode:
Id3v1Tag := TId3v1Tag.Create;
Id3v2Tag := TId3v2Tag.Create;
mpegInfo := TMpegInfo.Create;
This should work.
The angels have the phone box.
  Mit Zitat antworten Zitat
4. Apr 2009, 10:57
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.
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:29 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz