Class: FFruby::File
- Inherits:
-
Object
- Object
- FFruby::File
- Defined in:
- ext/ffruby/ffrubyfile.c,
ext/ffruby/ffrubyfile.c
Overview
An interface to FFmpeg on existing files. Provides access to metadata and stream instances.
Instance Method Summary collapse
-
#album ⇒ Object
Returns the album string.
-
#artist ⇒ Object
(also: #author)
Returns the artist/author string.
-
#audio_streams ⇒ Object
Returns an array of audio streams contained within this file.
-
#bit_rate ⇒ Object
Returns the bit rate.
-
#comment ⇒ Object
Returns the comment string.
-
#copyright ⇒ Object
Returns the copyright string.
-
#duration ⇒ Object
Returns the duration in seconds as a float.
-
#format ⇒ Object
Returns the format name.
-
#genre ⇒ Object
Returns the genre string.
-
#new(filename) ⇒ FFruby::File
constructor
Creates an FFruby::File instance using the given filename.
-
#streams ⇒ Object
Returns an array of streams contained within this file.
-
#title ⇒ Object
Returns the title string.
-
#track ⇒ Object
Returns the track number.
-
#video_streams ⇒ Object
Returns an array of video streams contained within this file.
-
#year ⇒ Object
Returns the year.
Constructor Details
#new(filename) ⇒ FFruby::File
Creates an FFruby::File instance using the given filename.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'ext/ffruby/ffrubyfile.c', line 263
static VALUE ffrf_initialize(VALUE self, VALUE filename)
{
size_t len;
char* msg;
VALUE exception;
AVFormatContext *fmt = NULL;
VALUE filename_str = rb_funcall(filename, rb_intern("to_s"), 0);
char* filename_ptr = RSTRING_PTR(filename_str);
#ifdef HAVE_AVFORMAT_OPEN_INPUT
if (avformat_open_input(&fmt, filename_ptr, NULL, NULL) != 0)
#else
if (av_open_input_file(&fmt, filename_ptr, NULL, 0, NULL) != 0)
#endif
{
len = strlen("Cannot open file !") + strlen(filename_ptr) + 1;
msg = ALLOC_N(char, len);
snprintf(msg, len, "Cannot open file %s!", filename_ptr);
exception = rb_exc_new2(rb_eIOError, msg);
free(msg);
rb_exc_raise(exception);
}
#ifdef HAVE_AVFORMAT_FIND_STREAM_INFO
if (avformat_find_stream_info(fmt, NULL) < 0)
#else
if (av_find_stream_info(fmt) < 0)
#endif
{
len = strlen("Problem reading file !") + strlen(filename_ptr) + 1;
msg = ALLOC_N(char, len);
snprintf(msg, len, "Problem reading file %s!", filename_ptr);
exception = rb_exc_new2(rb_eIOError, msg);
free(msg);
rb_exc_raise(exception);
}
DATA_PTR(self) = fmt;
return self;
}
|
Instance Method Details
#album ⇒ Object
Returns the album string.
137 138 139 140 |
# File 'ext/ffruby/ffrubyfile.c', line 137
static VALUE ffrf_album(VALUE self)
{
return METADATA_STR(album);
}
|
#artist ⇒ Object Also known as:
Returns the artist/author string.
115 116 117 118 119 120 121 122 |
# File 'ext/ffruby/ffrubyfile.c', line 115
static VALUE ffrf_artist(VALUE self)
{
#ifdef HAVE_AV_DICT_GET
return METADATA_STR(artist);
#else
return METADATA_STR(author);
#endif
}
|
#audio_streams ⇒ Object
Returns an array of audio streams contained within this file.
254 255 256 257 |
# File 'ext/ffruby/ffrubyfile.c', line 254
static VALUE ffrf_audio_streams(VALUE self)
{
return ffrf_av_streams(self, cFFrubyAudioStream);
}
|
#bit_rate ⇒ Object
Returns the bit rate.
168 169 170 171 172 |
# File 'ext/ffruby/ffrubyfile.c', line 168
static VALUE ffrf_bit_rate(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return INT2NUM(fmt->bit_rate);
}
|
#comment ⇒ Object
Returns the comment string.
131 132 133 134 |
# File 'ext/ffruby/ffrubyfile.c', line 131
static VALUE ffrf_comment(VALUE self)
{
return METADATA_STR(comment);
}
|
#copyright ⇒ Object
Returns the copyright string.
125 126 127 128 |
# File 'ext/ffruby/ffrubyfile.c', line 125
static VALUE ffrf_copyright(VALUE self)
{
return METADATA_STR(copyright);
}
|
#duration ⇒ Object
Returns the duration in seconds as a float.
161 162 163 164 165 |
# File 'ext/ffruby/ffrubyfile.c', line 161
static VALUE ffrf_duration(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return rb_float_new((double) fmt->duration / (double) AV_TIME_BASE);
}
|
#format ⇒ Object
Returns the format name.
175 176 177 178 179 |
# File 'ext/ffruby/ffrubyfile.c', line 175
static VALUE ffrf_format(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return rb_str_new2(fmt->iformat->name);
}
|
#genre ⇒ Object
Returns the genre string.
143 144 145 146 |
# File 'ext/ffruby/ffrubyfile.c', line 143
static VALUE ffrf_genre(VALUE self)
{
return METADATA_STR(genre);
}
|
#streams ⇒ Object
Returns an array of streams contained within this file.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'ext/ffruby/ffrubyfile.c', line 182
static VALUE ffrf_streams(VALUE self)
{
unsigned int i;
AVFormatContext *fmt;
VALUE streams;
VALUE* args;
if ((streams = rb_iv_get(self, "@streams")) == Qnil)
{
fmt = ffrf_get_fmt(self);
streams = rb_ary_new();
rb_iv_set(self, "@streams", streams);
args = (VALUE*) ALLOCA_N(VALUE*, 2);
args[0] = self;
for (i = 0; i < fmt->nb_streams; i++)
{
args[1] = INT2FIX(i);
switch (fmt->streams[i]->codec->codec_type)
{
#ifdef HAVE_CONST_AVMEDIA_TYPE_UNKNOWN
case AVMEDIA_TYPE_VIDEO:
#else
case CODEC_TYPE_VIDEO:
#endif
rb_ary_push(streams, rb_class_new_instance(2, args, cFFrubyVideoStream));
break;
#ifdef HAVE_CONST_AVMEDIA_TYPE_UNKNOWN
case AVMEDIA_TYPE_AUDIO:
#else
case CODEC_TYPE_AUDIO:
#endif
rb_ary_push(streams, rb_class_new_instance(2, args, cFFrubyAudioStream));
break;
default:
break;
}
}
}
return streams;
}
|
#title ⇒ Object
Returns the title string.
109 110 111 112 |
# File 'ext/ffruby/ffrubyfile.c', line 109
static VALUE ffrf_title(VALUE self)
{
return METADATA_STR(title);
}
|
#track ⇒ Object
Returns the track number.
155 156 157 158 |
# File 'ext/ffruby/ffrubyfile.c', line 155
static VALUE ffrf_track(VALUE self)
{
return METADATA_INT(track);
}
|
#video_streams ⇒ Object
Returns an array of video streams contained within this file.
248 249 250 251 |
# File 'ext/ffruby/ffrubyfile.c', line 248
static VALUE ffrf_video_streams(VALUE self)
{
return ffrf_av_streams(self, cFFrubyVideoStream);
}
|
#year ⇒ Object
Returns the year.
149 150 151 152 |
# File 'ext/ffruby/ffrubyfile.c', line 149
static VALUE ffrf_year(VALUE self)
{
return METADATA_INT(year);
}
|