Class QuickTime::Movie
In: ext/exporter.c
lib/quicktime/movie.rb
Parent: Object

see ext/movie.c for additional methods

Methods

Public Class methods

Returns a new, empty movie.

[Source]

    # File lib/quicktime/movie.rb, line 10
10:     def self.empty
11:       new.load_empty
12:     end

Opens a movie at filepath.

[Source]

   # File lib/quicktime/movie.rb, line 5
5:     def self.open(filepath)
6:       new.load_from_file(filepath)
7:     end

Public Instance methods

Adds the tracks of given movie into called movie‘s current selection.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

/*
  call-seq: add_into_selection(movie)
  
  Adds the tracks of given movie into called movie's current selection.
  
  You can track the progress of this operation by passing a block to this 
  method. It will be called regularly during the process and pass the 
  percentage complete (0.0 to 1.0) as an argument to the block.
*/
static VALUE movie_add_into_selection(VALUE obj, VALUE src)
{
  if (rb_block_given_p())
    SetMovieProgressProc(MOVIE(obj), (MovieProgressUPP)movie_progress_proc, rb_block_proc());
  
  AddMovieSelection(MOVIE(obj), MOVIE(src));
  
  if (rb_block_given_p())
    SetMovieProgressProc(MOVIE(obj), 0, 0);
  
  return obj;
}

Adds given movie to the end of movie which this method is called on.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

     # File lib/quicktime/movie.rb, line 124
124:     def append_movie(movie, &block)
125:       select(duration, 0)
126:       insert_into_selection(movie, &block)
127:       deselect
128:     end

Returns an array of audio tracks in this movie.

[Source]

    # File lib/quicktime/movie.rb, line 38
38:     def audio_tracks
39:       tracks.select { |t| t.audio? }
40:     end

Returns a hash of boundaries. The hash contains four keys: :left, :top, :right, :bottom. Each holds an integer representing the pixel value.

[Source]

/*
  call-seq: bounds() -> bounds_hash
  
  Returns a hash of boundaries. The hash contains four keys: :left, :top, 
  :right, :bottom. Each holds an integer representing the pixel value.
*/
static VALUE movie_bounds(VALUE obj)
{
  VALUE bounds_hash = rb_hash_new();
  Rect bounds;
  GetMovieBox(MOVIE(obj), &bounds);
  rb_hash_aset(bounds_hash, ID2SYM(rb_intern("left")), INT2NUM(bounds.left));
  rb_hash_aset(bounds_hash, ID2SYM(rb_intern("top")), INT2NUM(bounds.top));
  rb_hash_aset(bounds_hash, ID2SYM(rb_intern("right")), INT2NUM(bounds.right));
  rb_hash_aset(bounds_hash, ID2SYM(rb_intern("bottom")), INT2NUM(bounds.bottom));
  return bounds_hash;
}

Determine if a movie has changed since opening. Returns true/false. See reset_changed_status to reset this value.

[Source]

/*
  call-seq: changed?() -> bool
  
  Determine if a movie has changed since opening. Returns true/false. 
  See reset_changed_status to reset this value.
*/
static VALUE movie_changed(VALUE obj)
{
  if (HasMovieChanged(MOVIE(obj))) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}

Resets the "changed?" status. Does not revert the movie itself.

[Source]

/*
  call-seq: clear_changed_status()
  
  Resets the "changed?" status. Does not revert the movie itself.
*/
static VALUE movie_clear_changed_status(VALUE obj)
{
  ClearMovieChanged(MOVIE(obj));
  return Qnil;
}

Deletes the specified section on movie and returns a new movie with that content.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

     # File lib/quicktime/movie.rb, line 160
160:     def clip_section(position = 0, duration = 0, &block)
161:       select(position, duration)
162:       movie = clip_selection(&block)
163:       deselect
164:       movie
165:     end

Deletes current selection on movie and returns a new movie with that content.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

/*
  call-seq: clip_selection()
  
  Deletes current selection on movie and returns a new movie with that 
  content.
  
  You can track the progress of this operation by passing a block to this 
  method. It will be called regularly during the process and pass the 
  percentage complete (0.0 to 1.0) as an argument to the block.
*/
static VALUE movie_clip_selection(VALUE obj)
{
  VALUE new_movie_obj = rb_obj_alloc(cMovie);
  
  if (rb_block_given_p())
    SetMovieProgressProc(MOVIE(obj), (MovieProgressUPP)movie_progress_proc, rb_block_proc());
  
  RMOVIE(new_movie_obj)->movie = CutMovieSelection(MOVIE(obj));
  
  if (rb_block_given_p())
    SetMovieProgressProc(MOVIE(obj), 0, 0);
  
  return new_movie_obj;
}

