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.
-
#audio_streams ⇒ Object
Returns an array of audio streams contained within this file.
-
#author ⇒ Object
Returns the author string.
-
#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.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'ext/ffruby/ffrubyfile.c', line 211
static VALUE ffrf_initialize(VALUE self, VALUE filename)
{
size_t len;
char* msg;
AVFormatContext *fmt;
VALUE exception;
VALUE filename_str = rb_funcall(filename, rb_intern("to_s"), 0);
char* filename_ptr = RSTRING(filename_str)->ptr;
if (av_open_input_file(&fmt, filename_ptr, NULL, 0, NULL) != 0)
{
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);
}
if (av_find_stream_info(fmt) < 0)
{
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.
89 90 91 92 93 |
# File 'ext/ffruby/ffrubyfile.c', line 89
static VALUE ffrf_album(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return rb_str_new2(fmt->album);
}
|
#audio_streams ⇒ Object
Returns an array of audio streams contained within this file.
202 203 204 205 |
# File 'ext/ffruby/ffrubyfile.c', line 202
static VALUE ffrf_audio_streams(VALUE self)
{
return ffrf_av_streams(self, cFFrubyAudioStream);
}
|
#author ⇒ Object
Returns the author string.
68 69 70 71 72 |
# File 'ext/ffruby/ffrubyfile.c', line 68
static VALUE ffrf_author(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return rb_str_new2(fmt->author);
}
|
#bit_rate ⇒ Object
Returns the bit rate.
124 125 126 127 128 |
# File 'ext/ffruby/ffrubyfile.c', line 124
static VALUE ffrf_bit_rate(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return INT2NUM(fmt->bit_rate);
}
|
#comment ⇒ Object
Returns the comment string.
82 83 84 85 86 |
# File 'ext/ffruby/ffrubyfile.c', line 82
static VALUE ffrf_comment(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return rb_str_new2(fmt->comment);
}
|
#copyright ⇒ Object
Returns the copyright string.
75 76 77 78 79 |
# File 'ext/ffruby/ffrubyfile.c', line 75
static VALUE ffrf_copyright(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return rb_str_new2(fmt->copyright);
}
|
#duration ⇒ Object
Returns the duration in seconds as a float.
117 118 119 120 121 |
# File 'ext/ffruby/ffrubyfile.c', line 117
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.
131 132 133 134 135 |
# File 'ext/ffruby/ffrubyfile.c', line 131
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.
96 97 98 99 100 |
# File 'ext/ffruby/ffrubyfile.c', line 96
static VALUE ffrf_genre(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return rb_str_new2(fmt->genre);
}
|
#streams ⇒ Object
Returns an array of streams contained within this file.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'ext/ffruby/ffrubyfile.c', line 138
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)
{
case CODEC_TYPE_VIDEO:
rb_ary_push(streams, rb_class_new_instance(2, args, cFFrubyVideoStream));
break;
case CODEC_TYPE_AUDIO:
rb_ary_push(streams, rb_class_new_instance(2, args, cFFrubyAudioStream));
break;
default:
break;
}
}
}
return streams;
}
|
#title ⇒ Object
Returns the title string.
61 62 63 64 65 |
# File 'ext/ffruby/ffrubyfile.c', line 61
static VALUE ffrf_title(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return rb_str_new2(fmt->title);
}
|
#track ⇒ Object
Returns the track number.
110 111 112 113 114 |
# File 'ext/ffruby/ffrubyfile.c', line 110
static VALUE ffrf_track(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return INT2NUM(fmt->track);
}
|
#video_streams ⇒ Object
Returns an array of video streams contained within this file.
196 197 198 199 |
# File 'ext/ffruby/ffrubyfile.c', line 196
static VALUE ffrf_video_streams(VALUE self)
{
return ffrf_av_streams(self, cFFrubyVideoStream);
}
|
#year ⇒ Object
Returns the year.
103 104 105 106 107 |
# File 'ext/ffruby/ffrubyfile.c', line 103
static VALUE ffrf_year(VALUE self)
{
AVFormatContext *fmt = ffrf_get_fmt(self);
return INT2NUM(fmt->year);
}
|