1

我是 Python 的初学者,想制作一个像电影“阿凡达”一样的视频日记。我想使用 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。

4

1 回答 1

0

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

于 2013-02-18T10:38:53.853 回答