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

see ext/exporter.c for additional methods

Methods

Attributes

movie  [R] 

Public Class methods

[Source]

   # File lib/quicktime/exporter.rb, line 6
6:     def initialize(movie)
7:       @movie = movie
8:     end

Public Instance methods

Exports a movie to the given filepath. This will use either the settings you set beforehand, or QuickTime‘s defaults.

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: export_to_file(filepath)
  
  Exports a movie to the given filepath. This will use either the 
  settings you set beforehand, or QuickTime's defaults.

  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 exporter_export_to_file(VALUE obj, VALUE filepath)
{
  OSErr err;
  FSSpec fs;
  Movie movie = MOVIE(rb_iv_get(obj, "@movie"));
  ComponentInstance component = exporter_component(obj);
  
  if (rb_block_given_p())
    SetMovieProgressProc(movie, (MovieProgressUPP)movie_progress_proc, rb_block_proc());
  
  // Activate so QuickTime doesn't export a white frame
  SetMovieActive(movie, TRUE);
  
  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 use exporter settings when converting movie
  err = ConvertMovieToFile(movie, 0, &fs, 'MooV', 'TVOD', 0, 0, 0, component);
  if (err != noErr)
    rb_raise(eQuickTime, "Error %d occurred while attempting to export movie to file %s.", err, RSTRING(filepath)->ptr);
  
  if (rb_block_given_p())
    SetMovieProgressProc(movie, 0, 0);
  
  CloseComponent(component);
  
  return Qnil;
}

Loads the settings at the given filepath. See save_settings.

[Source]

/*
  call-seq: load_settings(filepath)
  
  Loads the settings at the given filepath. See save_settings.
*/
static VALUE exporter_load_settings(VALUE obj, VALUE filepath)
{
  FILE *file;
  long length, read_length;
  
  file = fopen(RSTRING(filepath)->ptr, "r+b");
  if (!file) {
    rb_raise(eQuickTime, "Unable to open file for loading at %s.", RSTRING(filepath)->ptr);
  }
  
  // obtain file size:
  fseek(file , 0, SEEK_END);
  length = ftell(file);
  rewind(file);
  
  // clear existing settings if there are any
  if (REXPORTER(obj)->settings) {
    QTDisposeAtomContainer(REXPORTER(obj)->settings);
  }
  
  // load the file into settings
  REXPORTER(obj)->settings = (QTAtomContainer)NewHandleClear(length);
  read_length = fread(*(Handle)REXPORTER(obj)->settings, 1, length, file);
  if (read_length != length) {
    rb_raise(eQuickTime, "Unable to read entire file at %s.", RSTRING(filepath)->ptr);
  }
  
  fclose(file);
  
  return Qnil;
}

Opens the offical QuickTime GUI settings dialog. The process will be suspended until the user closes the dialogue. If the user clicks Okay the settings will be applied to this Exporter. You can then use save_settings to save them to a file, and load_settings to load them back again.

[Source]

/*
  call-seq: open_settings_dialog()
  
  Opens the offical QuickTime GUI settings dialog. The process will be 
  suspended until the user closes the dialogue. If the user clicks Okay 
  the settings will be applied to this Exporter. You can then use 
  save_settings to save them to a file, and load_settings to load them 
  back again.
*/
static VALUE exporter_open_settings_dialog(VALUE obj)
{
  Boolean canceled;
  OSErr err;
  ProcessSerialNumber current_process = {0, kCurrentProcess};
  Movie movie = MOVIE(rb_iv_get(obj, "@movie"));
  ComponentInstance component = exporter_component(obj);
  
  // Bring this process to the front
  err = TransformProcessType(&current_process, kProcessTransformToForegroundApplication);
  if (err != noErr) {
    rb_raise(eQuickTime, "Error %d occurred while bringing this application to the forground.", err);
  }
  SetFrontProcess(&current_process);
  
  // Show export dialog and save settings
  err = MovieExportDoUserDialog(component, movie, 0, 0, GetMovieDuration(movie), &canceled);
  if (err != noErr) {
    rb_raise(eQuickTime, "Error %d occurred while opening export dialog.", err);
  }
  
  if (!canceled) {
    // Clear existing settings if there are any
    if (REXPORTER(obj)->settings) {
      QTDisposeAtomContainer(REXPORTER(obj)->settings);
    }
    MovieExportGetSettingsAsAtomContainer(component, &REXPORTER(obj)->settings);
  }
  
  CloseComponent(component);
  
  if (canceled) {
    return Qfalse;
  } else {
    return Qtrue;
  }
}

Saves the settings to the given filepath (usually with .st extension). See open_settings_dialog and load_settings.

[Source]

/*
  call-seq: save_settings(filepath)
  
  Saves the settings to the given filepath (usually with .st extension). 
  See open_settings_dialog and load_settings.
*/
static VALUE exporter_save_settings(VALUE obj, VALUE filepath)
{
  FILE *file;
  QTAtomContainer settings = REXPORTER(obj)->settings;
  
  if (!settings) {
    rb_raise(eQuickTime, "Unable to save settings because no settings are specified.");
  }
  
  file = fopen(RSTRING(filepath)->ptr, "wb");
  if (!file) {
    rb_raise(eQuickTime, "Unable to open file for saving at %s.", RSTRING(filepath)->ptr);
  }
  fwrite(*settings, GetHandleSize((Handle)settings), 1, file);
  fclose(file);
  
  return Qnil;
}

[Validate]