我正在尝试从YouTube视频流式传输视频和音频数据,以便我可以单独进行一些视频和音频分析,然后使用OpenCV将其叠加到帧上。我对文件的处理非常好,但希望将其扩展到YouTube上的流媒体。
目前,我已经考虑过使用VLC Python绑定从YouTube流式传输,但我不确定如何从此视频中提取帧。
以下是执行YouTube直播的vlc代码:
import vlc
import time
import numpy as np
from ctypes import *
class MyDisplay(vlc.VideoDisplayCb):
def __doc__(o,p):
print "fsdfs"
class MyLock(vlc.VideoLockCb):
def __doc__():
raise Exception("sdsds")
return np.array(500,500).__array_interface__['data']
class MyPlayback(vlc.AudioPlayCb):
def from_param(self,a,b,c,d):
print "asfds"
def callbck(a,b,c,d):
print 'aa'
print a
print b
print c
print d
return 'a'
if __name__ == '__main__':
url = 'https://www.youtube.com/watch?v=F82XtLmL0tU'
i = vlc.Instance('--verbose 2'.split())
media = i.media_new(url)
media_list = i.media_list_new([url])
p = i.media_player_new()
p.set_media(media)
lp = i.media_list_player_new()
lp.set_media_player(p)
lp.set_media_list(media_list)
CMPFUNC = CFUNCTYPE(c_char, c_void_p, c_void_p, c_uint, c_long)
lp.next()
lock = MyLock()
display = MyDisplay()
playback = MyPlayback()
p.audio_set_callbacks(CMPFUNC(callbck),None,None,None,None,None)
p.play()
time.sleep(5)
r = p.video_take_snapshot(0,'rnd.pong',0,0)
如何使用VLC(使用Python绑定)生成帧和音频数据流?还有另一种方法(例如使用ffmpeg)吗?
由于