Page 1 of 2

Recording video from webcam

Posted: Wed Apr 14, 2010 9:33 pm
by cborn
I'm new to Rev and I"m trying see if it's suitable for a project I have in mind. The documentation seems to suggest it'll be perfect, but I'm having trouble getting a proof-of-concept stack working.

I want to create a simple stack of three buttons: Preview, Record and Playback. The item to preview, record and playback is a recording from the webcam. I've tried a variety of combinations of the Video library controls, but can't seem to get a usable file. What I get is a white square on screen during the preview and record. When recording, my webcam is on and a .mov file is created, and I can successfully stop the recording. But the file created is not playable by QT.

Here are the script settings at this moment:

Preview Button

Code: Select all

on mouseUp
   revInitializeVideoGrabber Video, "QT", "300, 100, 800, 500 "
   revVideoGrabDialog
   local vSettings
   revVideoGrabSettings "vSettings"
   set the videoSettings of this cd to vSettings
   revSetVideoGrabSettings "vSettings"
   revPreviewVideo
end mouseUp

Record button

Code: Select all

on mouseUp
   revStopPreviewingVideo
   revRecordVideo "/myvideo.mov"
end mouseUp
I haven't even tried the playback button, since I don't have recording working.

What am I missing? :?

Thank you!

Re: Recording video from webcam

Posted: Thu Apr 15, 2010 12:07 am
by bn
cborn,
your preview button works if you set it to this script:

Code: Select all

on mouseUp
   global recordVideo
   revInitializeVideoGrabber the short name of this stack, "QT", "300, 100, 800, 500 "
   
   revVideoGrabDialog
   revSetVideoGrabberRect "300, 100, 800, 500 "
   
   local vSettings
   revVideoGrabSettings "vSettings"
   set the videoSettings of this stack to vSettings
   
   revPreviewVideo
   put true into recordVideo
   repeat while recordvideo is true
      revVideoGrabIdle
      wait for 1 millisecond with messages
   end repeat
end mouseUp
your record button like this

Code: Select all

on mouseUp
   global recordVideo
   revStopPreviewingVideo
   put specialfolderpath("desktop") into tDesk
   revRecordVideo (tDesk & "/myvideo.mov")
   put true into recordVideo
   repeat while recordvideo is true
      revVideoGrabIdle
      wait for 1 millisecond with messages
   end repeat
end mouseUp
to stop recording a button with this script

Code: Select all

on mouseUp
   global recordVideo
   put false into recordVideo
   revStopRecordingVideo
end mouseUp
to finish video and get rid of the rectangle a button:

Code: Select all

on mouseUp
   global recordVideo
   put false into recordvideo
   revCloseVideoGrabber
end mouseUp
all assuming you are using Quicktime, here tested on a Mac. The file appears on the desktop as myVideo.mov. Repeated recordings overwrite the file without warning.
regards
Bernd

Re: Recording video from webcam

Posted: Thu Apr 15, 2010 4:46 pm
by cborn
Bernd,

Wow, this is great, thanks so much! It's working fabulously!

I am using QT on a Mac, but will need to test Windows, as well. I'm hoping to output to a web app.

I see that it requires this interesting QT dialog box at first. Is there a way to choose those settings so that it does not appear?

thanks again for your help!
:D

carly

Re: Recording video from webcam

Posted: Thu Apr 15, 2010 7:40 pm
by bn
Charly,
did you have a look at the example stack that comes with rev. It is in the "programs" folder inside Revolution->resources->sample projects->Video Capure.rev.
I has all the code for windows and mac and all functions on different buttons.
I tried to adapt to your code, but I agree that a separate button for the QT dialog is much better.
Just have a look. They store the QT-settings in a custom property of the stack: videosettings.
Custom properties are a convenient way to store data for an app and it is persistent between runs.
If you take that stack apart you should find most of what you need for previewing/recording/taking stills.

I will gladly be of help if you run into problems.
regards
Bernd

Re: Recording video from webcam

Posted: Thu Apr 15, 2010 10:47 pm
by cborn
Yeah, I just found that stack this afternoon. I've been working with it, removing the screen grab features and making it smaller.

The one problem I'm having is that the preview is not functioning when viewed as a webpage. I'm also interested in getting the video it creates to be a bit smaller, more compressed.

I'm hoping to turn it into a revlet that I can embed in our LMS. It would brilliant if I could send the video to a database on a server ... but I haven't approached that part of Rev scripting yet.

Re: Recording video from webcam

Posted: Thu Apr 15, 2010 11:16 pm
by bn
Carly,
(sorry I addressed you as Charly in my previous post)
I am afraid you can not use the required video external for revlets. The dictionary states all the video commands are Desktop, and I dont think you can include the necessary externals in a revlet like you can when you make an app.
I tried to do a revlet and it did not work.
cborn wrote:I'm also interested in getting the video it creates to be a bit smaller, more compressed
H.264 is a fairly good compressor, you could also reduce the framerate, depending on what you want to record. Aside from what you already do i.e. reducing the size of the rect.
Again, why exactly would you need a revlet, you could do a standalone that uploads the movies to a server, couldn't you?
regards
Bernd

Re: Recording video from webcam

Posted: Fri Apr 16, 2010 4:23 pm
by cborn
Bernd,

We are hoping to integrate with our LMS, and let the LMS handle all of the foreign language text, etc that might be needed for the exercises we have in mind. I was actually successful in embeding the revlet in a Moodle lesson, it records just fine it just doesn't show the preview while recording. At this point, it still saves the file to the desktop, of course. With the preview portion being the only thing not functioning at this point, it was seeming like things might work out somehow.

What I am thinking about is making a tool that would be a plugin to the LMS and perform the video/audio capture as part of a set of exercises. The prompts for the recordings would be created in the LMS, and would include a wide range of textual and visual materials. Rev seems to have trouble with the text of some languages, so it's not going to work as the sole delivery platform for us. We need it for teaching foreign languages, and we teach a number of them, including Arabic, Japanese and Russian.

Basically, I'm exploring this as a way to cobble together an online language lab.

Re: Recording video from webcam

Posted: Sat Apr 17, 2010 1:05 pm
by bn
Carly,
cool, I tried again and was able to record movies from a revlet. Since the videosettings seem not to work in the revlet I set a custom property in the stack before building the revlet. I used H.264. The settings for H.264 did not reduce the framerate, seems to be a bug in the settings dialog. But I got H.264 .mov from the revlet, without preview. For 320 by 240 movie about 240 KiloBytes per second on the medium setting for compression/quality.

Rumors have it that the next version of Rev will have a much improved support for Unicode -> Russian, Chinese, Arab.

What is a LMS?

regards
Bernd

Re: Recording video from webcam

Posted: Sun Apr 18, 2010 11:42 am
by Klaus
Did this work on Windows, too? I never got the RevVideoGrabber to work with QT on Windows (XP and WIn7) in the last 4 years!

Have a sunny sunday :)


Best

Klaus

Re: Recording video from webcam

Posted: Mon Apr 19, 2010 6:31 pm
by cborn
yeah, I'm currently trying to sort out how to set the custom property, I'm glad to hear that it works.

I didn't get the revlet to record in QT from Windows. But it did record using VFW in AVI format. That's not ideal for us, but it's something.

We're using Moodle. We may write a custom Moodle module around this if we can get the kinks worked out (which is going very well so far, considering I'm not a programmer!).

Re: Recording video from webcam

Posted: Tue Apr 20, 2010 5:35 pm
by cborn
Bernd

Sorry, I went back and read through your post again more slowly and realized that I didn't actually answer your question about LMS. LMS is Learning Management System, some call them Content or Course Management Systems (CMS).

