Get Duration of .Mp3/.Avi file without using QMediaPlayer
I have been working on an application where I can traverse the system drives using QDirIterator and look for audio/video files, grab the details using QStandardItemModel and display it on QTreeview. I have been successful in displaying file name, type, size, date-modified but DURATION is something which I am not able to do.
I know QMediaPlayer seems to help in getting the duration and user will need to run the clip in order to achieve the duration. I don't want to use QMediaPlayer approach. Is their any other way of retrieving duration info of mp3/avi file and then display it in TreeView?
For mp3 you can simply parse the file: http://www.multiweb.cz/twoinches/MP3inside.htm#MP3FileStructure
Well I can find lot of details on Mp3 here. But I see No. of frames in file between 44-47. Would you please elaborate me on how to go ahead with it?
[quote author="AcerExtensa" date="1353921688"]For mp3 you can simply parse the file: http://www.multiweb.cz/twoinches/MP3inside.htm#MP3FileStructure [/quote]
Can retrieve detailed info (including duration) for almost any multimedia file type that exists :-)
(Use it as a library or call the CLI tool via QProcess)
You need to parse the file then compute for the duration. This "link":http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header may help you.
[quote author="Code_ReaQtor" date="1353980381"]You need to parse the file then compute for the duration. This "link":http://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header may help you.[/quote]
Why re-invent the wheel when MediaInfo does it all and not only for MP3 files, but for pretty much any audio/video format in existence? Unless you do this for your own education, I don't see much reason.
Detecting the "duration" of MP3 files is especially difficult, because there is NO global header in a MP3 file, which could tell you the duration (or total frame count). Unless you want to parse all MP3 frames in the file (slow!) you might be able to guesstimate the duration from the file size and the bitrate (can be parsed from the first frame, for example). But that can only work with strict CBR files, it will fail horribly with VBR files. With VBR files you might be able to do something with the Xing header, if present, though...