Class: QuickTime::Track
- Inherits:
-
Object
- Object
- QuickTime::Track
- Defined in:
- lib/quicktime/track.rb,
ext/track.c
Overview
see ext/track.c for additional methods
Instance Method Summary collapse
-
#audio? ⇒ Boolean
Returns true/false depending on if track is an audio track.
-
#bounds ⇒ Object
Returns a hash of boundaries.
-
#delete ⇒ Object
Removes the track from its movie and deletes it from memory.
-
#disable ⇒ Object
Disables the track.
-
#duration ⇒ Object
Returns the length of this track in seconds using raw_duration and time_scale.
-
#enable ⇒ Object
Enables the track.
-
#enable_alpha ⇒ Object
Enable the straight alpha graphic mode for this track.
-
#enabled? ⇒ Boolean
Returns true/false depending on if the track is enabled.
-
#frame_count ⇒ Object
Returns the number of frames in the track.
-
#frame_rate ⇒ Object
The average frame_rate for this track.
-
#height ⇒ Object
Returns the bounding height of this track in number of pixels.
-
#id ⇒ Object
Returns either id number QuickTime uses to reference this track.
-
#load(movie, index) ⇒ Object
Loads a QuickTime track from a given movie.
-
#media_type ⇒ Object
Returns either :audio or :video depending on the type of track this is.
-
#new_audio_media ⇒ Object
Creates a new audio media for this track.
-
#new_text_media ⇒ Object
Creates a new text media for this track.
-
#new_video_media ⇒ Object
Creates a new video media for this track.
-
#offset ⇒ Object
Returns the offset of the track from the beginning of the movie (in seconds).
-
#offset=(seconds) ⇒ Object
Sets the offset of the track from the start of the movie (in seconds).
-
#raw_duration ⇒ Object
Returns the raw duration of the track.
-
#reset_transformations ⇒ Object
Revert any transformations (scale, translate, rotate) performed on this track.
-
#rotate(degrees) ⇒ Object
Rotate the track by the given number of degrees.
-
#scale(width, height) ⇒ Object
Scale the track’s size by width and height respectively.
-
#text? ⇒ Boolean
Returns true/false depending on if track is a text track.
-
#time_scale ⇒ Object
Returns the time scale of the track.
-
#translate(x, y) ⇒ Object
Offset a track’s position by x and y values respectively.
-
#video? ⇒ Boolean
Returns true/false depending on if track is a video track.
-
#volume ⇒ Object
Returns the volume of the audio from 0.0 to 1.0.
-
#volume=(volume_float) ⇒ Object
Sets the volume to the given value (0.0 to 1.0).
-
#width ⇒ Object
Returns the bounding width of this track in number of pixels.
Instance Method Details
#audio? ⇒ Boolean
Returns true/false depending on if track is an audio track.
16 17 18 |
# File 'lib/quicktime/track.rb', line 16 def audio? media_type == :audio end |
#bounds ⇒ Object
Returns a hash of boundaries. The hash contains four keys: :left, :top, :right, :bottom. Each holds an integer representing the pixel value.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'ext/track.c', line 301
static VALUE track_bounds(VALUE obj)
{
VALUE bounds_hash = rb_hash_new();
RgnHandle region;
Rect bounds;
region = GetTrackDisplayBoundsRgn(TRACK(obj));
GetRegionBounds(region, &bounds);
DisposeRgn(region);
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;
}
|
#delete ⇒ Object
Removes the track from its movie and deletes it from memory.
109 110 111 112 113 |
# File 'ext/track.c', line 109
static VALUE track_delete(VALUE obj)
{
DisposeMovieTrack(TRACK(obj));
return Qnil;
}
|
#disable ⇒ Object
Disables the track. See enabled? to determine if it’s disabled already.
120 121 122 123 124 |
# File 'ext/track.c', line 120
static VALUE track_disable(VALUE obj, VALUE boolean)
{
SetTrackEnabled(TRACK(obj), FALSE);
return obj;
}
|
#duration ⇒ Object
Returns the length of this track in seconds using raw_duration and time_scale.
6 7 8 |
# File 'lib/quicktime/track.rb', line 6 def duration raw_duration.to_f/time_scale end |
#enable ⇒ Object
Enables the track. See enabled? to determine if it’s enabled already.
131 132 133 134 135 |
# File 'ext/track.c', line 131
static VALUE track_enable(VALUE obj, VALUE boolean)
{
SetTrackEnabled(TRACK(obj), TRUE);
return obj;
}
|
#enable_alpha ⇒ Object
Enable the straight alpha graphic mode for this track.
This is best used on an overlayed video track which includes some alpha transparency (such as in a PNG image).
243 244 245 246 247 |
# File 'ext/track.c', line 243
static VALUE track_enable_alpha(VALUE obj)
{
MediaSetGraphicsMode(GetMediaHandler(TRACK_MEDIA(obj)), graphicsModeStraightAlpha, 0);
return obj;
}
|
#enabled? ⇒ Boolean
Returns true/false depending on if the track is enabled.
142 143 144 145 146 147 148 149 |
# File 'ext/track.c', line 142
static VALUE track_enabled(VALUE obj, VALUE boolean)
{
if (GetTrackEnabled(TRACK(obj)) == TRUE) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#frame_count ⇒ Object
Returns the number of frames in the track.
67 68 69 70 |
# File 'ext/track.c', line 67
static VALUE track_frame_count(VALUE obj)
{
return INT2NUM(GetMediaSampleCount(TRACK_MEDIA(obj)));
}
|
#frame_rate ⇒ Object
The average frame_rate for this track. May not be exact.
11 12 13 |
# File 'lib/quicktime/track.rb', line 11 def frame_rate # what about odd frame rates such as 29.97? frame_count/duration end |
#height ⇒ Object
Returns the bounding height of this track in number of pixels.
36 37 38 |
# File 'lib/quicktime/track.rb', line 36 def height bounds[:bottom] - bounds[:top] end |
#id ⇒ Object
Returns either id number QuickTime uses to reference this track. Usually only used internally.
99 100 101 102 |
# File 'ext/track.c', line 99
static VALUE track_id(VALUE obj)
{
return INT2NUM(GetTrackID(TRACK(obj)));
}
|
#load(movie, index) ⇒ Object
Loads a QuickTime track from a given movie. This is done automatically when calling movie.tracks.
31 32 33 34 35 36 37 38 |
# File 'ext/track.c', line 31
static VALUE track_load(VALUE obj, VALUE movie_obj, VALUE index_obj)
{
RTRACK(obj)->track = GetMovieIndTrack(MOVIE(movie_obj), NUM2INT(index_obj));
if (!RTRACK(obj)->track)
rb_raise(eQuickTime, "Unable to fetch track for movie at index %d", NUM2INT(index_obj));
return obj;
}
|
#media_type ⇒ Object
Returns either :audio or :video depending on the type of track this is.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'ext/track.c', line 77
static VALUE track_media_type(VALUE obj)
{
OSType media_type;
GetMediaHandlerDescription(TRACK_MEDIA(obj), &media_type, 0, 0);
if (media_type == SoundMediaType) {
return ID2SYM(rb_intern("audio"));
} else if (media_type == VideoMediaType) {
return ID2SYM(rb_intern("video"));
} else if (media_type == TextMediaType) {
return ID2SYM(rb_intern("text"));
} else {
return Qnil;
}
}
|
#new_audio_media ⇒ Object
Creates a new audio media for this track.
Generally this method is not called directly, instead you can make a new audio track using Movie#new_audio_track.
215 216 217 218 219 |
# File 'ext/track.c', line 215
static VALUE track_new_audio_media(VALUE obj)
{
NewTrackMedia(TRACK(obj), SoundMediaType, 44100, 0, 0);
return obj;
}
|
#new_text_media ⇒ Object
Creates a new text media for this track.
Generally this method is not called directly, instead you can make a new text track using Movie#new_text_track.
229 230 231 232 233 |
# File 'ext/track.c', line 229
static VALUE track_new_text_media(VALUE obj)
{
NewTrackMedia(TRACK(obj), TextMediaType, 600, 0, 0);
return obj;
}
|
#new_video_media ⇒ Object
Creates a new video media for this track.
Generally this method is not called directly, instead you can make a new video track using Movie#new_video_track.
201 202 203 204 205 |
# File 'ext/track.c', line 201
static VALUE track_new_video_media(VALUE obj)
{
NewTrackMedia(TRACK(obj), VideoMediaType, 600, 0, 0);
return obj;
}
|
#offset ⇒ Object
Returns the offset of the track from the beginning of the movie (in seconds).
177 178 179 180 |
# File 'ext/track.c', line 177
static VALUE track_get_offset(VALUE obj)
{
return rb_float_new((double)GetTrackOffset(TRACK(obj))/GetMediaTimeScale(TRACK_MEDIA(obj)));
}
|
#offset=(seconds) ⇒ Object
Sets the offset of the track from the start of the movie (in seconds).
187 188 189 190 191 |
# File 'ext/track.c', line 187
static VALUE track_set_offset(VALUE obj, VALUE seconds)
{
SetTrackOffset(TRACK(obj), TRACK_TIME(obj, seconds));
return Qnil;
}
|
#raw_duration ⇒ Object
Returns the raw duration of the track. Combine this with time_scale to reach the duration in seconds.
46 47 48 49 |
# File 'ext/track.c', line 46
static VALUE track_raw_duration(VALUE obj)
{
return INT2NUM(GetMediaDuration(TRACK_MEDIA(obj)));
}
|
#reset_transformations ⇒ Object
Revert any transformations (scale, translate, rotate) performed on this track.
321 322 323 324 325 326 327 328 |
# File 'ext/track.c', line 321
static VALUE track_reset_transformations(VALUE obj)
{
MatrixRecord matrix;
GetTrackMatrix(TRACK(obj), &matrix);
SetIdentityMatrix(&matrix);
SetTrackMatrix(TRACK(obj), &matrix);
return obj;
}
|
#rotate(degrees) ⇒ Object
Rotate the track by the given number of degrees.
286 287 288 289 290 291 292 293 |
# File 'ext/track.c', line 286
static VALUE track_rotate(VALUE obj, VALUE degrees)
{
MatrixRecord matrix;
GetTrackMatrix(TRACK(obj), &matrix);
RotateMatrix(&matrix, FloatToFixed(NUM2DBL(degrees)), 0, 0);
SetTrackMatrix(TRACK(obj), &matrix);
return obj;
}
|
#scale(width, height) ⇒ Object
Scale the track’s size by width and height respectively.
The value passed is a relative float where “1” is the current size.
256 257 258 259 260 261 262 263 |
# File 'ext/track.c', line 256
static VALUE track_scale(VALUE obj, VALUE width, VALUE height)
{
MatrixRecord matrix;
GetTrackMatrix(TRACK(obj), &matrix);
ScaleMatrix(&matrix, FloatToFixed(NUM2DBL(width)), FloatToFixed(NUM2DBL(height)), 0, 0);
SetTrackMatrix(TRACK(obj), &matrix);
return obj;
}
|
#text? ⇒ Boolean
Returns true/false depending on if track is a text track.
26 27 28 |
# File 'lib/quicktime/track.rb', line 26 def text? media_type == :text end |
#time_scale ⇒ Object
Returns the time scale of the track. Usually only needed when working with raw_duration.
57 58 59 60 |
# File 'ext/track.c', line 57
static VALUE track_time_scale(VALUE obj)
{
return INT2NUM(GetMediaTimeScale(TRACK_MEDIA(obj)));
}
|
#translate(x, y) ⇒ Object
Offset a track’s position by x and y values respectively.
Values should be in pixels.
272 273 274 275 276 277 278 279 |
# File 'ext/track.c', line 272
static VALUE track_translate(VALUE obj, VALUE x, VALUE y)
{
MatrixRecord matrix;
GetTrackMatrix(TRACK(obj), &matrix);
TranslateMatrix(&matrix, FloatToFixed(NUM2DBL(x)), FloatToFixed(NUM2DBL(y)));
SetTrackMatrix(TRACK(obj), &matrix);
return obj;
}
|
#video? ⇒ Boolean
Returns true/false depending on if track is a video track.
21 22 23 |
# File 'lib/quicktime/track.rb', line 21 def video? media_type == :video end |
#volume ⇒ Object
Returns the volume of the audio from 0.0 to 1.0.
156 157 158 159 |
# File 'ext/track.c', line 156
static VALUE track_get_volume(VALUE obj)
{
return rb_float_new((double)GetTrackVolume(TRACK(obj))/0x0100);
}
|
#volume=(volume_float) ⇒ Object
Sets the volume to the given value (0.0 to 1.0)
166 167 168 169 170 |
# File 'ext/track.c', line 166
static VALUE track_set_volume(VALUE obj, VALUE volume_obj)
{
SetTrackVolume(TRACK(obj), (short)(0x0100*NUM2DBL(volume_obj)));
return Qnil;
}
|
#width ⇒ Object
Returns the bounding width of this track in number of pixels.
31 32 33 |
# File 'lib/quicktime/track.rb', line 31 def width bounds[:right] - bounds[:left] end |