使用opencv和pyaudio从网络摄像头录制视频和音频



我是Python的初学者,我想在电影"Avartar"。我想使用OpenCV。录制我的网络摄像头的视频流已经可以工作了,但如何同时保存我的网络摄像机的视频和音频?顺便说一句:我使用的是Linux和python 2.7

我当前的视频录制代码:

 #!/usr/bin/python
 time = localtime()
 s = "%02i:%02i:%02i_%02i-%02i-%02i" % (time[3],time[4],time[5],time[2],time[1],time[0])
 global fn
 fn = "%02i_%02i_%02i__%02i_%02i_%02i" % (time[3],time[4],time[5],time[2],time[1],time[0])
 recordingtime=str(s)
 videodir="./Videos/"
 # Set video settings
 capture = cv.CaptureFromCAM(0)
 fourcc = cv.CV_FOURCC('M','J','P','G')
 fps = 25
 w, h = 720, 540
 stream = cv.CreateVideoWriter(video.avi", fourcc, fps, (w, h))
 # recording time
 recordingtime = 20
 recstart = int(time())
 while True:
     now = int(time())
     recdiff = now - recstart
     counter = recdiff - recordingtime
     if counter <= 0 :
         # start timer
         rectime = recordingtime
    frame = cv.QueryFrame(capture)
         # write stream
    # Display text
    ## color settings for text
    r=255 
    g=255 
    b=255 
         ## Text position
    tx = 450 
    ty = 330
    font = cv.InitFont(cv.CV_FONT_HERSHEY_COMPLEX, .7, .7, 0, 1, 20)
    cv.PutText(frame, recordingtime, (ty,tx),font, (b,g,r))
    cv.WriteFrame(stream, frame)
         ## Farbdefinition des eingeblendeten Textes
    r=255 
    g=0 
    b=0 
         ## Textposition
    tx = 450 
    ty = 50 
    font = cv.InitFont(cv.CV_FONT_HERSHEY_COMPLEX, 2, 2, 0, 4, 20)
    cv.PutText(frame, str(counter)[1:], (ty,tx),font, (b,g,r))
    # show window
    cv.ShowImage("capture", frame)
         # move window
    cv.MoveWindow ("capture", 550,400)
    key = cv.WaitKey(10)
    if key & 255 == 27:
        sys.exit()
     else :
    break

提前感谢您的帮助。

干杯M.

不幸的是,opencv 中不支持音频流

相关内容

  • 没有找到相关文章

最新更新