Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I get current real-time buffer size in vlc streaming buffer through python-vlc? #61

Closed
maozezhong opened this issue Jul 27, 2018 · 15 comments

Comments

@maozezhong
Copy link

I want to get the current real-time buffer size while vlc streaming video, How can I get it through python-vlc. real-time buffer size means like, a video is stream from one server to one client, vlc get it and stored it in a buffer pool, and vlc decode the data in the pool so as to show the video currently, what I want is the size or time of video data in the pool during the streaming.

@mrJean1
Copy link
Collaborator

mrJean1 commented Jul 27, 2018

The MediaStats class provides some details like the number of bytes read, frames decoded, the bitrate and other things, but there's no buffer size. To get the MediaStats from Python, use

p = vlc.player()
p.set_mrl(<video_file_name>)
p.play()
...
s = vlc.MediaStats()
m = p.get_media()
if m.get_stats(s):
    print(s)
...

Following is an example of the output (with Python 2.7.15) playing one video, but paused:

MediaStats
 read_bytes: 7901716
 input_bitrate: 2.51318240166*
 demux_read_bytes: 7843817
 demux_bitrate: 2.56340408325*
 demux_corrupted: 0
 demux_discontinuity: 2
 decoded_video: 192
 decoded_audio: 291
 displayed_pictures: 65
 lost_pictures: 0
 played_abuffers: 145
 lost_abuffers: 0
 sent_packets: 0
 sent_bytes: 0
 send_bitrate: 0.0

*) Bitrates are conventionally in Ko/s, for kilo-octets-per-sec.

Screen shots of 2 of the Media Information... window panes of the VLC App (on macOS) playing an other video.

vlc_mediastats_example

vlc_mediacodec_example

@mrJean1
Copy link
Collaborator

mrJean1 commented Jul 28, 2018

The latest version 18.7.27 of examples/cocoavlc.py now also shows how to get and interpret MediaStats.

@maozezhong
Copy link
Author

@mrJean1 , hello, thank you for your reply. Is it possible to get buffer size through input-bitrate and demux_bitrate ? Like in my opinion, input bitrate means the vidieo data stream to the current pool, and demux bitrate is the data get out from the current pool , So I can simply get buffer size through this two parameter, am I right?

@mrJean1
Copy link
Collaborator

mrJean1 commented Jul 29, 2018

Possibly, using one of these cache sizes. But you may have to get that cache size from the VLC App, since there doesn't seem to be a way to get or set any of these from Python.

Here's a screen shot of the VLC 3.0.3 App Preferences -> Input/Codecs -> Advanced caching settings on macOS.

vlc-inputcodecsadvanced-caching

@mrJean1
Copy link
Collaborator

mrJean1 commented Jul 29, 2018

It turns out there are command line options to set the caching values:

% /Applications/VLC.app/.../VLC --help --advanced
...
  Subpictures
    Advanced:
      --file-caching <integer [0 .. 60000]>    File caching (ms)
      --live-caching <integer [0 .. 60000]>    Live capture caching (ms)
      --disc-caching <integer [0 .. 60000]>    Disc caching (ms)
      --network-caching <integer [0 .. 60000]>    Network caching (ms)
 ...

From Python, you could set these as follows, untested however:

i = vlc.Instance(["--file-caching=2000 --network-caching=3000"])
p = i.media_player_new()
...

@maozezhong
Copy link
Author

@mrJean1 Thanks a lot! It seems to set the caching values means to set the total size of the buffer pool, like, when I set the file-caching=2000, it means the upper limit of buffer pools is 2000ms, in another word, the max time of video the buffer pool can store is 2000ms. what I want to get is the real-time buffer size when streaming the video data, because the pool is not always full, so 2000ms may not be the value I want, am I right? So, any other adivce? correct me if I am wrong~

@mrJean1
Copy link
Collaborator

mrJean1 commented Jul 30, 2018

That question is now beyond the Python-VLC project. Ask that again, but at the VideoLan.org support/help page.

@maozezhong
Copy link
Author

OK, Thanks a lot anyway!

@mrJean1
Copy link
Collaborator

mrJean1 commented Jul 30, 2018

Just to explain, the buffer size is probably not just the bitrate times the caching time.

@maozezhong
Copy link
Author

Ok, So (read_bytes -demux_read_bytes ) / input_bitrate may not be the caching time? what is the buffer size exactly?

@mrJean1
Copy link
Collaborator

mrJean1 commented Jul 30, 2018

Like my previous comment, this may not be that simple either. Just don’t know and don’t have an authoritative answer, sorry.

@maozezhong
Copy link
Author

ok, thank you for your patient reply~

@mrJean1
Copy link
Collaborator

mrJean1 commented Aug 8, 2018

As an experiment, the latest examples/cocoavlc.py computes input-caching as (read_bytes - demux_read_bytes) / (input_bitrate * 1000) in seconds and (read_bytes - demux_read_bytes) in bytes.

Typical initial values are around 30 s and 70 KiB for sample videos at about 2 secs, see cocoavlc-snapshotX-TableWindow.pdf. Both those values increase for any time later in the videos.

@oaubert oaubert closed this as completed Jun 4, 2020
@floris-vos
Copy link

this is closed - I suppose it means that this is just impossible?
I tried with MediaStats, but couldn't get any kind of reasonable buffer or cache info.

@mrJean1
Copy link
Collaborator

mrJean1 commented Mar 26, 2023

The MediaStats struct hasn't changed in VLC since the examples shown above. And that's all vlc.py can provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants