Writing movie files to disk...

Reposted, as the original poster wanted all his personal information removed.

Which is kinda ok. However we do ask you to leave your name and affiliation when writing posts (see the "How to use the forum" instructions). Anonymous posts usually reduce at least my motivation to answer at all (especially when i'm busy) to basically zero. It's not fun to spend one's own time writing into a void.

-mario

How do i write captured video data to a movie file on disc?

It goes like this:

% Create a new movie file, image size 512x512, 60 frames per second:
movie = Screen('CreateMovie', windowPtr, 'MyTestMovie.mov', 512, 512,
60);

In your loop you add new frames to the movie:
Screen('AddFrameToMovie', frame);

'frame' can be a Psychtoolbox window handle (for screenshots), an
offscreen window handle or any texture handle, so you're quite flexible.

E.g. above you'd do the following instead of the "figure, imshow(im)":

% Convert 'im' image matrix to ptb texture:
frame = Screen('MakeTexture', windowPtr, im);

% Add texture to movie:
Screen('AddFrameToMovie', frame);

% Dispose texture:
Screen('Close', frame);

At the end you close the file with

Screen('FinalizeMovie', movie);

If you'd use ptb's builtin video capture engine on Windows, you could
directly add video frames as provided by frame = Screen
('GetCapturedImage',...), this would be more efficient.

On OS/X you wouldn't need this at all. You could just directly set
the optional parameters for video recording in the Screen
('OpenVideocapture', ...); command (see its help) and it would
automatically record a movie, optionally with sound.

The whole thing is demonstrated in ImagingStereoDemo if you set the
optional 'writeMovie' flag to 1 and follow the code.
Hi, I'm hoping someone can help me out. I'm trying to write a movie to disk, but my code bugs up even when I run these two lines:

[windowPtr rect] = Screen('OpenWindow', 0, 127, [0 0 512 512]);
movie = Screen('CreateMovie', windowPtr, 'MyTestMovie.mov', 512, 512, 60);

---------------------------------
This is the error I get:

??? Error using ==> Screen
Usage:

moviePtr = Screen('CreateMovie', windowPtr, movieFile [, width][, height][,
frameRate=30][, movieOptions]);
---------------------------------

Does anyone know what's going on? It seems like my syntax is fine..

Thanks,
Evan

--- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@...> wrote:
>
> Reposted, as the original poster wanted all his personal information removed.
>
> Which is kinda ok. However we do ask you to leave your name and affiliation when writing posts (see the "How to use the forum" instructions). Anonymous posts usually reduce at least my motivation to answer at all (especially when i'm busy) to basically zero. It's not fun to spend one's own time writing into a void.
>
> -mario
>
> How do i write captured video data to a movie file on disc?
>
> It goes like this:
>
> % Create a new movie file, image size 512x512, 60 frames per second:
> movie = Screen('CreateMovie', windowPtr, 'MyTestMovie.mov', 512, 512,
> 60);
>
> In your loop you add new frames to the movie:
> Screen('AddFrameToMovie', frame);
>
> 'frame' can be a Psychtoolbox window handle (for screenshots), an
> offscreen window handle or any texture handle, so you're quite flexible.
>
> E.g. above you'd do the following instead of the "figure, imshow(im)":
>
> % Convert 'im' image matrix to ptb texture:
> frame = Screen('MakeTexture', windowPtr, im);
>
> % Add texture to movie:
> Screen('AddFrameToMovie', frame);
>
> % Dispose texture:
> Screen('Close', frame);
>
> At the end you close the file with
>
> Screen('FinalizeMovie', movie);
>
> If you'd use ptb's builtin video capture engine on Windows, you could
> directly add video frames as provided by frame = Screen
> ('GetCapturedImage',...), this would be more efficient.
>
> On OS/X you wouldn't need this at all. You could just directly set
> the optional parameters for video recording in the Screen
> ('OpenVideocapture', ...); command (see its help) and it would
> automatically record a movie, optionally with sound.
>
> The whole thing is demonstrated in ImagingStereoDemo if you set the
> optional 'writeMovie' flag to 1 and follow the code.
>
All right, another update:

I'm not too sure if GStreamer (vs QuickTime) is the route I want to go, but I uninstalled and reinstalled it and got a new set of error messages (good news, I hope :) )

------------------------------------------------------------------
PTB-WARNING: Failed to create an encoder element of type 'VideoCodec=' from the following passed parameter string:
PTB-WARNING: x264enc key-int-max=30 profile=3 speed-preset=1
PTB-WARNING: Will revert to default settings for this element. This will likely fail soon...
PTB-WARNING: Full parameter string was:
PTB-WARNING: VideoCodec=x264enc key-int-max=30 profile=3 speed-preset=1
PTB-WARNING: Failed to create 'x264enc' H.264 video encoder! Does not seem to be installed on your system?
PTB-WARNING: Failed to create an encoder element of type 'VideoCodec=' from the following passed parameter string:
PTB-WARNING: xvidenc
PTB-WARNING: Will revert to default settings for this element. This will likely fail soon...
PTB-WARNING: Full parameter string was:
PTB-WARNING: VideoCodec=xvidenc
PTB-WARNING: Failed to create 'xvidenc' xvid/mpeg-4 video encoder! Does not seem to be installed on your system?
PTB-WARNING: Failed to create an encoder element of type 'AudioCodec=' from the following passed parameter string:
PTB-WARNING: faac
PTB-WARNING: Will revert to default settings for this element. This will likely fail soon...
PTB-WARNING: Full parameter string was:
PTB-WARNING: AudioCodec=faac
PTB-WARNING: Failed to create requested audio encoder [faac ]! Falling back to default encoder.
Error in function CreateMovie: Usage error
Could not find or setup requested audio codec for recording. Aborted.
------------------------------------------------------------------

I should have the x264enc codec by default, right? If not, how could I obtain it?


Evan


--- In psychtoolbox@yahoogroups.com, "evanechang" <evanechang@...> wrote:
>
> Hi, I'm hoping someone can help me out. I'm trying to write a movie to disk, but my code bugs up even when I run these two lines:
>
> [windowPtr rect] = Screen('OpenWindow', 0, 127, [0 0 512 512]);
> movie = Screen('CreateMovie', windowPtr, 'MyTestMovie.mov', 512, 512, 60);
>
> ---------------------------------
> This is the error I get:
>
> ??? Error using ==> Screen
> Usage:
>
> moviePtr = Screen('CreateMovie', windowPtr, movieFile [, width][, height][,
> frameRate=30][, movieOptions]);
> ---------------------------------
>
> Does anyone know what's going on? It seems like my syntax is fine..
>
> Thanks,
> Evan
>
> --- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@> wrote:
> >
> > Reposted, as the original poster wanted all his personal information removed.
> >
> > Which is kinda ok. However we do ask you to leave your name and affiliation when writing posts (see the "How to use the forum" instructions). Anonymous posts usually reduce at least my motivation to answer at all (especially when i'm busy) to basically zero. It's not fun to spend one's own time writing into a void.
> >
> > -mario
> >
> > How do i write captured video data to a movie file on disc?
> >
> > It goes like this:
> >
> > % Create a new movie file, image size 512x512, 60 frames per second:
> > movie = Screen('CreateMovie', windowPtr, 'MyTestMovie.mov', 512, 512,
> > 60);
> >
> > In your loop you add new frames to the movie:
> > Screen('AddFrameToMovie', frame);
> >
> > 'frame' can be a Psychtoolbox window handle (for screenshots), an
> > offscreen window handle or any texture handle, so you're quite flexible.
> >
> > E.g. above you'd do the following instead of the "figure, imshow(im)":
> >
> > % Convert 'im' image matrix to ptb texture:
> > frame = Screen('MakeTexture', windowPtr, im);
> >
> > % Add texture to movie:
> > Screen('AddFrameToMovie', frame);
> >
> > % Dispose texture:
> > Screen('Close', frame);
> >
> > At the end you close the file with
> >
> > Screen('FinalizeMovie', movie);
> >
> > If you'd use ptb's builtin video capture engine on Windows, you could
> > directly add video frames as provided by frame = Screen
> > ('GetCapturedImage',...), this would be more efficient.
> >
> > On OS/X you wouldn't need this at all. You could just directly set
> > the optional parameters for video recording in the Screen
> > ('OpenVideocapture', ...); command (see its help) and it would
> > automatically record a movie, optionally with sound.
> >
> > The whole thing is demonstrated in ImagingStereoDemo if you set the
> > optional 'writeMovie' flag to 1 and follow the code.
> >
>
--- In psychtoolbox@yahoogroups.com, "evanechang" <evanechang@...> wrote:
>
> All right, another update:
>
> I'm not too sure if GStreamer (vs QuickTime) is the route I want to go, but I uninstalled and reinstalled it and got a new set of error messages (good news, I hope :) )
>

Yep. You probably just installed a wrong version of GStreamer, which doesn't contain the needed codec plugins. You'll need the GPL version, not the LGPL version. The recommended one is ...

<http://ossbuild.googlecode.com/files/GStreamer-WinBuilds-GPL-x86-Beta04-0.10.7.msi>

... according to our "help GStreamer".

Quicktime movie writing is not supported on Windows, GStreamer or nothing. For videocapture from cameras or video playback you still have the choice, but use of Quicktime is not recommended anymore. All new development will only happen for GStreamer.

-mario

> ------------------------------------------------------------------
> PTB-WARNING: Failed to create an encoder element of type 'VideoCodec=' from the following passed parameter string:
> PTB-WARNING: x264enc key-int-max=30 profile=3 speed-preset=1
> PTB-WARNING: Will revert to default settings for this element. This will likely fail soon...
> PTB-WARNING: Full parameter string was:
> PTB-WARNING: VideoCodec=x264enc key-int-max=30 profile=3 speed-preset=1
> PTB-WARNING: Failed to create 'x264enc' H.264 video encoder! Does not seem to be installed on your system?
> PTB-WARNING: Failed to create an encoder element of type 'VideoCodec=' from the following passed parameter string:
> PTB-WARNING: xvidenc
> PTB-WARNING: Will revert to default settings for this element. This will likely fail soon...
> PTB-WARNING: Full parameter string was:
> PTB-WARNING: VideoCodec=xvidenc
> PTB-WARNING: Failed to create 'xvidenc' xvid/mpeg-4 video encoder! Does not seem to be installed on your system?
> PTB-WARNING: Failed to create an encoder element of type 'AudioCodec=' from the following passed parameter string:
> PTB-WARNING: faac
> PTB-WARNING: Will revert to default settings for this element. This will likely fail soon...
> PTB-WARNING: Full parameter string was:
> PTB-WARNING: AudioCodec=faac
> PTB-WARNING: Failed to create requested audio encoder [faac ]! Falling back to default encoder.
> Error in function CreateMovie: Usage error
> Could not find or setup requested audio codec for recording. Aborted.
> ------------------------------------------------------------------
>
> I should have the x264enc codec by default, right? If not, how could I obtain it?
>
>
> Evan
>
>
> --- In psychtoolbox@yahoogroups.com, "evanechang" <evanechang@> wrote:
> >
> > Hi, I'm hoping someone can help me out. I'm trying to write a movie to disk, but my code bugs up even when I run these two lines:
> >
> > [windowPtr rect] = Screen('OpenWindow', 0, 127, [0 0 512 512]);
> > movie = Screen('CreateMovie', windowPtr, 'MyTestMovie.mov', 512, 512, 60);
> >
> > ---------------------------------
> > This is the error I get:
> >
> > ??? Error using ==> Screen
> > Usage:
> >
> > moviePtr = Screen('CreateMovie', windowPtr, movieFile [, width][, height][,
> > frameRate=30][, movieOptions]);
> > ---------------------------------
> >
> > Does anyone know what's going on? It seems like my syntax is fine..
> >
> > Thanks,
> > Evan
> >
> > --- In psychtoolbox@yahoogroups.com, "Mario" <mario.kleiner@> wrote:
> > >
> > > Reposted, as the original poster wanted all his personal information removed.
> > >
> > > Which is kinda ok. However we do ask you to leave your name and affiliation when writing posts (see the "How to use the forum" instructions). Anonymous posts usually reduce at least my motivation to answer at all (especially when i'm busy) to basically zero. It's not fun to spend one's own time writing into a void.
> > >
> > > -mario
> > >
> > > How do i write captured video data to a movie file on disc?
> > >
> > > It goes like this:
> > >
> > > % Create a new movie file, image size 512x512, 60 frames per second:
> > > movie = Screen('CreateMovie', windowPtr, 'MyTestMovie.mov', 512, 512,
> > > 60);
> > >
> > > In your loop you add new frames to the movie:
> > > Screen('AddFrameToMovie', frame);
> > >
> > > 'frame' can be a Psychtoolbox window handle (for screenshots), an
> > > offscreen window handle or any texture handle, so you're quite flexible.
> > >
> > > E.g. above you'd do the following instead of the "figure, imshow(im)":
> > >
> > > % Convert 'im' image matrix to ptb texture:
> > > frame = Screen('MakeTexture', windowPtr, im);
> > >
> > > % Add texture to movie:
> > > Screen('AddFrameToMovie', frame);
> > >
> > > % Dispose texture:
> > > Screen('Close', frame);
> > >
> > > At the end you close the file with
> > >
> > > Screen('FinalizeMovie', movie);
> > >
> > > If you'd use ptb's builtin video capture engine on Windows, you could
> > > directly add video frames as provided by frame = Screen
> > > ('GetCapturedImage',...), this would be more efficient.
> > >
> > > On OS/X you wouldn't need this at all. You could just directly set
> > > the optional parameters for video recording in the Screen
> > > ('OpenVideocapture', ...); command (see its help) and it would
> > > automatically record a movie, optionally with sound.
> > >
> > > The whole thing is demonstrated in ImagingStereoDemo if you set the
> > > optional 'writeMovie' flag to 1 and follow the code.
> > >
> >
>
--- In psychtoolbox@yahoogroups.com, Matthew Edmundson <medmunds@...> wrote:
>
> Mario, can GStreamer not call other codecs that are on the system?
>

Yes, but it needs a plugin to do that. PTB only supports automatic setup of a small set of codecs. These are ones that are not OS specific, but at least very well supported on Linux.

By default PTB wouldn't make any use of, e.g., OSX specific "Quicktime" codecs or MS-Windows specific "DirectShow" codecs, so if none of the open source codecs is available in a distribution, automatic or convenient setup will not work out of the box. You can pass a manual encoding pipeline description for writing of movie files if you learn the gst-launch syntax of the GStreamer command line interface. That provides maximum flexibility and maximum "fun" in debugging. Cfe line 334 of ImagingStereoDemo.m. That one would encode to Flash video format.

-mario