Python VLC MediaPlayer – 截图
在本文中,我们将看到如何在Python vlc 模块中截取 MediaPlayer 对象的屏幕截图。 VLC媒体播放器是VideoLAN项目开发的一款免费开源的便携式跨平台媒体播放软件和流媒体服务器。 MediPlyer 对象是 vlc 模块中用于播放视频的基本对象。屏幕截图,也称为 ss、sc、屏幕捕获或屏幕抓取,是显示计算机显示器内容的数字图像。常见的屏幕截图由设备上运行的操作系统或软件创建。还可以通过拍摄屏幕照片来创建屏幕截图或屏幕截图。
In order to do this we will use video_take_snapshot
method with the MediaPlayer object
Syntax : media_player.video_take_snapshot(n, location, width, height)
Argument : It takes video output number, folder location and width and height of screenshot as argument
Return : It returns 0 on success, -1 if the video was not found
下面是实现
# importing vlc module
import vlc
# importing time module
import time
# creating vlc media player object
media_player = vlc.MediaPlayer()
# media object
media = vlc.Media("death_note.mkv")
# setting media to the media player
media_player.set_media(media)
# setting video scale
media_player.video_set_scale(0.6)
# start playing video
media_player.play()
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
# taking screen shot
media_player.video_take_snapshot(0, "F://test", 400, 300)
输出 :
下面是文件夹位置
另一个例子
下面是实现
# importing vlc module
import vlc
# importing time module
import time
# creating vlc media player object
media_player = vlc.MediaPlayer()
# media object
media = vlc.Media("1mp4.mkv")
# setting media to the media player
media_player.set_media(media)
# setting video scale
media_player.video_set_scale(0.6)
# start playing video
media_player.play()
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
# taking screen shot
media_player.video_take_snapshot(0, "F://test", 400, 300)
输出 :
下面是文件夹位置