Returns a new movie from the specified portion of called movie.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

     # File lib/quicktime/movie.rb, line 147
147:     def clone_section(position = 0, duration = 0, &block)
148:       select(position, duration)
149:       movie = clone_selection(&block)
150:       deselect
151:       movie
152:     end

Returns a new movie from the current selection. Does not modify original movie.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

/*
  call-seq: clone_selection()
  
  Returns a new movie from the current selection. Does not modify original 
  movie. 
  
  You can track the progress of this operation by passing a block to this 
  method. It will be called regularly during the process and pass the 
  percentage complete (0.0 to 1.0) as an argument to the block.
*/
static VALUE movie_clone_selection(VALUE obj)
{
  VALUE new_movie_obj = rb_obj_alloc(cMovie);
  
  if (rb_block_given_p())
    SetMovieProgressProc(MOVIE(obj), (MovieProgressUPP)movie_progress_proc, rb_block_proc());
  
  RMOVIE(new_movie_obj)->movie = CopyMovieSelection(MOVIE(obj));
  
  if (rb_block_given_p())
    SetMovieProgressProc(MOVIE(obj), 0, 0);
  
  return new_movie_obj;
}

Adds the tracks of given movie into called movie. Position will default to beginning of movie. Duration will default to length of given movie.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

     # File lib/quicktime/movie.rb, line 113
113:     def composite_movie(movie, position = 0, duration = 0, &block)
114:       select(position, duration)
115:       add_into_selection(movie, &block)
116:       deselect
117:     end

Deletes the specified section on movie.

[Source]

     # File lib/quicktime/movie.rb, line 168
168:     def delete_section(position = 0, duration = 0)
169:       select(position, duration)
170:       delete_selection
171:       deselect
172:     end

Removes the portion of the movie which is selected.

[Source]

/*
  call-seq: delete_selection()
  
  Removes the portion of the movie which is selected.
*/
static VALUE movie_delete_selection(VALUE obj)
{
  ClearMovieSelection(MOVIE(obj));
  return obj;
}

Reset selection to beginning

[Source]

     # File lib/quicktime/movie.rb, line 103
103:     def deselect
104:       select(0, 0)
105:     end

Dispose of the loaded QuickTime movie. This will automatically be done when this movie instance is garbage collected. However if you are iterating through many movies it is often helpful to dispose of it as soon as you‘re done with it.

[Source]

/*
  call-seq: dispose()
  
  Dispose of the loaded QuickTime movie. This will automatically be done 
  when this movie instance is garbage collected. However if you are 
  iterating through many movies it is often helpful to dispose of it 
  as soon as you're done with it.
*/
static VALUE movie_dispose(VALUE obj)
{
  if (MOVIE(obj)) {
    DisposeMovie(MOVIE(obj));
    RMOVIE(obj)->movie = NULL;
  }
  return obj;
}

Returns the length of this movie in seconds using raw_duration and time_scale.

[Source]

    # File lib/quicktime/movie.rb, line 16
16:     def duration
17:       raw_duration.to_f/time_scale
18:     end

Convenience method for exporting the movie. See Exporter::export.

[Source]

    # File lib/quicktime/movie.rb, line 58
58:     def export(*args, &block)
59:       exporter.export(*args, &block)
60:     end

Exports a frame of the movie at the given time (in seconds) to the given file. The image format is automatically determined from the file extension. If this cannot be determined from the extension then you can use export_image_type to specify the ostype manually.

[Source]

     # File lib/quicktime/movie.rb, line 87
 87:     def export_image(filepath, seconds)
 88:       # TODO support more file types
 89:       type = case File.extname(filepath).downcase
 90:         when '.pct', '.pict' then 'PICT'
 91:         when '.tif', '.tiff' then 'TIFF'
 92:         when '.jpg', '.jpeg' then 'JPEG'
 93:         when '.png'          then 'PNGf'
 94:         when '.tga'          then 'TPIC'
 95:         when '.bmp'          then 'BMPf'
 96:         when '.psd'          then '8BPS'
 97:         else raise QuickTime::Error, "Unable to guess ostype from file extension of #{filepath}"
 98:       end
 99:       export_image_type(filepath, seconds, type)
100:     end

