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

时间:2013-02-18 09:46:23

标签: python audio video opencv recording

我是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

提前感谢您的帮助。

干杯 微米。

1 个答案:

答案 0 :(得分:0)

遗憾的是,opencv

中不支持音频流