Class: QuickTime::Track

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

Overview

see ext/track.c for additional methods

Instance Method Summary collapse

Instance Method Details

#audio?Boolean

Returns true/false depending on if track is an audio track.

Returns:

  • (Boolean)


16
17
18
# File 'lib/quicktime/track.rb', line 16

def audio?
  media_type == :audio
end

#deleteObject

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

#disableObject

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

#durationObject

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

#enableObject

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

#enabled?Boolean

Returns true/false depending on if the track is enabled.

Returns:

  • (Boolean)


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_countObject

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_rateObject

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

#idObject

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_typeObject

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_mediaObject

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_mediaObject

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_mediaObject

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

#offsetObject

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_durationObject

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

#text?Boolean

Returns true/false depending on if track is a text track.

Returns:

  • (Boolean)


26
27
28
# File 'lib/quicktime/track.rb', line 26

def text?
  media_type == :text
end

#time_scaleObject

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

#video?Boolean

Returns true/false depending on if track is a video track.

Returns:

  • (Boolean)


21
22
23
# File 'lib/quicktime/track.rb', line 21

def video?
  media_type == :video
end

#volumeObject

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