Exports an image as the given ostype. It is best to use export_image instead if the ostype can be determined from the filepath extension.

[Source]

/*
  call-seq: export_image_type(filepath, time, ostype)
  
  Exports an image as the given ostype. It is best to use export_image
  instead if the ostype can be determined from the filepath extension.
*/
static VALUE movie_export_image_type(VALUE obj, VALUE filepath, VALUE frame_time, VALUE ostype_obj)
{
  GraphicsImportComponent component;
  PicHandle picture;
  Handle handle;
  FSSpec fs;
  OSErr err;
  
  picture = GetMoviePict(MOVIE(obj), MOVIE_TIME(obj, frame_time));
  
  err = NativePathNameToFSSpec(RSTRING(filepath)->ptr, &fs, 0);
  if (err != fnfErr)
    rb_raise(eQuickTime, "Error %d occurred while opening file for export at %s.", err, RSTRING(filepath)->ptr);
  
  // Convert the picture handle into a PICT file (still in a handle)
  // by adding a 512-byte header to the start.
  handle = NewHandleClear(512);
  err = HandAndHand((Handle)picture, handle);
  if (err != noErr)
    rb_raise(eQuickTime, "Error %d occurred while converting handle for pict export %s.", err, RSTRING(filepath)->ptr);
  
  err = OpenADefaultComponent(GraphicsImporterComponentType, kQTFileTypePicture, &component);
  if (err != noErr)
    rb_raise(eQuickTime, "Error %d occurred while opening picture component for %s.", err, RSTRING(filepath)->ptr);
  
  err = GraphicsImportSetDataHandle(component, handle);
  if (err != noErr)
    rb_raise(eQuickTime, "Error %d occurred while setting graphics importer data handle for %s.", err, RSTRING(filepath)->ptr);
  
  err = GraphicsImportExportImageFile(component, OSTYPE(RSTRING(ostype_obj)->ptr), 0, &fs, smSystemScript);
  if (err != noErr)
    rb_raise(eQuickTime, "Error %d occurred while exporting pict to file %s.", err, RSTRING(filepath)->ptr);
  
  CloseComponent(component);
  DisposeHandle(handle);
  DisposeHandle((Handle)picture);
  
  return Qnil;
}

Returns an Exporter instance for this movie.

[Source]

    # File lib/quicktime/movie.rb, line 53
53:     def exporter
54:       Exporter.new(self)
55:     end

Saves the movie to the given filepath by flattening it.

[Source]

/*
  call-seq: flatten(filepath)
  
  Saves the movie to the given filepath by flattening it.
*/
static VALUE movie_flatten(VALUE obj, VALUE filepath)
{
  OSErr err;
  FSSpec fs;
  VALUE new_movie_obj = rb_obj_alloc(cMovie);
  
  err = NativePathNameToFSSpec(RSTRING(filepath)->ptr, &fs, 0);
  if (err != fnfErr)
    rb_raise(eQuickTime, "Error %d occurred while opening file for export at %s", err, RSTRING(filepath)->ptr);
  
  // TODO make these flags settable through an options hash
  RMOVIE(new_movie_obj)->movie = FlattenMovieData(MOVIE(obj),
                                  flattenDontInterleaveFlatten
                                  | flattenCompressMovieResource
                                  | flattenAddMovieToDataFork
                                  | flattenForceMovieResourceBeforeMovieData,
                                  &fs, 'TVOD', smSystemScript, createMovieFileDontCreateResFile);
  return new_movie_obj;
}

Returns the bounding height of this movie in number of pixels.

[Source]

    # File lib/quicktime/movie.rb, line 26
26:     def height
27:       bounds[:bottom] - bounds[:top]
28:     end

Inserts the given movie into called movie, replacing any current selection.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

/*
  call-seq: insert_into_selection(movie)
  
  Inserts the given movie into called movie, replacing any current selection.
  
  You can track the progress of this operation by passing a block to this 
  method. It will be called regularly during the process and pass the 
  percentage complete (0.0 to 1.0) as an argument to the block.
*/
static VALUE movie_insert_into_selection(VALUE obj, VALUE src)
{
  if (rb_block_given_p())
    SetMovieProgressProc(MOVIE(obj), (MovieProgressUPP)movie_progress_proc, rb_block_proc());
  
  PasteMovieSelection(MOVIE(obj), MOVIE(src));
  
  if (rb_block_given_p())
    SetMovieProgressProc(MOVIE(obj), 0, 0);
  
  return obj;
}