Anyway, I'm having trouble setting the custom property. Is it that I must get the VideoSettingDialog if I want to set the compression to H.264? I'd like to make it a required setting and then bypass the dialog, if at all possible.

Re: Recording video from webcam

Posted: Tue Apr 20, 2010 5:58 pm
by bn
Carly,
I took the commands from the Rev Demo Stack(video capture) and made a separatet button to save the settings into the custom property
this creates the custom property "videosetting" of the stack. You can look at the custom properties of the stack in the properties inspector->custom properties.
if you find a custom property "videosetting" with some 'gibberish' in it then you created the custom property successfully.
I only choose my setting once in the development environment. I did then hid the button for the setting of the custom property. A custom property is persisten between restarts.

Code: Select all

on mouseUp 
  -- the video grabber component requires us to declare a variable
  -- so that it can return data to it
  local myvar
  -- bring up the system QuickTime capture settings dialog
  revVideoGrabDialog "display"
  -- capture the settings the user has entered to the variable myVar
  revVideoGrabSettings "myvar"
  -- set the custom property "videoSettings" of this stack to contain the
  -- data returned in the myVar variable
  set the videoSettings of this stack to myvar
  -- save this stack so that the next time the user opens it
  -- the same settings will be preserved and loaded in the stack script
  save this stack
end mouseUp

later I read out the custom property "videosetting" and hand it over to the external in the initialization routine, here as a button but preverably in a handler runs e.g at opencard, if that is the only card of the revlet.

Code: Select all

on mouseUp
   
   -- read in the rectangluar area of the "video" image
   -- used to place the video capture area
   put rect of image "video" into tRect
   -- check to see if we are to use QuickTime or Video for Windows
   
   -- the command to initialize the video grabber, using QuickTime
   revInitializeVideoGrabber short name of this stack,"qt",tRect
   
   -- set the rectangle area to display the preview in to the variable we
   -- stored earlier
   revSetVideoGrabberRect tRect
   -- the video grabber component requires us to declare a variable to use
   -- to store or retrieve settings
   local myvar
   -- load the videoSettings custom property of this stack into the myVar variable
   put the videoSettings of this stack into myVar
   -- set the video grabber to use the settings we just loaded from the stack
   revSetVideoGrabSettings "myvar"
end mouseUp
I left the original comments from the example stack in the scripts. Of course you can change your variable names, but for testing I would stick with the demo variable names.

if this does not work please say so.

regards
Bernd

Re: Recording video from webcam

Posted: Thu Apr 22, 2010 4:43 pm
by cborn
Bernd,

This is great, thank you so much for all of your help!

In my messing around, I've somehow broken my video settings dialog box such that I can't change the compression type from Y'CbCr 4:2:2 - uyvy to H.264. That pull-down menu will not respond. I've tried removing all of the custom properties I can find in the stack, card, objects, etc. In case they were getting in the way. But I can't seem to fix the issue. It seems to only be affecting Revolution, and not Quicktime as a whole. So may reinstall the program. As soon as I get that sorted out, I'll be able to test your recent scripts. I'm sure they will work fine.

Thanks again!

Re: Recording video from webcam

Posted: Thu Apr 29, 2010 6:01 pm
by cborn
Bernd,

I'm making pretty good progress with this and so we've gone ahead and purchased a license of Rev Enterprise. I'm wondering, is there any way we can get the video preview to work from a revlet? Is that a QT problem or a Rev problem? This feature would make my project be just awesome, so I'm very interested in trying to figure it out.

Re: Recording video from webcam

Posted: Thu Apr 29, 2010 10:52 pm
by bn
Carly,
cborn wrote:Is that a QT problem or a Rev problem?
I am afraid it is a Rev problem.

I added it to the Quality Control Center as a bug report
http://quality.runrev.com/qacenter/show_bug.cgi?id=8752

Welcome to Rev,
You know where to ask if you get stuck...

regards
Bernd