Wx.media return incorrect duration sound's time (posible bugt)

Hello every body.

I am make a player with wx.Media, when I import a mp3 file, Wx return diferent time when the file has a bit rate variable or bit rate constant. I have the same file, but with diferent duration retorned by Wx. If i use software to get multimedia information like Mediainfo, VLC, Reaper etc, all softwares return the same time with variable or constant bit rate. Has Wx a bug?, how can I solbed it?

Regards.

What operating system and version are you using?

I use:

  • Windows10 x64
  • Python 3.9
  • WxPython 4.1.1

Hi carlos.rojas,

How did you get the bit rate using wx.media?
I couldn’t find the way to get bit-rate from the document: wx.media.MediaCtrl — wxPython Phoenix 4.1.1 documentation

Regards,

This may not be the solution you are looking for, but I just call ffmpeg from python to obtain that information.

David

Hello.

I use Media info to get mp3 information, but remember, my problem is the time duration retorned by wx.media.MediaCtrl.Length() instruction when mp3 file is variable or constant bit rate, here a example:
‘track.mp3’

with bit rate variable : 2054243 milliseconds
with bit rate constant: 2106902 milliseconds

This may be a (known) problem in wxWidgets. The wxAMMediaBackend (which I think is the default backend?) has a comment in the code about GetDuration() not working correctly with VBR MP3 files:

You might want to try the other backends (e.g. WMP 10) to see if the behavior is any different?

Hello, thank for your answer.

I tryed with MEDIABACKEND_DIRECTSHOW and MEDIABACKEND_WMP10, but the problems it’s continuing. In vefore coment show a problem with variable bit rate (vbr), but in my test, wx.media and other softwares return the same duration time, the problem ocurre when I load a constant bit rate mp3 (cbr), because only wx.media return a diferent duration.

Regards.

I checked the duration that FFmpeg returns and that of wx.media.Length for VBR and CBR.
As you pointed out, wx.media.MediaCtrl.Length returns the same value for media with VBR but a different value for CBR (but not always).

I noticed that the Windows 10 explorer also shows the same but wrong duration time as wx.media.Length returns, so I guess this problem is with the backend of Windows.

Clipboard01

The three files shown above have the same duration time (90.648 s). The first one is the original and the other two are converted from the original one using FFmpeg with a constant bit rate. The wx.media.MediaCtrl.Length returns 92.984 s for the last file.

1 Like

OK, I understand, thank you for your answer. So I think is no posible solved it.

If you have FFmpeg installed, you can get the correct information by calling it from python as follows:

from subprocess import Popen, PIPE

def read_info(path):
    command = ['ffprobe',
               '-i', path,
               '-loglevel', 'quiet',    # no verbose
               '-print_format', 'json', # -format json
               '-show_streams',         # -streams info
               ]
    with Popen(command, stdout=PIPE, stderr=PIPE) as fp:
        ret, err = fp.communicate()
        if not err:
            return eval(ret)
1 Like