Inserts given movie into called movie. The position defaults to the beginning of the movie. If a duration is passed, that amount of the movie will be replaced.

You can track the progress of this operation by passing a block to this method. It will be called regularly during the process and pass the percentage complete (0.0 to 1.0) as an argument to the block.

[Source]

     # File lib/quicktime/movie.rb, line 136
136:     def insert_movie(movie, position = 0, duration = 0, &block)
137:       select(position, duration)
138:       insert_into_selection(movie, &block)
139:       deselect
140:     end

Loads a new, empty QuickTime movie. Should only be called if no movie has been loaded (or it has been disposed). Usually you go through Movie.empty.

[Source]

/*
  call-seq: load_empty()
  
  Loads a new, empty QuickTime movie. Should only be called if no movie 
  has been loaded (or it has been disposed). Usually you go through 
  Movie.empty.
*/
static VALUE movie_load_empty(VALUE obj)
{
  if (MOVIE(obj)) {
    rb_raise(eQuickTime, "Movie has already been loaded.");
  } else {
    RMOVIE(obj)->movie = NewMovie(0);
    return obj; 
  }
}

Loads a new, empty QuickTime movie at given filepath. Should only be called if no movie has been loaded (or it has been disposed). Usually you go through Movie.open.

[Source]

/*
  call-seq: load_from_file(filepath)
  
  Loads a new, empty QuickTime movie at given filepath. Should only be 
  called if no movie has been loaded (or it has been disposed). Usually 
  you go through Movie.open.
*/
static VALUE movie_load_from_file(VALUE obj, VALUE filepath)
{
  if (MOVIE(obj)) {
    rb_raise(eQuickTime, "Movie has already been loaded.");
  } else {
    OSErr err;
    FSSpec fs;
    short resRefNum = -1;
    short resId = 0;
    Movie *movie = ALLOC(Movie);
    
    err = NativePathNameToFSSpec(RSTRING(filepath)->ptr, &fs, 0);
    if (err != 0)
      rb_raise(eQuickTime, "Error %d occurred while reading file at %s", err, RSTRING(filepath)->ptr);
    
    err = OpenMovieFile(&fs, &resRefNum, fsRdPerm);
    if (err != 0)
      rb_raise(eQuickTime, "Error %d occurred while opening movie at %s", err, RSTRING(filepath)->ptr);
    
    err = NewMovieFromFile(movie, resRefNum, &resId, 0, newMovieActive, 0);
    if (err != 0)
      rb_raise(eQuickTime, "Error %d occurred while loading movie at %s", err, RSTRING(filepath)->ptr);
    
    err = CloseMovieFile(resRefNum);
    if (err != 0)
      rb_raise(eQuickTime, "Error %d occurred while closing movie file at %s", err, RSTRING(filepath)->ptr);
    
    RMOVIE(obj)->movie = *movie;
    RMOVIE(obj)->filepath = RSTRING(filepath)->ptr;
    RMOVIE(obj)->resId = resId;
    
    return obj;
  }
}

Creates a new audio track with given width/height on movie and returns it.

[Source]

    # File lib/quicktime/movie.rb, line 70
70:     def new_audio_track(width, height)
71:       track = new_track(width, height)
72:       track.new_audio_media
73:       track
74:     end

Creates a new text track with given width/height on movie and returns it.

[Source]

    # File lib/quicktime/movie.rb, line 77
77:     def new_text_track(width, height)
78:       track = new_track(width, height)
79:       track.new_text_media
80:       track
81:     end

Creates a new track with the given width/height on the movie and returns it.

This method is generally not called directly. Instead you should call new_video_track or new_audio_track. If you call method make sure to call new_media on track to setup the media.

[Source]

/*
  call-seq: new_track(width, height) -> track
  
  Creates a new track with the given width/height on the movie and returns it.
  
  This method is generally not called directly. Instead you should call 
  new_video_track or new_audio_track. If you call method make sure to 
  call new_media on track to setup the media.
*/
static VALUE movie_new_track(VALUE obj, VALUE width, VALUE height)
{
  VALUE track_obj = rb_obj_alloc(cTrack);
  RTRACK(track_obj)->track = NewMovieTrack(MOVIE(obj), NUM2INT(width), NUM2INT(height), kFullVolume);
  return track_obj;
}

Creates a new video track with given width/height on movie and returns it.

[Source]

    # File lib/quicktime/movie.rb, line 63
63:     def new_video_track(width, height)
64:       track = new_track(width, height)
65:       track.new_video_media
66:       track
67:     end

Returns the poster time of the movie (in seconds).

[Source]

/*
  call-seq: poster_time() -> seconds
  
  Returns the poster time of the movie (in seconds).
*/
static VALUE movie_get_poster_time(VALUE obj)
{
  return rb_float_new((double)GetMoviePosterTime(MOVIE(obj))/GetMovieTimeScale(MOVIE(obj)));
}

Sets the poster_time of the movie (in seconds).

[Source]

/*
  call-seq: poster_time=(seconds)
  
  Sets the poster_time of the movie (in seconds).
*/
static VALUE movie_set_poster_time(VALUE obj, VALUE seconds)
{
  SetMoviePosterTime(MOVIE(obj), MOVIE_TIME(obj, seconds));
  return Qnil;
}

Returns the raw duration of the movie. Combine this with time_scale to reach the duration in seconds.

[Source]

/*
  call-seq: raw_duration() -> duration_int
  
  Returns the raw duration of the movie. Combine this with time_scale to 
  reach the duration in seconds.
*/
static VALUE movie_raw_duration(VALUE obj)
{
  return INT2NUM(GetMovieDuration(MOVIE(obj)));
}

Saves the movie to the current file.

[Source]

/*
  call-seq: save()
  
  Saves the movie to the current file.
*/
static VALUE movie_save(VALUE obj)
{
  OSErr err;
  FSSpec fs;
  short resRefNum = -1;
  
  if (!RMOVIE(obj)->filepath || !RMOVIE(obj)->resId) {
    rb_raise(eQuickTime, "Unable to save movie because it does not have an associated file.");
  } else {
    err = NativePathNameToFSSpec(RMOVIE(obj)->filepath, &fs, 0);
    if (err != 0)
      rb_raise(eQuickTime, "Error %d occurred while reading file at %s", err, RMOVIE(obj)->filepath);
    
    err = OpenMovieFile(&fs, &resRefNum, fsWrPerm);
    if (err != 0)
      rb_raise(eQuickTime, "Error %d occurred while opening movie at %s", err, RMOVIE(obj)->filepath);
    
    err = UpdateMovieResource(MOVIE(obj), resRefNum, RMOVIE(obj)->resId, 0);
    if (err != 0)
      rb_raise(eQuickTime, "Error %d occurred while saving movie file", err);
    
    err = CloseMovieFile(resRefNum);
    if (err != 0)
      rb_raise(eQuickTime, "Error %d occurred while closing movie file at %s", err, RMOVIE(obj)->filepath);
    
    return Qnil;
  }
}

Select a portion of a movie. Both position and duration should be floats representing seconds.

[Source]

/*
  call-seq: select(position, duration)
  
  Select a portion of a movie. Both position and duration should be
  floats representing seconds.
*/
static VALUE movie_select(VALUE obj, VALUE position, VALUE duration)
{
  SetMovieSelection(MOVIE(obj), MOVIE_TIME(obj, position), MOVIE_TIME(obj, duration));
  return obj;
}

Returns an array of text tracks in this movie.

[Source]

    # File lib/quicktime/movie.rb, line 48
48:     def text_tracks
49:       tracks.select { |t| t.text? }
50:     end

Returns the time scale of the movie. Usually only needed when working with raw_duration.

[Source]

/*
  call-seq: time_scale() -> scale_int
  
  Returns the time scale of the movie. Usually only needed when working 
  with raw_duration.
*/
static VALUE movie_time_scale(VALUE obj)
{
  return INT2NUM(GetMovieTimeScale(MOVIE(obj)));
}

Returns the number of tracks in the movie.

[Source]

/*
  call-seq: track_count() -> count
  
  Returns the number of tracks in the movie.
*/
static VALUE movie_track_count(VALUE obj)
{
  return INT2NUM(GetMovieTrackCount(MOVIE(obj)));
}

Returns an array of tracks in this movie.

[Source]

    # File lib/quicktime/movie.rb, line 31
31:     def tracks
32:       (1..track_count).map do |i|
33:         Track.new.load_from_movie(self, i)
34:       end
35:     end

Returns an array of video tracks in this movie.

[Source]

    # File lib/quicktime/movie.rb, line 43
43:     def video_tracks
44:       tracks.select { |t| t.video? }
45:     end

Returns the bounding width of this movie in number of pixels.

[Source]

    # File lib/quicktime/movie.rb, line 21
21:     def width
22:       bounds[:right] - bounds[:left]
23:     end

[Validate]