Class: QuickTime::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/quicktime/exporter.rb,
ext/exporter.c

Overview

see ext/exporter.c for additional methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(movie) ⇒ Exporter

Returns a new instance of Exporter.



6
7
8
# File 'lib/quicktime/exporter.rb', line 6

def initialize(movie)
  @movie = movie
end

Instance Attribute Details

#movieObject (readonly)

Returns the value of attribute movie.



4
5
6
# File 'lib/quicktime/exporter.rb', line 4

def movie
  @movie
end

Instance Method Details

#export_to_file(filepath) ⇒ Object

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.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'ext/exporter.c', line 46

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;
}

#load_settings(filepath) ⇒ Object

Loads the settings at the given filepath. See save_settings.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'ext/exporter.c', line 128

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;
}

#open_settings_dialogObject

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.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'ext/exporter.c', line 85

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 brining 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;
  }
}

#save_settings(filepath) ⇒ Object

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



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'ext/exporter.c', line 166

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;
}