Open In App

Python VLC MediaPlayer – Getting FPS

Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will see how we can get the fps i.e frame rate per second in the MediaPlayer object in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. MediaPlayer object is the basic object in vlc module for playing the video. We can create a MediaPlayer object with the help of MediaPlayer method. Frame rate is the frequency at which consecutive images called frames appear on a display. The term applies equally to film and video cameras, computer graphics, and motion capture systems. Frame rate may also be called the frame frequency, and be expressed in hertz.

In order to do this we will use get_fps method with the MediaPlayer object Syntax : media_player.get_fps() Argument : It takes no argument Return : It returns float

Below is the implementation 

Python3




# importing vlc module
import vlc
 
# importing time module
import time
 
 
# creating vlc media player object
media_player = vlc.MediaPlayer()
 
# media resource locator
mrl = "death_note.mkv"
 
# setting mrl to the media player
media_player.set_mrl(mrl)
 
# start playing video
media_player.play()
 
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
 
# getting fps
value = media_player.get_fps()
 
# printing fps
print("Frame Rate per Second : ")
print(value)


Output :

Frame Rate per Second : 
23.976215362548828

Another example Below is the implementation 

Python3




# importing vlc module
import vlc
 
# importing time module
import time
 
# creating vlc media player object
media_player = vlc.MediaPlayer()
 
# media resource locator
mrl = "1.mp4"
 
# setting mrl to the media player
media_player.set_mrl(mrl)
 
# start playing video
media_player.play()
 
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
 
 
# getting cursor co-ordinates
value = media_player.video_get_cursor()
 
# getting fps
value = media_player.get_fps()
 
# printing fps
print("Frame Rate per Second : ")
print(value)


Output :

Frame Rate per Second : 
29.969999313354492


Last Updated : 10 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads